Search code examples
c++preprocessor-directivexlc

IBM XL C/C++ Compiler: check compiler mode using preprocessor directive


I am trying to compile a sample c++ file test.cpp using IBM xlC compiler on AIX system. The file should be compiled in both 32-bit and 64-bit modes. I am using following commands to compile them in both modes:

xlC test.cpp (default compiler mode is 32-bit)

xlC -q64 test.cpp

Under test.cpp, I have to printf("Using 32-bit compiler") if compiling for 32-bit and printf("Using 64-bit compiler") if compiling for 64-bit.

How can I achieve this using preprocessor conditionals? Is there a pre-defined macro either for compiler or for machine architecture that tells the difference?


Solution

  • in XLC, if you are using the -q64 flag, the macro __64BIT__ is defined.

    Straight from IBM XL C/C++'s documentation:

    If the compiler is invoked in 64-bit mode, the __64BIT__ preprocessor macro is defined.