Ifdef Error
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 Learn more about Stack Overflow the company Business Learn more about
#warning In C
hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask k&r preferred method Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. c preprocessor message Join them; it only takes a minute: Sign up #error directive in C? up vote 21 down vote favorite 4 Can you please give the information about #error directive in C? What is #error directive? what the use of https://msdn.microsoft.com/en-us/library/c8tk0xsk.aspx it? c share|improve this question edited Mar 13 '13 at 23:21 Kornel 62.7k24138200 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. 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 http://stackoverflow.com/questions/5323349/error-directive-in-c 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.7k47490 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 error. –RastaJedi Apr 19 at 19:57 add a comment| up vote 12 down vote I may have invalid code but its something like... #if defined USING_SQLITE && defined USING_MYSQL #error You cannot use both sqlite and mysql at the same time #endif #if !(defined USING_SQLITE && defined USING_MYSQL) #error You must use either sqlite or mysql #endif #ifdef USING_SQLITE //... #endif #ifdef USING_MYSQL //... #endif sh
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 http://stackoverflow.com/questions/426736/error-macro-names-must-be-identifiers-using-ifdef-0 Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs http://www.people.vcu.edu/~jsiebers/mcnpinfo/dcomment/manual/node9.html 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 Error: macro names must be identifiers using #ifdef 0 up vote 24 down vote favorite 6 I have the source code of an in c application written in C++ and I just want to comment something using: #ifdef 0 ... #endif And I get this error error: macro names must be identifiers Why is this happening? c++ macros c-preprocessor share|improve this question edited Nov 27 '15 at 11:33 Brian Tompsett - 汤莱恩 3,091132775 asked Jan 9 '09 at 1:27 Eduardo 4,225164567 I think you misremembered; #ifdef 0 is an error in C as well as C++. –Jonathan #error in c Leffler Jan 9 '09 at 2:25 2 You are right I misrembered, It does not work in C, I am not going to delete the question because maybe someone in the future makes the same mistake. –Eduardo Jan 9 '09 at 5:36 @Eduardo Thanks for not deleting the question. –kartik Feb 24 '14 at 8:00 add a comment| 6 Answers 6 active oldest votes up vote 47 down vote accepted The #ifdef directive is used to check if a preprocessor symbol is defined. The standard (C11 6.4.2 Identifiers) mandates that identifiers must not start with a digit: identifier: identifier-nondigit identifier identifier-nondigit identifier digit identifier-nondigit: nondigit universal-character-name other implementation-defined characters> nondigit: one of _ a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z digit: one of 0 1 2 3 4 5 6 7 8 9 The correct form for using the pre-processor to block out code is: #if 0 : : : #endif You can also use: #ifdef NO_CHANCE_THAT_THIS_SYMBOL_WILL_EVER_EXIST : : : #endif but you need to be confident that the symbols will not be inadve
determine the fate of information processed the preprocessor. The syntax of the conditional directives are: #ifdef Name0 lines to evaluate if Name0 is defined #elseif Name1 lines to evaluate if Name1 is defined, and Name0 is Not defined ... #elif NameN lines to evaluate if NameN is defined, and Name0-Name(N-1) is Not defined #else lines to evaluate if Name0-NameN are Not defined #endif and #ifndef Name0 lines to evaluate if Name0 is Not defined #elseif Name1 lines to evaluate if Name1 is defined, and Name0 is defined #else lines to evaluate if Name0 is defined and Name1 is Not defined #endif The expression #ifdef Name evaluates to true in Name has been #defined. In this case (true), the input file lines are processed until a #elseif, #else, or #endif directive is encountered. The #elseif, #else, and #endif directives are valid only following a #ifdef directive. If the #ifdef directive evaluated to be true, t hen these directives (#elseif, #else, and #endif) stop processing of the input lines until a #endif directive is encounter. Thus, the code /* simple_ifdef.inp */ #define TEST1 #define TEST2 #ifdef TEST1 test1 is defined, test2 and test3 are unchecked #elseif TEST2 test1 is not defined, test2 is defined, test3 is unchecked #elseif TEST3 test1 and test2 are not defined, test3 is defined #else test1, test2, test3 are not defined. #endif /* check for TEST2 alone */ #ifdef TEST2 test2 is defined #endif evaluates to be test1 is defined, test2 and test3 are unchecked test2 is defined If an #ifdef is evaluated to be false, then the #elseif directive is processed as if it was an #ifdef directive. If all #elseif directives evaluate to be false, the #else directive is processed if it exists. Input is evaluated until an #endif directive is encountered. A #endif directive ends the #ifdef processing. #ifdef directives can be nested, however, all directives in a given logical level must exist in a single file. The following sample code showi