C++Builder Quickly Learn To Check OS Platform Compiled In C++ Builder With Predefined Macros

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
Quickly Learn To Check OS Platform Compiled In C++ Builder With Predefined Macros
By Yilmaz Yoru March 16, 2021

Sometimes it is needed to understand compilation platform during compile or acting and designing UI elements in accordance with the platform. In this post we would like to give some examples to check some options in application codes. The C++ compiler predefines certain global identifiers, known as manifest constants. Most global identifiers begin and end with __ (two underscores) in C++.

Для просмотра ссылки Войди или Зарегистрируйся is the easiest and fastest C & C++ IDE for developing simple or professional applications on Windows, MacOS, iOS and Android operating systems. C++Builder has both CLANG Enhanced C/C++ Compiler and it’s new Borland C/C++ Compiler. It is also easy for beginners to learn with its wide range of samples, tutorials, help files and LSP support. C++ Builder comes with Rapid Application Development Studio, also knowns as RAD Studio, and C++ Builder is one of the most professional IDEs that work under RAD Studio. It also features a modern, high-productivity RAD Studio IDE, debugger tools, and enterprise connectivity for to accelerate cross-platform UI development. You can develop GUI based applications easily, as it comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs. There is a free C++ Builder Community Edition that can be used by students, beginners and startups with limitations.

You can download Free the C++ Builder Community Edition (CE) here: Для просмотра ссылки Войди или Зарегистрируйся. Professional developers can use the Professional, Architect or Enterprise versions of C++ Builder. You can download and use the trial version for one month with the same capabilities as the full version . Please visit Для просмотра ссылки Войди или Зарегистрируйся.

To understand compile platform you can use Для просмотра ссылки Войди или Зарегистрируйся to check platform operating system. All these macros are listed Для просмотра ссылки Войди или Зарегистрируйся. There are Для просмотра ссылки Войди или Зарегистрируйся Predefined Macros listed by LLVM.org Для просмотра ссылки Войди или Зарегистрируйся . Here below we listed some #if / #endif examples. Note that #definitions are cared in completion, so if something is not related with under this #if clauses it is not compiled. For example if you check your application is for Windows or not, your Windows specific codes are only compiled if it is compiled for windows. So by using these kind of Predefined Macros, all codes will not be include in compilation that will let your compiled file size as much as small with predefinitions.

Checking OS Platform
C++:
#if _WIN32 || _WIN64
    // do Windows based specific things
#elseif __ANDROID__         
    // do Android OS specific things
#elseif __APPLE__
    // do iOS specific things
#elseif __MACH__
    // do Mac-OS specific things
#else
    // do for other OSes if none of above
#endif
Checking Compilation if it is compiled with BCC or CLANG Compiler
C++:
#if __BORLANDC__
   // do things for BCC compiler
#elseif __clang__
   // do things for CLANG compiler
#endif
Checking Compilation if it is C only or C++
C++:
if __cplusplus
   // do c++ things
#else
   // do c things
#endif
Checking Compilation if it is for 32bit or 64bit Windows ( Inline usage)
C++:
#if _WIN32 || _WIN64
   #if _WIN64         
      std::cout << "Windows 64bits";
   #else         
      std::cout << "Windows 32bits";
   #endif
#endif
Checking ARM Platform if it is 32bit or 64bit
C++:
#if __arm__ || __arm64__
    // do ARM based specific things
    #if __arm__         
         // do things for ARM 32bits
    #elseif __arm64__
         // do things for ARM 64bits
    #endif
#endif