Skip to content

Commit c617048

Browse files
committed
document has_win32
1 parent 56ed7c8 commit c617048

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

doc/specs/stdlib_system.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,31 @@ call sleep(500)
347347
348348
print *, "Finished sleeping!"
349349
```
350+
351+
## `has_win32` - Check if the system is running on Windows
352+
353+
### Status
354+
355+
Experimental
356+
357+
### Description
358+
359+
The `has_win32` interface provides a quick, compile-time check to determine if the current system is Windows. It leverages a C function that checks for the presence of the `_WIN32` macro, which is defined in C compilers when targeting Windows. This function is highly efficient and works during the compilation phase, avoiding the need for runtime checks.
360+
361+
### Syntax
362+
363+
`result = ` [[stdlib_system(module):has_win32(function)]] `()`
364+
365+
### Return Value
366+
367+
Returns a `logical` flag: `.true.` if the system is Windows, or `.false.` otherwise.
368+
369+
### Example
370+
371+
```fortran
372+
if (has_win32()) then
373+
print *, "Running on Windows!"
374+
else
375+
print *, "Not running on Windows."
376+
end if
377+
```

src/stdlib_system.F90

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ end subroutine process_kill
260260
!! version: experimental
261261
!!
262262
!! Pauses execution for a specified time in milliseconds.
263-
!! ([Specification](../page/specs/stdlib_system.html#sleep-pause-execution-for-a-specified-time))
263+
!! ([Specification](../page/specs/stdlib_system.html#sleep-pause-execution-for-a-specified-time=in-milliseconds))
264264
!!
265265
!! ### Summary
266266
!! Pauses code execution for a specified number of milliseconds. This routine is a cross-platform
@@ -281,12 +281,30 @@ module subroutine sleep(millisec)
281281
end subroutine sleep
282282
end interface sleep
283283

284-
285-
!! version: experimental
286-
!!
287284
interface
285+
286+
!! version: experimental
287+
!!
288+
!! Returns a `logical` flag indicating if the system is Windows.
289+
!! ([Specification](../page/specs/stdlib_system.html#has_win32-check-if-the-system-is-running-on-windows))
290+
!!
291+
!! ### Summary
292+
!! A fast, compile-time check to determine if the system is running Windows, based on the `_WIN32` macro.
293+
!!
294+
!! ### Description
295+
!!
296+
!! This interface provides a function to check if the current system is Windows. The check is performed by
297+
!! wrapping a C function that tests if the `_WIN32` macro is defined. This check is fast and occurs at
298+
!! compile-time, making it a more efficient alternative to platform-specific runtime checks.
299+
!!
300+
!! The `has_win32` function is particularly useful for conditional compilation or system-specific code paths
301+
!! that are dependent on whether the code is running on Windows.
302+
!!
303+
!! @note This function relies on the `_WIN32` macro, which is defined in C compilers when targeting Windows.
304+
!!
288305
module logical function has_win32()
289306
end function has_win32
290-
end interface
307+
308+
end interface
291309

292310
end module stdlib_system

0 commit comments

Comments
 (0)