C99 preprocessor features adopted in C++11 (C++11)
In the C++11 standard, several C99 preprocessor features are adopted to provide a common preprocessor interface for C and C++ compilers. This eases porting C source files to the C++ compiler and eliminates some subtle semantic differences that exist between the old C and C++ preprocessors, thus avoiding preprocessor compatibility issues or diverging preprocessor behaviors.
Preprocessor arithmetic with extended integer types
In the C89, C++98, and C++03 preprocessors, integer literals that have int or unsigned int type are widened to long or unsigned long. However, in the C99 and C++11 preprocessors, all signed and unsigned integer types (character types included) are widened to long long or unsigned long long under normal circumstances in XL C/C++.
If this feature is enabled, and both -qnolonglong and -qlanglvl=noc99longlong are set in either -q32 or -q64 modes, the preprocessor still uses long long or unsigned long long representations for all integral and character literals in preprocessor controlling expressions.
The following example is valid on the where the underlying type of wchar_t is unsigned short.
#if ~0ull == 0u + ~0u
#error C++11 preprocessor arithmetic! 0u has the same representation as 0ull,\
hence ~0ull == 0u + ~0u
#else
#error non-C++11 preprocessor arithmetic. 0ul does not have the same \
representation as 0ull, hence ~0ull != 0u + ~0u
#endif
If this feature is disabled and -qwarn0x is set, the C++11 preprocessor evaluates the controlling expressions in the #if and #elif directives, and compares the evaluation results against that of the non-C++11 preprocessor. If they are different, the compiler warns you that the preprocessor controlling expression evaluates differently between C++11 and non-C++11 language levels.
Mixed string literal concatenation
#include <wchar.h>
#include <stdio.h>
int main()
{
wprintf(L"Guess what? %ls\n", "I can now concate" L"nate regular strings\
and wide strings!");
printf("Guess what? %ls\n", L"I can now concate" "nate strings\
this way too!");
}
This example prints the following output when it is executed:Guess what? I can now concatenate regular strings and wide strings!
Guess what? I can now concatenate strings this way too!
Diagnostic for header files and include names
//inc.C
#include "0x/mylib.h"
int main()
{
return 0;
}
When compiling or preprocessing this example with this
feature enabled, the compiler issues the following warning message:"inc.C", line 1.10: 1540-0893 (W) The header file name "0x/mylib.h"
in #include directive shall not start with a digit.
Increased limit for #line directives
#line 1000000 //Valid in C++11, but invalid in C++98
int main()
{
return 0;
}
Diagnostic for object-like macro definitions
//w.C
//With -qnodollar, '$' is not part of the macro name,
//thus it begins the replacement list
#define A$B c
#define STR2( x ) # x
#define STR( x ) STR2( x )
char x[] = STR( A$B );
When compiling or preprocessing
this example with this feature enabled and -qnodollar is
specified, the compiler issues the following warning message:"w.C", line 1.10: 1540-0891 (W) Missing white space between
the identifier "A" and the replacement list.
The _Pragma operator
#pragma comment(copyright, "IBM 2010")
_Pragma("comment(copyright, \"IBM 2010\")")
_Pragma("comment(copyright, \"IBM 2010\")")
int main()
{
return 0;
}
Variadic macros and empty macro arguments
Variadic macros and empty macro arguments are supported in C99 and C++11. For details, see Variadic macros.
Predefined macros
- __STDC__
- __STDC_VERSION__
- __STDC_ISO_10646_