I would like to print a macro value (expand the macro) in the #warning directive.
For example, for the code:
#define AAA 17 #warning AAA = ???
The desired compile-time output would be
warning: AAA = 17
What do I use for ???, or, how do I augment the code?
The LENGTH and BREADTH are called the macro templates. The values 10 and 20 are called macro expansions. When the program run and if the C preprocessor sees an instance of a macro within the program code, it will do the macro expansion. It replaces the macro template with the value of macro expansion.
Macros allow you to write commonly used PL/I code in a way that hides implementation details and the data that is manipulated and exposes only the operations. In contrast with a generalized subroutine, macros allow generation of only the code that is needed for each individual use.
The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control. In many C implementations, it is a separate program invoked by the compiler as the first part of translation.
You can use the preprocessor directive #pragma message
.
Example:
#define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) #define AAA 123 #pragma message "content of AAA: " STR(AAA) int main() { return 0; }
The output may look like this:
$ gcc test.c test.c:5:9: note: #pragma message: content of AAA: 123 #pragma message("content of AAA: " STR(AAA)) ^
For reference:
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