How to conditionally compile code for different platforms in C++Builder?
Asked Answered
C

1

5

What are the platform conditional defines for Android, iOS, Win32, Win64 in C++Builder? I've found only examples for Delphi.

Canaigre answered 23/4, 2015 at 16:33 Comment(0)
B
10

The so called manifest constants are documented on this help page. The platform ones I've listed here:

┌─────────────┬───────┬──────────────────────────────┐
│ Macro       │ Value │ Description                  │
├─────────────┼───────┼──────────────────────────────┤
│ _Windows    │ 1     │ Windows platform             │
├─────────────┼───────┼──────────────────────────────┤
│ __WIN32__   │ 1     │ 32-bit Windows platform      │
├─────────────┼───────┼──────────────────────────────┤
│ _WIN64      │ 1     │ 64-bit Windows platform      │
├─────────────┼───────┼──────────────────────────────┤
│ __arm__     │       │ 32-bit ARM compiler          │
├─────────────┼───────┼──────────────────────────────┤
│ __arm64__   │       │ 64-bit ARM64 compiler        │
├─────────────┼───────┼──────────────────────────────┤
│ __APPLE__   │       │ Apple platform               │
├─────────────┼───────┼──────────────────────────────┤
│ __MACH__    │       │ MAC OSX platform             │
├─────────────┼───────┼──────────────────────────────┤
│ __ANDROID__ │       │ Android platform             │
└─────────────┴───────┴──────────────────────────────┘

These macros are compiler intrinsic, so they have no header file to include. An example:

#if _Windows
  // Windows platform
#elif __APPLE__
  // Apple platform
#elif __ANDROID__
  // Android platform
#else
  #error Not a supported platform
#endif
Bordie answered 24/4, 2015 at 10:4 Comment(2)
Thank you, thank you! It's much easier when you can find the right word(s) to search on!Canaigre
Mac OS X is MACH . (should be two underscores on either side of MACH, not bolded)Flagstad

© 2022 - 2024 — McMap. All rights reserved.