Preprocessor Error
Contents |
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 Channel 9 Documentation APIs and reference #error c++ Dev centers Samples Retired content We’re sorry. The content you requested has been #error gcc removed. You’ll be auto redirected in 1 second. C/C++ Preprocessor Reference Preprocessor Preprocessor Directives Preprocessor Directives #error Directive
#error In C Example
#error Directive #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
Error Directive Must Use C++ For The Type Iostream
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 2010 Visual Studio 2008 Visual Studio 2005 Visual Studio .NET 2003 The #error directive emits a user-specified error message #error access 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 © 2016 Microsoft © 2016 Microsoft
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies
#warning In C
of this site About Us Learn more about Stack Overflow the company #error in excel Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users c preprocessor message Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a https://msdn.microsoft.com/en-us/library/c8tk0xsk.aspx 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 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 http://stackoverflow.com/questions/2221517/how-do-i-generate-an-error-or-warning-in-the-c-preprocessor 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 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 an
Strings library Containers library Algorithms library Iterators library Numerics library Input/output library Localizations library Regular expressions http://en.cppreference.com/w/cpp/preprocessor/error library (C++11) Atomic operations library (C++11) Thread support library (C++11) Filesystem library (C++17) Technical Specifications [edit] C++ language General topics Preprocessor Comments Keywords Escape https://en.wikipedia.org/wiki/C_preprocessor sequences Flow control Conditional execution statements if switch Iteration statements (loops) for range-for (C++11) while do-while Jump statements continue - break goto - return #error in Functions Function declaration Lambda function declaration inline specifier Exception specifications (deprecated) noexcept specifier (C++11) Exceptions throw-expression try-catch block Namespaces Namespace declaration Namespace aliases Types Fundamental types Enumeration types Function types Compound types Union types Specifiers decltype (C++11) auto (C++11) alignas (C++11) const/volatile constexpr (C++11) Storage duration specifiers #error in c Initialization Default initialization Value initialization Zero initialization Copy initialization Direct initialization Aggregate initialization List initialization (C++11) Constant initialization Reference initialization Expressions Value categories Order of evaluation Operators Operator precedence Alternative representations Literals Boolean - Integer - Floating-point Character - String - nullptr (C++11) User-defined (C++11) Utilities Attributes (C++11) Types typedef declaration Type alias declaration (C++11) Casts Implicit conversions - Explicit conversions static_cast - dynamic_cast const_cast - reinterpret_cast Memory allocation new expression delete expression Classes Class declaration Initializer lists this pointer Access specifiers friend specifier Class-specific function properties Virtual function override specifier (C++11) final specifier (C++11) explicit (C++11) static Special member functions Default constructor Copy constructor Move constructor (C++11) Copy assignment Move assignment (C++11) Destructor Templates Class template Function template Template specialization Parameter packs (C++11) Miscellaneous Inline assembly History of C++ [edit] Preprocessor #if#ifdef#ifndef#else#elif#endif #define#undef#,## operators #include__has_include(C++17) #error #pragma_Pragma(C++11) #line [edit] Shows
article is written like a manual or guidebook. Please help rewrite this article from a descriptive, neutral point of view, and remove advice or instruction. (February 2013) (Learn how and when to remove this template message) This article includes a list of references, but its sources remain unclear because it has insufficient inline citations. Please help to improve this article by introducing more precise citations. (March 2015) (Learn how and when to remove this template message) (Learn how and when to remove this template message) The C preprocessor or cpp is the macro preprocessor for the C and C++ computer programming languages. The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control. In many C implementations, it is a separate program invoked by the compiler as the first part of translation. The language of preprocessor directives is only weakly related to the grammar of C, and so is sometimes used to process other kinds of text files. Contents 1 Phases 1.1 Including files 1.2 Conditional compilation 1.3 Macro definition and expansion 1.4 Special macros and directives 1.4.1 Token stringification 1.4.2 Token concatenation 1.5 User-defined compilation errors 2 Implementations 2.1 Compiler-specific preprocessor features 3 Other uses 4 See also 5 References 6 External links Phases[edit] Preprocessing is defined by the first four (of eight) phases of translation specified in the C Standard. Trigraph replacement: The preprocessor replaces trigraph sequences with the characters they represent. Line splicing: Physical source lines that are continued with escaped newline sequences are spliced to form logical lines. Tokenization: The preprocessor breaks the result into preprocessing tokens and whitespace. It replaces comments with whitespace. Macro expansion and directive handling: Preprocessing directive lines, including file inclusion and conditional compilation, are executed. The preprocessor simultaneously expands macros and, in the 1999 version of the C standard,[clarification needed] handles _Pragma operators. Including files[edit] One of the most common uses