Precompiler Error
Contents |
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups
#error C++
TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs #error in c example and reference Dev centers Samples Retired content We’re sorry. The content you requested has been error directive must use c++ for the type iostream removed. You’ll be auto redirected in 1 second. C/C++ Preprocessor Reference Preprocessor Preprocessor Directives Preprocessor Directives #error Directive #error Directive #error Directive #define Directive
#error Gcc
#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. This documentation is archived and is
#error Access
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 this Thank you! We appreciate your feedback. Dev centers Windows Office Visual Studio Micro
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 #warning in c the company Business Learn more about hiring developers or posting ads with us Stack Overflow
C Preprocessor Message
Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 #error in excel million programmers, just like you, helping each other. Join 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 https://msdn.microsoft.com/en-us/library/c8tk0xsk.aspx I have a program that must be compiled only in DEBUG mode. (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.2k43203377 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 http://stackoverflow.com/questions/2221517/how-do-i-generate-an-error-or-warning-in-the-c-preprocessor answer answered Feb 8 '10 at 12:33 Hans Passant 656k819631609 add a comment| up vote 11 down vote C 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 unrefere
and often underused preprocessor directive. Behaviour of this preprocessor directive is the same for both C and C++ compilers. Purpose The #error directive terminates compilation and outputs the text following the directive. Format #error text All http://www.complete-concrete-concise.com/programming/c/preprocessor-%E2%80%93-the-error-directive preprocessor directives begin with the # symbol. It must be the first character on the line or the first character on the line following optional white space. Some early compilers flagged an error if # was not the first character on the line. Spaces or tabs are permitted between the # and error, but not escape characters or other symbols or macros. The preprocessor #error in removes white space and concatenates the # and error together. If anything follows the #error directive (other than white space) then the program is malformed. The following are valid uses: #error some error message text # error some error text to display # /* comments are white space */ error some error message to display The following are invalid uses: // #\ is not #error in c a valid preprocessor directive # \t error text to output // #" is not a valid preprocessor directive # "" text to output Use It is used to render a program malformed and output the text following the #error directive. The text may be quoted or unquoted (it doesn't matter). No macro expansion takes place. The language specifications do not say how the text following the #error directive is to be treated. The GCC compiler, replaces all white space characters between tokens with a single white space character. I have no reason to believe other compilers behave differently since white space is not considered significant in the C and C++ languages - it serves only to seperate tokens from one another. There are many times when it is useful to halt compilation: code is incomplete code requires particular library versions code uses compiler dependent features code has specific compiler requirements Incomplete Code When developing code, it is common to create stub functions. For the final release, these stub functions need to be implemented. We can let the compiler help us catch unimplemented functions: int my_function( void ) { #error my_functi