Preprocessor #error Variable
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta c preprocessor print define value Discuss the workings and policies of this site About Us Learn c++ preprocessor # more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack gcc preprocessor print Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, c++ preprocessor if helping each other. Join them; it only takes a minute: Sign up Is it possible to print a preprocessor variable in C? up vote 31 down vote favorite 3 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
Gcc Pragma Message
> 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? c variables c-preprocessor share|improve this question edited Jun 5 at 17:18 Brian Tompsett - 汤莱恩 3,101132775 asked Jul 30 '09 at 2:54 apalopohapa 1,06631226 add a comment| 5 Answers 5 active oldest votes up vote 34 down vote accepted 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. share|improve this answer answered Feb 12 '12 at 21:01 MattM 44047 2 Its not standard, but GCC, MSVC, CLANG... (probably others support it too) –ideasman42 Jun 21 '15 at 2:45 add a comment| up vote 4 down vote 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_VERSIO
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site
Gcc Preprocessor Print Macro Value
About Us Learn more about Stack Overflow the company Business Learn more about c preprocessor directives hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join #pragma message the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Are there any C preprocessor http://stackoverflow.com/questions/1204202/is-it-possible-to-print-a-preprocessor-variable-in-c variables? up vote 2 down vote favorite Is there anything like a preprocessor variable in C? It could simplify my definitions. Currently I have something like this: typedef struct mystruct { int val1; int val2; int val3; int val4; } MYSTRUCT; typedef struct mysuperstruct { MYSTRUCT *base; int val; } MYSUPERSTRUCT; #define MY_OBJECT_BEGIN(name, val1, val2, val3, val4) \ MYSTRUCT name##Base = { val1, val2, val3, http://stackoverflow.com/questions/14527306/are-there-any-c-preprocessor-variables val4 }; \ MYSUPERSTRUCT * name##Objs = { #define MY_OBJECT_VALUE(name, val) \ { &(name##Base), val }, #define MY_OBJECT_END() \ NULL \ }; It is used this way: MY_OBJECT_BEGIN(obj1, 1, 2, 3, 4) MY_OBJECT_VALUE(obj1, 5) MY_OBJECT_VALUE(obj1, 6) MY_OBJECT_VALUE(obj1, 7) MY_OBJECT_END() Which generates something like this: MYSTRUCT obj1Base = { 1, 2, 3, 4 }; MYSUPERSTRUCT * obj1Objs = { { &(obj1Base), 5 }, { &(obj1Base), 6 }, { &(obj1Base), 7 }, NULL } It's obvious that repetitive use of the object name is redundant. I would like to store the name in the MY_OBJECT_BEGIN definition to some preprocessor variable so that I can use it the following way: MY_OBJECT_BEGIN(obj1, 1, 2, 3, 4) MY_OBJECT_VALUE(5) MY_OBJECT_VALUE(6) MY_OBJECT_VALUE(7) MY_OBJECT_END() Does standard C preprocessor provide a way to achieve this? c variables c-preprocessor share|improve this question edited Apr 23 at 21:47 Brian Tompsett - 汤莱恩 3,101132775 asked Jan 25 '13 at 17:36 yman 46110 3 I always like to mention X macros when this sort of thing comes up... –Oliver Charlesworth Jan 25 '13 at 17:43 add a comment| 2 Answers 2 active oldest votes up vote 5 down vote accepted There are no standard C preprocessor variab
they are actually compiled. Before the actual compilation of every C program it is passed through a Preprocessor. The Preprocessor looks through the program trying to https://en.wikibooks.org/wiki/C_Programming/Preprocessor find out specific instructions called Preprocessor directives that it can understand. All Preprocessor directives begin with the # (hash) symbol. C++ compilers use the same C preprocessor.[1] The preprocessor is a part of the compiler which performs preliminary operations (conditionally compiling code, including files etc...) to your code before the compiler sees it. These transformations are lexical, meaning that the c preprocessor output of the preprocessor is still text. NOTE: Technically the output of the preprocessing phase for C consists of a sequence of tokens, rather than source text, but it is simple to output source text which is equivalent to the given token sequence, and that is commonly supported by compilers via a -E or /E option -- although command line options c preprocessor print to C compilers aren't completely standard, many follow similar rules. Contents 1 Directives 1.1 #include 1.1.1 Headers 1.2 #pragma 1.3 #define 1.4 macros 1.5 #error 1.6 #warning 1.7 #undef 1.8 #if,#else,#elif,#endif (conditionals) 1.9 #ifdef,#ifndef 2 Useful Preprocessor Macros for Debugging 2.1 Compile-time assertions 2.2 X-Macros Directives[edit] Directives are special instructions directed to the preprocessor (preprocessor directive) or to the compiler (compiler directive) on how it should process part or all of your source code or set some flags on the final object and are used to make writing source code easier (more portable for instance) and to make the source code more understandable. Directives are handled by the preprocessor, which is either a separate program invoked by the compiler or part of the compiler itself. #include[edit] C has some features as part of the language and some others as part of a standard library, which is a repository of code that is available alongside every standard-conformant C compiler. When the C compiler compiles your program it usually also links it with the standard C library. For example, on encountering a #in