Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

#elifdef/#elifndef

Use case

Cleaner platform detection macros.

Explanation

Before C++23: #elif defined(x). Now: #elifdef x.

Code

#include <print>

#ifdef __aarch64__
#define ARCH "ARM64"
#elifdef __x86_64__
#define ARCH "x86_64"
#else
#define ARCH "unknown"
#endif

int main() {
  std::println("Arch: {}", ARCH);
  return 0;
}

View on GitHub.

Output

$ ./src/c++23/build/elifdef-elifndef
Arch: ARM64