C Preprocessor #warning #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 c preprocessor error directive of this site About Us Learn more about Stack Overflow the company c preprocessor error macro Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges
Preprocessor Warning Message
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:
C Preprocessor Define
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 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 c preprocessor if 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, 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 Fe
tokens Description #error emits tokens to standard error, and increments the assembler
C Preprocessor Tutorial
error counter, hereby preventing the program from being successfully c preprocessor ifdef assembled. #error is specified in the ANSI C standard. #warning emits tokens to c preprocessor ## operator standard error, and increments the assembler warning counter. #warning is not specified in the ANSI C standard, but is commonly implemented in http://stackoverflow.com/questions/2221517/how-do-i-generate-an-error-or-warning-in-the-c-preprocessor 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 http://www.atmel.com/webdoc/avrassembler/avrassembler.wb_preprocessor.error.html 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 Clea
MySQL MariaDB PostgreSQL SQLite MS Office Excel Access Word Web Development HTML CSS Color Picker Languages C Language More ASCII Table https://www.techonthenet.com/c_language/directives/warning.php Linux UNIX Java Clipart Techie Humor Advertisement C Language Introduction Compiling and Linking File Naming Preprocessor Directives #include #define #undef #if #ifdef #ifndef #elif #else #endif #warning http://tigcc.ticalc.org/doc/cpp.html #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 stdarg.h Functions stdio.h Functions stdlib.h c preprocessor Functions string.h Functions time.h Functions NEXT: #error C Language: #warning Directive This C tutorial explains how to use the #warning preprocessor directive in the C language. Description In the C Programming Language, the #warning directive is similar to an #error directive, but does not result in the cancellation of preprocessing. Information following the #warning c preprocessor error directive is output as a message prior to preprocessing continuing. Syntax The syntax for the #warning directive in the C language is: #warning message message The message to output prior to continuing preprocessing. Example Let's look at how to use #warning directives in your C program. The following example shows the output of the #warning directive: /* Example using #warning directive by TechOnTheNet.com */ #include
the C compiler to transform your program before actual compilation. It is called a macro processor because it allows you to define macros, which are brief abbreviations for longer constructs. Preprocessor Overview Header Files Macros Conditionals Pragmas Other Directives User-defined Diagnostics Line Control Preprocessor Output C Preprocessor Command-Line Options Traditional Mode Implementation Details History GNU General Public License GNU Free Documentation License Funding Free Software Original author: Free Software Foundation, Inc. Authors of the modifications: Zeljko Juric, Sebastian Reichelt, and Kevin Kofler Published by the TIGCC Team. See the History section for details and copyright information. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation. A copy of the license is included in the section entitled "GNU Free Documentation License". This manual contains no Invariant Sections. The Front-Cover Texts are (a) (see below), and the Back-Cover Texts are (b) (see below). (a) The FSF's Front-Cover Text is: A GNU Manual (b) The FSF's Back-Cover Text is: You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development. Preprocessor Overview The C preprocessor, often known as cpp, is a macro processor that is used automatically by the C compiler to transform your program before compilation. It is called a macro processor because it allows you to define macros, which are brief abbreviations for longer constructs. The C preprocessor is intended to be used only with C, C++, and Objective-C source code. In the past, it has been abused as a general text processor. It will choke on input which does not obey C's lexical rules. For example, apostrophes will be interpreted