Preprocessor Error Macro
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 #error c++ and reference Dev centers Samples Retired content We’re sorry. The content #error gcc you requested has been removed. You’ll be auto redirected in 1 second. C/C++ Preprocessor Reference Preprocessor Preprocessor Directives #error in c example Preprocessor Directives #error Directive #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 error directive must use c++ for the type iostream #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 2010 Visual Studio 2008 Visual Studio 2005 Visual Studio .NET 2003
#error Access
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 © 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 of this site About Us Learn more about Stack Overflow the company Business
#warning In C
Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation c preprocessor message Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just #error in excel like you, helping each other. Join them; it only takes a minute: Sign up Forcing preprocessor error with macro up vote 0 down vote favorite Is there a way that I can force a preprocessor macro in C++ https://msdn.microsoft.com/en-us/library/c8tk0xsk.aspx to emit an error? What I would like to do is define a macro UNKNOWN. I'm writing some code for a robot, and I don't yet know where all of the electronics are being plugged in. I'd like to be able to define the ports in some header file, like const int MOTOR_PORT = 1; const int FAN_PORT = 2; //etc. However, when I reach a port that I don't yet know, I want to http://stackoverflow.com/questions/21055507/forcing-preprocessor-error-with-macro be able to write something like const int LED_PORT = UNKNOWN; In debug mode, UNKNOWN would just be defined to some arbitrary value, like 0. However, when compiling in release mode, I want it to throw an error when UNKNOWN is used, so that unassigned ports don't end up in the final release. I know I can use the #error directive to force an error, but can I do something similar in a macro? I've seen a solution using static_assert, but I unfortunately can't use C++11 for this platform. c++ debugging macros c-preprocessor share|improve this question edited Jul 2 at 18:27 Brian Tompsett - 汤莱恩 3,101132775 asked Jan 10 '14 at 22:19 Will Kunkel 1,42211335 You could try BOOST_STATIC_ASSERT. –chris Jan 10 '14 at 22:21 I'm not using boost, and I'm reluctant to add another dependency just for this. –Will Kunkel Jan 10 '14 at 22:22 If you just omit to define UNKNOWN or define it to nothing, the particular code here would fail to compile. Or even just #define UNKNOWN (1/0) –nos Jan 10 '14 at 22:26 Ideally, I'd like to retain the ability of #error to emit a custom error message, rather than just an unrelated error. –Will Kunkel Jan 10 '14 at 22:37 @WilliamKunkel That can't be done if
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 http://stackoverflow.com/questions/5323349/error-directive-in-c more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users https://en.wikipedia.org/wiki/C_preprocessor 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 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 #error in the use of it? c share|improve this question edited Mar 13 '13 at 23:21 Kornel 62.7k24138200 asked Mar 16 '11 at 5:59 PHP 1,16431739 migrated from programmers.stackexchange.com Mar 16 '11 at 9:38 This question came from our site for professionals, academics, and students working within the systems development life cycle who care about creating, delivering, and maintaining software responsibly. 4 This seems more like a question for stackoverflow.com –jmort253 Mar 16 '11 at 6:29 add preprocessor error macro 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.7k47491 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 error earlier on than a compilation error. –RastaJedi Apr 19 at 19:57 add a comment| up vote 12 down vote I may have invalid code but its something like... #if defined USING_SQLITE && defined USING_MYSQL #error You cannot use both sqlite and mysql at the same time #endif #if !(defined USING_SQLI
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 directi