Site icon Learn C++

Learn How To Check The 32bitness Or 64bitness Your C++ Application

If you are looking to a way to reliably determine whether C++ code is being compiled in 32 bits or 64 bits there is way to check in C++ code.

For a cross platform compilation (cross compiler environments like FireMonkey framework in C++ Builder) there is no single reliable method to check if your application is running as a 32bits or 64bits application. Note that lower bits applications (i.e 32 bits) can run on higher bits operating systems, but you can not run higher bits applications in lower bits operating systems. Both _WIN32 and _WIN64 can sometimes both be undefined, if the project settings are wrong or missing. A project labelled “Win32” could be set to 64-bit, due to a project configuration error.

Sometimes (like happened before on Visual Studio 2008 SP1) intellisense / codeinsights does not grey out the correct parts of the code, according to the current #define which makes it difficult to see exactly which #define is being used at compile time.

You can use Predefined Macros to check platform operating system. All these macros are listed here. There are CLANG Predefined Macros listed by LLVM.org here . 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 Compilation if it is for 32bits or 64bits Windows

[crayon-67428274d4413291976700/]

Checking Compilation on Runtime if it is for 32bits or 64bits Windows

[crayon-67428274d441d874409793/]

Checking ARM Platform if it is 32bits or 64bits

[crayon-67428274d441f573469384/]

Checking 64bit Compilation in GNU C Projects

[crayon-67428274d4421162773014/]

Checking 64bit Compilation on Runtime of GNU C Projects

[crayon-67428274d4425921827879/]

Checking 64bit Compilation with Void Pointer Size
This method may not work for all compilers, in some compiler options void size might be 4 bytes (32bits) while it is compiled for 64bits (8 bytes).

[crayon-67428274d4427023217958/]

Please see full list of Predefined Macros to examine more options about OS & Compiler based options.

Exit mobile version