Error Preprocessor Directive C
Contents |
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 #error in c example Learn more about Stack Overflow the company Business Learn more about hiring developers
#warning In C
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow #error c++ 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 #error directive in C? up vote 21 down error directive must use c++ for the type iostream vote favorite 4 Can you please give the information about #error directive in C? What is #error directive? what the use of it? c share|improve this question edited Mar 13 '13 at 23:21 Kornel 62.6k24138199 asked Mar 16 '11 at 5:59 PHP 1,16631739 migrated from programmers.stackexchange.com Mar 16 '11 at 9:38 This question came from our site for professional programmers interested in conceptual questions about software development.
#error Gcc
4 This seems more like a question for stackoverflow.com –jmort253 Mar 16 '11 at 6:29 add a comment| 3 Answers 3 active oldest votes up vote 24 down vote accepted It's a preprocessor directive that is used (for example) when you expect one of several possible -D symbols to be defined, but none is. #if defined(BUILD_TYPE_NORMAL) # define DEBUG(x) do {;} while (0) /* paranoid-style null code */ #elif defined(BUILD_TYPE_DEBUG) # define DEBUG(x) _debug_trace x /* e.g. DEBUG((_debug_trace args)) */ #else # error "Please specify build type in the Makefile" #endif When the preprocessor hits the #error directive, it will report the string as an error message and halt compilation; what exactly the error message looks like depends on the compiler. share|improve this answer answered Mar 16 '11 at 6:09 geekosaur 34.6k47490 1 That is one paranoid null statement... –Chris Lutz Mar 16 '11 at 9:40 Wouldn't it be more appropriate to say it halts preprocessing? I guess preprocessing can be viewed as a step in compilation, but it can definitely be done as a separate step, and is internally performed as a separate step, so it fails/reports a fatal error earlier on than a compilation
message. You would use ‘#error’ inside of #error access a conditional that detects a combination of use of #error directive in c parameters which you know the program does not properly support. For
K&r Preferred Method
example, if you know that the program will not run properly on a VAX, you might write #ifdef __vax__ http://stackoverflow.com/questions/5323349/error-directive-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 https://gcc.gnu.org/onlinedocs/cpp/Diagnostics.html 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 http://stackoverflow.com/questions/171435/portability-of-warning-preprocessor-directive About Us Learn more about Stack Overflow the company Business Learn more about http://www.barrgroup.com/embedded-systems/how-to/c-preprocessor-error-directive 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 Portability of #warning preprocessor in c directive up vote 38 down vote favorite 2 I know that the #warning directive is not standard C/C++, but several compilers support it, including gcc/g++. But for those that don't support it, will they silently ignore it or will it result in a compile failure? In other words, can I safely use it in my project without breaking the build for compilers that don't support error preprocessor directive it? c++ compiler-construction warnings c-preprocessor portability share|improve this question edited Jun 3 at 20:00 Brian Tompsett - 汤莱恩 3,093132775 asked Oct 5 '08 at 3:40 jonner 3,05051927 add a comment| 5 Answers 5 active oldest votes up vote 19 down vote accepted It is likely that if a compiler doesn't support #warning, then it will issue an error. Unlike #pragma, there is no recommendation that the preprocessor ignore directives it doesn't understand. Having said that, I've used compilers on various different (reasonably common) platforms and they have all supported #warning. share|improve this answer answered Oct 5 '08 at 3:53 Greg Hewgill 511k1088801044 add a comment| up vote 60 down vote It should be noted that MSVC uses the syntax: #pragma message ( "your warning text here" ) The usual #warning syntax generates a fatal error C1021: invalid preprocessor command 'warning' so it is not portable to those compilers. share|improve this answer answered Nov 11 '08 at 0:30 nolandda 1,09721015 20 This is one of the rare cases, when MS does things in the right way. –doc Aug 5 '10 at 14:05 Is MSVC syntax portable? I mean, would it properly
Witness ExpertiseProduct Liability Automotive Electronics Medical Device Design Computer Security Process & Architecture Safety & Reliability all... How-ToArticles Books Coding Standard Glossary Webinars Skills Tests Surveys BlogsNews Barr Code Coding Standards Device Security Expert Witness Software Safety Registration for Fall Training Courses Now Open. See our complete training calendar. Glossary Find definitions for technical terms in our Embedded Systems Glossary. A B C D EF G H I JK L M N OP Q R S TU V W X YZ Symbols Test Your Skills How good are your embedded programming skills? Test yourself in the Embedded C Quiz or the Embedded C++ Quiz. Newsletter Signup Want to receive free how-to articles and industry news as well as announcements of free webinars and other training courses by e-mail? Signup Today! How to Use the C Preprocessor's #error Directive Wed, 1999-09-01 00:00 - Nigel Jones by Nigel Jones One of the least used but potentially most useful features of the C preprocessor is the ANSI-specified #error directive. Here's a look at a couple of clever uses for #error that have proven invaluable in embedded software development. The syntax of #error is very straightforward: #error