Search code examples
c++platformbit

How to determine architecture in platform neutral way?


I have a C++ app that uses wxWidgets. Certain parts of the app differ for 32 and 64 bit hosts. Currently I use sizeof(void *), but is there a better way that uses conditional compilation and is platform neutral?


Solution

  • Typically people use #defines to determine bitness (the exact define will depend on the compiler). This is better than a runtime approach using sizeof(void*).

    As for platform neutral, well, some compilers are on multiple platforms..