C++Code SnippetGeneric ProgrammingLanguage FeatureLearn 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

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

Checking ARM Platform if it is 32bits or 64bits

Checking 64bit Compilation in GNU C Projects

Checking 64bit Compilation on Runtime of GNU C Projects

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).

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

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

C++C++11C++14C++17Introduction to C++Learn C++Syntax

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?