Originally posted by: ChristineLi
Are you developing programs consumed by multiple compilers?
If your answer is yes and the IBM XL C/C++ compilers are among your target compilers (either for AIX, Linux for big endian distributions or Linux for little endian distributions), you will be interested in this blog.
There is a quick way to distinguish code you wish to be consumed by XL C/C++ from code you wish to be consumed by other compilers.
Leverage the macros listed in Table 1 to identify the IBM XL C/C++ compiler. Note that besides the ones listed in Table 1, more macros that identify XL C/C++ are predefined, which is covered in the Further information section below.
#ifdef macro-to-identify-XL
your_code_for_XL_C/C++
#endif
Table 1. Macros recommended to use to identify the IBM XL C/C++ compiler
IBM XL compiler
|
Predefined macro name
|
Description
|
Predefined value
|
XL C/C++ for Linux for little endian distributions (that is, releases starting from V13.1.1)
|
__ibmxl__ (most commonly used)
|
Indicates the XL C/C++ compiler is being used.
|
1
|
- XL C/C++ for AIX
- XL C/C++ for Linux for big endian distributions (that is, V13.1.0 and previous releases)
|
__IBMC__ (C only)
|
Indicates the level of the XL C compiler.
|
An integer in format VRM, where:
V
Represents the version number
R
Represents the release number
M
Represents the modification number
|
__IBMCPP__ (C++ only)
|
Indicates the level of the XL C++ compiler.
|
An integer in format VRM, where:
V
Represents the version number
R
Represents the release number
M
Represents the modification number
|
__xlc__ (C only)
|
Indicates the level of the XL C compiler.
|
A string in format V.R.M.F, where:
V
Represents the version number
R
Represents the release number
M
Represents the modification number
F
Represents the fix level
|
__xlC__
|
Indicates the VR level of the XL C and XL C++ compilers in hexadecimal format.
|
A 4-digit hexadecimal integer in format 0xVVRR, where:
V
Represents the version number
R
Represents the release number
|
Most of the macros related to the XL C/C++ compiler are predefined and protected, which means that the compiler will issue a warning if you try to undefine or redefine them. You can use the -qshowmacros -E compiler options to view the values of the predefined macros.
Note that these macros contain two underscores (‘__’) as a prefix and a suffix. The use of such two underscores in identifiers is reserved for the compiler's internal use according to the ANSI-C standard.
Further information
- You may notice that for XL C/C++ for Linux, the macros predefined by the compiler to identify the XL compiler for little endian and big endian distributions are different, requiring migration effort when you move from big endian to little endian. To ease your migration effort, starting from V13.1.2, XL C/C++ for Linux (little endian distrubutions) provides a compiler option -qxlcompatmacros to define macros __IBMCPP__, __IBMC__, __xlc__, __xlC__, and __xlC_ver__.
Note that the default setting of -qxlcompatmacros changes along with the version of XL C/C++ for Linux, as shown in Table 2:
Table 2: Default setting of option -qxlcompatmacros for XL C/C++ for Linux releases
XL C/C++ for Linux
|
Compiler default option setting
|
V13.1.2
|
-qxlcompatmacros
|
V13.1.3
|
V13.1.4
|
V13.1.5
|
V13.1.6
|
-qnoxlcompatmacros
The __IBMCPP__, __IBMC__, __xlc__, __xlC__, and __xlC_ver__ macros are not predefined.
|
V16.1 (Note that there is no V14/V15.)
|
For more information about compiler behavior for XL C/C++ for Linux, V16.1, see -qxlcompatmacros.
- Besides IBM XL specific macros, XL C/C++ for Linux for little endian distributions also predefines some Clang related macros, as shown in Table 3. The reason is that XL C/C++ for Linux for little endian distributions combines the Clang front end infrastructure with the optimization technology in the IBM compiler back end. The predefined Clang related macros correctly reflect the architecture.
Table 3. Predefined macros related to Clang for XL C/C++ for Linux for little endian distributions
IBM XL compiler
|
Predefined macro name
|
Description
|
Predefined value
|
XL C/C++ for Linux for little endian distributions (that is, releases starting from V13.1.1)
|
__clang__
|
Indicates that the Clang front end is used.
|
- Changes per release
- “1” for XL C/C++ for Linux for little endian distributions, V16.1
|
What’s next?
Are you programming across multiple platforms? Stay tuned for our future blog on tips about differentiating platforms.