Error Preprocessor In C
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 Us Learn more about Stack Overflow the company c preprocessor error directive Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs error c windows system32 rundll32 exe Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, error c docume 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? c preprocessor warning What is #error directive? what the use of it? c share|improve this question edited Mar 13 '13 at 23:21 Kornel 62.6k24138199 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 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
C Preprocessor If
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.6k47490 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 #i
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
C Preprocessor Error Macro
Overflow the company Business Learn more about hiring developers or posting ads with us c preprocessor concatenate Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a ifdef preprocessor community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How do I generate an error or warning in the C preprocessor? up vote 19 http://stackoverflow.com/questions/5323349/error-directive-in-c 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 at 12:29 Eonil 31.1k43203377 add a comment| 7 Answers 7 active oldest votes up vote 34 down vote accepted Place anywhere: #ifndef DEBUG #error Only Debug builds http://stackoverflow.com/questions/2221517/how-do-i-generate-an-error-or-warning-in-the-c-preprocessor are supported #endif share|improve this answer answered Feb 8 '10 at 12:33 Hans Passant 654k819601604 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 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. T
Witness ExpertiseProduct Liability Automotive Electronics Medical Device Design Computer Security Process & Architecture Safety & Reliability all... How-ToArticles Books Coding Standard Glossary Webinars Skills Tests Surveys BlogsNews Barr Code Coding Standards Device Security Expert Witness http://www.barrgroup.com/embedded-systems/how-to/c-preprocessor-error-directive Software Safety Registration for Fall Training Courses Now Open. See our complete training http://www.cprogramming.com/reference/preprocessor/error.html calendar. Glossary Find definitions for technical terms in our Embedded Systems Glossary. A B C D EF G H I JK L M N OP Q R S TU V W X YZ Symbols Test Your Skills How good are your embedded programming skills? Test yourself in the Embedded C Quiz or c preprocessor the Embedded C++ Quiz. Newsletter Signup Want to receive free how-to articles and industry news as well as announcements of free webinars and other training courses by e-mail? Signup Today! How to Use the C Preprocessor's #error Directive Wed, 1999-09-01 00:00 - Nigel Jones by Nigel Jones One of the least used but potentially most useful features of the C preprocessor is the ANSI-specified #error directive. c preprocessor error Here's a look at a couple of clever uses for #error that have proven invaluable in embedded software development. The syntax of #error is very straightforward: #error
Practice Problems Quizzes Resources Source Code Source Code Snippets C and C++ Tips Finding a Job References Function Reference Syntax Reference Programming FAQ Getting Help Message Board Email About Us #error #error "This code should not compile" The #error macro allows you to make compilation fail and issue a statement that will appear in the list of compilation errors. It is most useful when combined with #if/#elif/#else to fail compilation if some condition is not true. For example: #ifndef __unix__ // __unix__ is typically defined when targetting Unix #error "Only Unix is supported" #endif Related C preprocessor tutorial Want to become a C++ programmer? The Cprogramming.com ebook, Jumping into C++, will walk you through it, step-by-step. Get Jumping into C++ today! Popular pages Exactly how to get started with C++ (or C) today C Tutorial C++ Tutorial 5 ways you can learn to program faster The 5 Most Common Problems New Programmers Face How to set up a compiler 8 Common programming Mistakes What is C++11? How to make a game in 48 hours Recent additions How to create a shared library on Linux with GCC - December 30, 2011 Enum classes and nullptr in C++11 - November 27, 2011 Learn about The Hash Table - November 20, 2011 Rvalue References and Move Semantics in C++11 - November 13, 2011 C and C++ for Java Programmers - November 5, 2011 A Gentle Introduction to C++ IO Streams - October 10, 2011 Custom Search Advertising | Privacy policy | Copyright © 1997-2011 Cprogramming.com. All rights reserved. | webmaster@cprogramming.com Popular pages C Tutorial Exactly how to get started with C++ (or C) today 5 ways you can learn to program faster C++ Tutorial The 5 Most Common Problems New Programmers Face How to make a game in 48 hours 8 Common Programming Mistakes What is C++11? Image credits