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++ codes.

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.

close

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

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++C++11C++14C++17Introduction to C++Learn C++

How To Access Individual Character Elements Of A C++ String

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

The Right Way To Access Character Elements Of A Wide String

C++Language FeatureLearn C++

You NEED to Learn To Use JSON (JavaScript Object Notation)

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

You Need To Know How To Correctly Remove Characters From C++ Strings

en_USEnglish