C Preprocessor #error Directive
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 c preprocessor directives examples Us Learn more about Stack Overflow the company Business Learn more about hiring
Visual Studio Preprocessor Directives
developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the c preprocessor error macro 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 vote ifdef preprocessor 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 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
Pre Processor Directive In C
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/reports a fatal
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners #error c++ ISV Startups TechRewards Events Community Magazine Forums Blogs Channel #error in c example 9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. The content you
#error Gcc
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 this T
Strings library Containers library Algorithms library Iterators library Numerics library Input/output library Localizations library Regular expressions library (C++11) Atomic operations http://en.cppreference.com/w/cpp/preprocessor/error library (C++11) Thread support library (C++11) Filesystem library (C++17) Technical Specifications https://en.wikipedia.org/wiki/C_preprocessor [edit] C++ language General topics Preprocessor Comments Keywords Escape 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 Functions Function declaration Lambda function declaration inline specifier c preprocessor 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 Initialization Default initialization Value initialization Zero initialization Copy initialization Direct initialization Aggregate c preprocessor #error 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 given message and renders program ill-formed. [edit] Syntax #error error_message [edit] Explanation After encountering #error directive, diagnostic message error_message is shown and the program
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 of the preprocessor is to include another file: #include