Gcc Preprocessor #error #warning
Contents |
message. You would use ‘#error’ inside of gcc #warning a conditional that detects a combination of gcc #pragma message parameters which you know the program does not properly support. For #warning c++ example, if you know that the program will not run properly on a VAX, you might write #ifdef __vax__ #error in c #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
C Preprocessor Message
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
Invalid Preprocessor Command 'warning'
developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask #error c++ 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 gcc #error them; it only 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. https://gcc.gnu.org/onlinedocs/cpp/Diagnostics.html (testing purpose) How can I have the preprocessor prevent compilation in RELEASE mode? c-preprocessor share|improve this question edited Jun 25 at 23:11 phs 7,05722761 asked Feb 8 '10 at 12:29 Eonil 31.1k43203377 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 655k819611605 add a comment| up vote 11 down vote C http://stackoverflow.com/questions/2221517/how-do-i-generate-an-error-or-warning-in-the-c-preprocessor provide a #error statement, and 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.9k94890 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 21k44075 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,2741820 an
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 http://stackoverflow.com/questions/3826832/is-there-a-portable-way-to-print-a-message-from-the-c-preprocessor 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 http://www.linuxtopia.org/online_books/an_introduction_to_gcc/gccintro_93.html 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 c preprocessor 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,091132775 gcc preprocessor #error asked Sep 30 '10 at 0:16 Andrew Wagner 4,759103761 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 12.1k13252 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 - #w
Web Development GUI Toolkits/Desktop Databases Mail Systems openSolaris Eclipse Documentation Techotopia.com Virtuatopia.com How To Guides Virtualization General System Admin Linux Security Linux Filesystems Web Servers Graphics & Desktop PC Hardware Windows Problem Solutions <<< previous table of contents next >>> 13.1 Preprocessor error messages No such file or directory This error occurs if GCC cannot find a requested file on its search path. The file may have been specified on the command-line, or with a preprocessor #include statement. Either the filename has been spelled incorrectly or the directory for the file needs to be added to the include path or link path. Example: #include