CCCL_OS#

CCCL_OS(os)#

Detect the current operating system.

For supported operating systems, the macro expands to an implementation-defined true value if the current operating system matches, or false otherwise. These values may be used in boolean expressions (preprocessor or otherwise), but no other guarantees are made.

Available values for os include:

  • WINDOWS: Windows, either in 32-bit or 64-bit mode.

  • LINUX: Any kind of Linux installation. Note that other unix-based operating systems will also match against this.

  • ANDROID: Android operating system.

  • QNX: QNX real-time operating system.

  • APPLE: macOS (Intel or Apple Silicon).

Passing any other value will result in an undefined expansion, which may or may not be diagnosed by the compiler.

Example
#define MY_OTHER_MACRO 1

// Expansion value can be used in ordinary macro conditionals
#if CCCL_OS(WINDOWS) && MY_OTHER_MACRO
  // ...
#endif

// Can be negated as usual
#if !CCCL_OS(QNX)
  // ...
#endif

#if CCCL_OS(APPLE)
  // Will be visible only on macOS
#endif

#if CCCL_OS(ANDROID)
  // Will be visible only on Android
#endif

#if CCCL_OS(LINUX) && !CCCL_OS(APPLE) && !CCCL_OS(ANDROID)
  // Only visible on Linux
#endif

Note

This macro is made available when including any libcu++ header. Users that wish to include the smallest possible header for this macro should include <cuda/std/version>.

Note

Some operating systems may satisfy multiple conditions. For example macOS and Android satisfy both APPLE/ANDROID and LINUX.

Parameters:
  • os – The name of the operating system to test.

Returns:

true if the specified OS is begin compiled for, false otherwise.