Gcc Compiler Directives #error
Contents |
message. You would use ‘#error’ inside of #error in c a conditional that detects a combination of
#error C++
parameters which you know the program does not properly support. For gcc #pragma message example, if you know that the program will not run properly on a VAX, you might write #ifdef __vax__
Gcc #error
#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 gcc #warning 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 or
#error In C Example
posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss
C Preprocessor Message
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 #warning in c takes a minute: Sign up GCC #pragma to stop compilation up vote 19 down vote favorite 1 Is there a GCC pragma directive that will stop,halt, or abort the compilation process? I am using gcc 4.1 but would want the pragma https://gcc.gnu.org/onlinedocs/cpp/Diagnostics.html to be available on gcc 3.x versions also. gcc share|improve this question asked Jan 23 '10 at 22:15 Sean A.O. Harney 13.9k42027 1 We might be able to provide a better answer if you tell us why you want compilation to stop. –Michael Jan 23 '10 at 22:22 add a comment| 4 Answers 4 active oldest votes up vote 31 down vote accepted You probably want #error: edd@ron:/tmp$ g++ -Wall -DGoOn -o stopthis stopthis.cpp edd@ron:/tmp$ ./stopthis Hello, world edd@ron:/tmp$ g++ http://stackoverflow.com/questions/2124968/gcc-pragma-to-stop-compilation -Wall -o stopthis stopthis.cpp stopthis.cpp:7:6: error: #error I had enough edd@ron:/tmp$ cat stopthis.cpp #include
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft #error in c Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. C/C++ Preprocessor Reference Preprocessor
developers of the MPLAB IDE » Effective C Tip #9 – use #warning Thursday, September 1st, 2011 by Nigel Jones This is the ninth in a series of tips on writing effective C. Way back in 1999 I wrote an article for Embedded Systems Programming concerning the #error directive. If you aren't particularly familiar with #error, then I suggest you read the article. While the #error directive has remained one of my most popular tools, I have become an equally big fan of #warning. Before I delve into the uses of #warning, I must warn you (if you would pardon the pun) that #warning is a non standard directive. However it is supported by IAR, GCC, Microchip's C18 compiler, Hi-Tech and probably a whole raft of other vendors. In other words, it's pretty standard for a non-standard feature. The use of #warning is simple enough: #warning This is a warning This will result in the compiler issuing a warning with the text ‘This is a warning' printed to stderr. Please note that, just as for #error, there is *no* requirement that the text be in quotes. If you insist on putting quotes around the text, then they will be printed to stderr as well. With the syntax out of the way, here's some of the ways that I use #warning. Protecting Incomplete Code Very often when I'm coding, I like to get the big picture in place without worrying about the minutiae of the implementation details. As a result I end up with functions or loop bodies that are incomplete. In these cases I simply add a #warning to alert me to the issue. For example void foo(void) { #warning To be completed } Thus what happens now is that whenever I compile the module, I get a warning (i.e. reminder) that there is something important still to be done. Commenting Out Code I *never* comment code out anymore as part of the debugging process, as it is simply too easy to forget that the code has been removed. Instead I use this con