Is is possible to print to stderr the value of a preprocessor variable in C? For example, what I have right now is:
#define PP_VAR (10) #if (PP_VAR > 10) #warning PP_VAR is greater than 10 #endif
But what I'd like to do is:
#define PP_VAR (10) #if (PP_VAR > 10) #warning PP_VAR=%PP_VAR% #endif
Is something like this possible in C?
printf("%d", 5);
A preprocessor variable is specified in a %DECLARE statement with the FIXED, CHARACTER, or INITIAL attribute. No other attributes can be declared for a preprocessor variable, and attributes must not be repeated. (Other attributes are supplied by the preprocessor, however.)
When the C preprocessor is used with the C, C++, or Objective-C compilers, it is integrated into the compiler and communicates a stream of binary tokens directly to the compiler's parser. However, it can also be used in the more conventional standalone mode, where it produces textual output.
The C preprocessor is a macro preprocessor (allows you to define macros) that transforms your program before it is compiled. These transformations can be the inclusion of header files, macro expansions, etc.
You can print out the value of a preprocessor variable under visual studio. The following prints out the value of _MSC_VER:
#define STRING2(x) #x #define STRING(x) STRING2(x) #pragma message(STRING(_MSC_VER))
Not sure how standard this is though.
This works with GCC 4.4.3:
#define STRING2(x) #x #define STRING(x) STRING2(x) #pragma message "LIBMEMCACHED_VERSION_HEX = " STRING(LIBMEMCACHED_VERSION_HEX)
yields:
src/_pylibmcmodule.c:1843: note: #pragma message: LIBMEMCACHED_VERSION_HEX = 0x01000017
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With