Ansi C Preprocessor #error
Contents |
message. You would use ‘#error’ inside of configure error c++ preprocessor a conditional that detects a combination of configure error c++ preprocessor /lib/cpp fails sanity check centos parameters which you know the program does not properly support. For c++ preprocessor if example, if you know that the program will not run properly on a VAX, you might write #ifdef __vax__
C++ Preprocessor Stringify
#error "Won't work on VAXen. See comments at get_last_object." #endif If you have several configuration parameters that must be set up by the installation in a consistent way, you can use conditionals to detect an inconsistency and report visual c++ preprocessor it with ‘#error’. For example, #if !defined(FOO) && defined(BAR) #error "BAR requires FOO." #endif The directive ‘#warning’ is like ‘#error’, but causes the preprocessor to issue a warning and continue preprocessing. The tokens following ‘#warning’ are used as the warning message. You might use ‘#warning’ in obsolete header files, with a message directing the user to the header file which should be used instead. Neither ‘#error’ nor ‘#warning’ macro-expands its argument. Internal whitespace sequences are each replaced with a single space. The line must consist of complete tokens. It is wisest to make the argument of these directives be a single string constant; this avoids problems with apostrophes and the like.
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 About Us Learn more about Stack Overflow the company Business Learn more about hiring developers c++ preprocessor definitions or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x
C++ Preprocessor Stringize
Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only
C++ Preprocessor Tricks
takes a minute: Sign up How do I generate an error or warning in the C preprocessor? up vote 19 down vote favorite 1 I have a program that must be compiled only in DEBUG mode. (testing purpose) How can https://gcc.gnu.org/onlinedocs/cpp/Diagnostics.html I have the preprocessor prevent compilation in RELEASE mode? c-preprocessor share|improve this question edited Jun 25 at 23:11 phs 7,05822761 asked Feb 8 '10 at 12:29 Eonil 30.9k43202376 add a comment| 7 Answers 7 active oldest votes up vote 34 down vote accepted Place anywhere: #ifndef DEBUG #error Only Debug builds are supported #endif share|improve this answer answered Feb 8 '10 at 12:33 Hans Passant 652k809511598 add a comment| up vote 11 down vote C provide a #error statement, and http://stackoverflow.com/questions/2221517/how-do-i-generate-an-error-or-warning-in-the-c-preprocessor most compilers add a #warning statement. The gcc documentation recommends to quote the message. share|improve this answer edited Nov 17 '15 at 17:28 answered Feb 8 '10 at 12:37 philant 22.8k94890 1 @Antonio Right, there is no [more] recommendation there. I replaced the link with one to gcc doc. –philant Nov 17 '15 at 17:29 add a comment| up vote 4 down vote You can use a error directive for that. The following code will throw an error at compile time if DEBUG is not defined: #ifndef DEBUG #error This is an error message #endif share|improve this answer edited Feb 8 '10 at 23:32 answered Feb 8 '10 at 12:34 Laurent Etiemble 20.9k44075 Sorry, I mix pragma and error while typing. Corrected in answer. –Laurent Etiemble Feb 8 '10 at 23:32 add a comment| up vote 4 down vote Maybe something more sofisticated, but it is only copy&paste of previous solutions. :-) #ifdef DEBUG #pragma message ( "Debug configuration - OK" ) #elif RELEASE #error "Release configuration - WRONG" #else #error "Unknown configuration - DEFINITELY WRONG" #endif P.S. There is also one way how to generate warning. Create unreferenced labe like HereIsMyWarning: and don't reference it. During compilation you will get warning like 1>..\Example.c(71) : warning C4102: 'HereIsMyWarning' : unreferenced label share|improve this answer edited May 27 '15 at 15:20 Janito Vaqueiro Ferreira Filho 3,2641820 answered May 27 '15 at 10:26 Zdeno Pavlik 1088 add a
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 About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads http://stackoverflow.com/questions/12637392/c-preprocessor-expand-macro-in-a-warning with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack http://stackoverflow.com/questions/3826832/is-there-a-portable-way-to-print-a-message-from-the-c-preprocessor Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up C preprocessor: expand macro in a #warning up vote 19 down vote favorite 9 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 = c++ preprocessor ??? The desired compile-time output would be warning: AAA = 17 What do I use for ???, or, how do I augment the code? c gcc c-preprocessor share|improve this question edited Nov 2 '14 at 18:56 AstroCB 7,808113261 asked Sep 28 '12 at 9:35 elomage 1,68811015 1 According to the C standard from 1999, you only have #error for something like that and it does not expand any macros, it just prints the text literally and causes compilation to stop. What are configure error c++ you trying to achieve with this anyway? –Alexey Frunze Sep 28 '12 at 9:41 I have a hierarchy of many makefiles that define AAA in various ways, depending on the make target parameters. I would like to verify that the definition is correct for the target. And I would not want to create a list of #if AAA = 1 ... #warning "is 1"... –elomage Sep 28 '12 at 9:44 Also, this is for the embedded world with no displays, so I can not easily test the macro value by adding something like printf( #AAA ); and check it at runtime. –elomage Sep 28 '12 at 9:58 So you do #if A == 1\#error A = 1\#elif A == 2\#error A = 2\#endif. –Alexey Frunze Sep 28 '12 at 10:00 @AlexeyFrunze That is exactly what I want to avoid - see my comment above. I may not know all the possible values, or there might be too many of those. –elomage Sep 28 '12 at 10:09 | show 1 more comment 4 Answers 4 active oldest votes up vote 26 down vote accepted 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 refe
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 About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Is there a portable way to print a message from the C preprocessor? up vote 50 down vote favorite 8 I would like to be able to do something like #print "C Preprocessor got here!" for debugging purposes. What's the best / most portable way to do this? printing c-preprocessor share|improve this question edited Feb 14 at 11:02 Brian Tompsett - 汤莱恩 3,078112675 asked Sep 30 '10 at 0:16 Andrew Wagner 4,733103761 add a comment| 6 Answers 6 active oldest votes up vote 46 down vote accepted The warning directive is probably the closest you'll get, but it's not entirely platform-independent: #warning "C Preprocessor got here!" AFAIK this works on most compilers except MSVC, on which you'll have to use a pragma directive: #pragma message ( "C Preprocessor got here!" ) share|improve this answer answered Sep 30 '10 at 0:24 You 12k13252 2 Which begs the question, can you put a directive based on a compilation flag to swap "pragma message" and "warning" somehow? For example, something like: #ifdef _LINUX #define #preprocmsg "#warning" else #define #preprocmsg "#pragma message"... I'll have to try that but instinct tells me the answer is no. –Bryan Sep 30 '10 at 0:41 3 @Bryan: Yes. #define WARNING(msg) _Pragma("message " #msg) –Matt Joiner Mar 2 '11 at 7:31 #pragma message () is not supported by older versions of gcc (such as gcc 4.1.2, the default version on RHEL5). I have yet to find an appropriate equivalent for these older versions - #warning is not going to be great, as warnings are treated as errors for us generally, and we'd really like the message to be informational, rather than stop the com