What are the platform conditional defines for Android, iOS, Win32, Win64 in C++Builder? I've found only examples for Delphi.
If code is useful only during debugging, conditional compilation can be used to automatically remove the code for release builds. Prior to the advent of the Microsoft .NET platform, the traditional method of compiling conditionally using C++ or Visual Basic was to explicitly mark the regions of conditional code.
How to code a C or C++ program which can easily be ported to several operating systems. The easiest way is to use some cross-platform framework library like Qt or POCO (or perhaps libsdl or GTK) which has been ported to several platforms and provides a common set of abstractions.
You can conditionally compile blocks of code depending on the framework like this: Execute the .NET 5 executable in bin/Debug/net5.0/example.exe Execute the .NET Core 3.1 executable in bin/Debug/netcoreapp3.1/example.exe
C is a mid-level language and it needs a compiler to convert it into an executable code so that the program can be run on our machine. How do we compile and run a C program? Below are the steps we use on an Ubuntu machine with gcc compiler.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With