Error Directive In 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
What Is The Purpose Of The Preprocessor Directive #error
Us Learn more about Stack Overflow the company Business Learn more about hiring preprocessor directive #error in c developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the use of #error directive in c 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 directive in C? up
#error In C Example
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 it? c share|improve this question edited Mar 13 '13 at 23:21 Kornel 62.5k24136198 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
#define #error
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 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.5k47390 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/r
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners #error c preprocessor ISV Startups TechRewards Events Community Magazine Forums Blogs Channel
#warning In C
9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. The content #error c++ you requested has been removed. You’ll be auto redirected in 1 second. C/C++ Preprocessor Reference Preprocessor Preprocessor Directives Preprocessor Directives #error Directive #error Directive http://stackoverflow.com/questions/5323349/error-directive-in-c #error Directive #define Directive #error Directive #if, #elif, #else, and #endif Directives #ifdef and #ifndef Directives #import Directive #include Directive #line Directive Null Directive #undef Directive #using Directive TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. https://msdn.microsoft.com/en-us/library/c8tk0xsk.aspx This documentation is archived and is not being maintained. #error Directive (C/C++) Visual Studio 2015 Other Versions Visual Studio 2013 Visual Studio 2012 Visual Studio 2010 Visual Studio 2008 Visual Studio 2005 Visual Studio .NET 2003 The #error directive emits a user-specified error message at compile time and then terminates the compilation.Syntax Copy #errortoken-string RemarksThe error message that this directive emits includes the token-string parameter. The token-string parameter is not subject to macro expansion. This directive is most useful during preprocessing for notifying the developer of a program inconsistency or the violation of a constraint. The following example demonstrates error processing during preprocessing: Copy #if !defined(__cplusplus) #error C++ compiler required. #endif See AlsoPreprocessor Directives Show: Inherited Protected Print Export (0) Print Export (0) Share IN THIS ARTICLE Is this page helpful? Yes No Additional feedback? 1500 characters remaining Submit Skip thi
MySQL MariaDB PostgreSQL SQLite MS Office Excel Access Word Web Development HTML CSS Color Picker Languages C Language More https://www.techonthenet.com/c_language/directives/error.php ASCII Table Linux UNIX Java Clipart Techie Humor Advertisement C Language Introduction Compiling and Linking File Naming Preprocessor Directives #include #define #undef #if #ifdef #ifndef https://www-s.acm.illinois.edu/webmonkeys/book/c_guide/1.7.html #elif #else #endif #warning #error Comments Variables Integer Variables Float Variables First Program assert.h Functions ctype.h Functions locale.h Functions math.h Functions setjmp.h Functions signal.h Functions in c stdarg.h Functions stdio.h Functions stdlib.h Functions string.h Functions time.h Functions NEXT: Comments C Language: #error Directive This C tutorial explains how to use the #error preprocessor directive in the C language. Description In the C Programming Language, the #error directive causes preprocessing to stop at the location where the directive is error directive in encountered. Information following the #error directive is output as a message prior to stopping preprocessing. Syntax The syntax for the #error directive in the C language is: #error message message Message to output prior to stopping preprocessing. Example Let's look at how to use #error directives in your C program. The following example shows the output of the #error directive: /* Example using #error directive by TechOnTheNet.com */ #include
They must begin on a separate line. Syntax: #if constant_expression #else
#endif
or
#if constant_expression #elif constant_expression #endif The compiler only compiles the code after the #if expression if the constant_expression evaluates to a non-zero value (true). If the value is 0 (false), then the compiler skips the lines until the next #else, #elif, or #endif. If there is a matching #else, and the constant_expression evaluated to 0 (false), then the lines between the #else and the #endif are compiled. If there is a matching #elif, and the preceding #if evaluated to false, then the constant_expression after that is evaluated and the code between the #elif and the #endif is compiled only if this expression evaluates to a non-zero value (true). Examples: int main(void) { #if 1 printf("Yabba Dabba Do!\n"); #else printf("Zip-Bang!\n"); #endif return 0; }
Only "Yabba Dabba Do!" is printed. int main(void) { #if 1 printf("Checkpoint1\n"); #elif 1 printf("Checkpoint2\n"); #endif return 0; }
Only "Checkpoint1" is printed. Note that if the first line is #if 0, then only "Checkpoint2" would be printed. #if OS==1 printf("Version 1.0"); #elif OS==2 printf("Version 2.0"); #else printf("Version unknown"); #endif
Prints according to the setting of OS which is defined with a #define. 1.7.2 #define, #undef, #ifdef, #ifndef The preprocessing directives #define and #undef allow the definition of identifiers which hold a certain value. These identifiers can simply be constants or a macro function. The directives #ifdef and #ifndef allow conditional compiling of certain lines of code based on whether or not an identifier has been defined. Syntax: #define identifier replacement-code #undef identifier #ifdef identifier #else or #elif #endif #ifndef identifier #else or #elif #endif #ifdef identifier is the same is #if defined( identifier). #ifndef identifier is the same as #if !defined(identifier). An identifier defined with #define is available anywhere in the source code u