Home > preprocessor directives > c preprocessor directives error

C Preprocessor Directives Error

Contents

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta

C Preprocessor Directives Examples

Discuss the workings and policies of this site About Us Learn preprocessor directives in c programming more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us

Visual Studio Preprocessor Directives

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 ifdef preprocessor you, helping each other. 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 it? c share|improve this question edited Mar 13 '13 at 23:21 Kornel 62.3k24135197 asked #error in c example 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 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 on

resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs

#warning In C

Channel 9 Documentation APIs and reference Dev centers Retired content Samples #error c++ We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. C/C++

#error Gcc

Preprocessor Reference Preprocessor Preprocessor Directives Preprocessor Directives #error Directive #error Directive #error Directive #define Directive #error Directive #if, #elif, #else, and #endif Directives #ifdef and #ifndef Directives #import http://stackoverflow.com/questions/5323349/error-directive-in-c 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 not being maintained. #error Directive (C/C++) Visual Studio 2015 Other Versions Visual Studio 2013 Visual Studio 2012 Visual Studio https://msdn.microsoft.com/en-us/library/c8tk0xsk.aspx 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 Microsoft Azure More... Learning resources Microsoft Virtual Academy Channel 9 MSDN Magazine Community Forums Blogs Codeplex Support Self support Programs BizSpark (for startups) Microsoft Imagine (for students) United States (English) Newsletter Privacy & cookies Terms of use Trademarks ©

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 http://stackoverflow.com/questions/2221517/how-do-i-generate-an-error-or-warning-in-the-c-preprocessor 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 http://www.atmel.com/webdoc/avrassembler/avrassembler.wb_preprocessor.error.html 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 I have a program that must be compiled only in DEBUG mode. (testing purpose) How preprocessor directives can I have the preprocessor prevent compilation in RELEASE mode? c-preprocessor share|improve this question edited Jun 25 at 23:11 phs 7,05822761 asked Feb 8 '10 at 12:29 Eonil 31k43203376 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 answer answered Feb 8 '10 at 12:33 Hans Passant 653k819531598 add a comment| up vote 11 down vote C provide a #error statement, c preprocessor directives 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.8k94890 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 20.9k44075 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 unreferenced labe like HereIsMyWarning: and don't reference it. During compilation you will get warning like 1>..\Example.c(71) : warning C4102: 'HereIsMyWarning' : unreferenced label share|improve this answer edited May 27 '15 at 15:20 Janito Vaqueiro Ferreira Filho 3,2641820 answered May 27 '15 at 10:26 Zdeno Pavlik 108

tokens Description #error emits tokens to standard error, and increments the assembler error counter, hereby preventing the program from being successfully assembled. #error is specified in the ANSI C standard. #warning emits tokens to standard error, and increments the assembler warning counter. #warning is not specified in the ANSI C standard, but is commonly implemented in preprocessors such as the GNU C preprocessor. #message emits tokens to standard output, and does not affect assembler error or warning counters. #message is not specified in the ANSI C standard.For all directives, the output will include file name and line number, like normal error and warning messages.tokens is a sequence of preprocessor tokens. Preprocessor macros are expanded except if appearing inside quoted strings (").Example #error "Unsupported part:" __PART_NAME__ PrevUpNextHomeContentsSearchDocumentation HomeAVR AssemblerPrefaceAVR Assembler Known IssuesAVR Assembler Command Line OptionsAssembler sourceAVR Assembler SyntaxAssembler directivesAVR Assembler PreprocessorIntroductionPreprocessor directives#define#undef#ifdef#ifndef#if and #elif#else#endif#error, #warning and #message#include#pragma, general purpose#pragma , AVR part related# (empty directive)OperatorsStringification (#)Concatenation (##)Pre-defined macrosExpressionsInstruction mnemonicsArithmetic and logic instructionsBranch InstructionsData Transfer InstructionsBit and Bit-test InstructionsI/O RegistersInstruction Set Nomenclature:Instructions ADC - Add with Carry ADD - Add without Carry ADIW - Add Immediate to Word AND - Logical AND ANDI - Logical AND with Immediateand ASR - Arithmetic Shift Right BCLR - Bit Clear in SREG BLD - Bit Load from the T Flag in SREG to a Bit in Register. BRBC - Branch if Bit in SREG is Cleared BRBS - Branch if Bit in SREG is Set BRCC - Branch if Carry Cleared BRCS - Branch if Carry Set BREAK - Break BREQ - Branch if Equal BRGE - Branch if Greater or Equal Signed) BRHC - Branch if Half Carry Flag is Cleared BRHS - Branch if Half Carry Flag is Set BRID - Branch if Global Interrupt is Disabled BRIE - Branch if Global Interrupt is Enabled BRLO - Branch if Lower (Unsigned) BRLT - Br

 

Related content

ifndef error

Ifndef Error table id toc tbody tr td div id toctitle Contents div ul li a href define C a li li a href Preprocessor Directives In C With Example a li ul td tr tbody table p 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 relatedl About Us Learn more about Stack Overflow the company Business Learn c ifdef more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags c preprocessor directives Users Badges Ask