C Preprocessor Macros #error
Contents |
message. You would use ‘#error’ inside of
C Preprocessor Macros Multiple Lines
a conditional that detects a combination of c preprocessor macro arguments parameters which you know the program does not properly support. For c preprocessor macro tricks example, if you know that the program will not run properly on a VAX, you might write #ifdef __vax__
C Preprocessor Macro Variable Arguments
#error "Won't work on VAXen. See comments at get_last_object." #endif If you have several configuration parameters that must be set up by the installation in a consistent way, you can use conditionals to detect an inconsistency and report
C Preprocessor Macro Concatenation
it with ‘#error’. For example, #if !defined(FOO) && defined(BAR) #error "BAR requires FOO." #endif The directive ‘#warning’ is like ‘#error’, but causes the preprocessor to issue a warning and continue preprocessing. The tokens following ‘#warning’ are used as the warning message. You might use ‘#warning’ in obsolete header files, with a message directing the user to the header file which should be used instead. Neither ‘#error’ nor ‘#warning’ macro-expands its argument. Internal whitespace sequences are each replaced with a single space. The line must consist of complete tokens. It is wisest to make the argument of these directives be a single string constant; this avoids problems with apostrophes and the like.
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 more about hiring c preprocessor macro overloading developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
C Preprocessor Macro If
x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join c preprocessor macro in string them; it only takes a minute: Sign up C preprocessor: expand macro in a #warning up vote 19 down vote favorite 9 I would like to print a macro value (expand the macro) in the #warning directive. For example, for https://gcc.gnu.org/onlinedocs/cpp/Diagnostics.html the code: #define AAA 17 #warning AAA = ??? The desired compile-time output would be warning: AAA = 17 What do I use for ???, or, how do I augment the code? c gcc c-preprocessor share|improve this question edited Nov 2 '14 at 18:56 AstroCB 7,849113261 asked Sep 28 '12 at 9:35 elomage 1,70811015 1 According to the C standard from 1999, you only have #error for something like that and it does not expand any macros, it http://stackoverflow.com/questions/12637392/c-preprocessor-expand-macro-in-a-warning just prints the text literally and causes compilation to stop. What are you trying to achieve with this anyway? –Alexey Frunze Sep 28 '12 at 9:41 I have a hierarchy of many makefiles that define AAA in various ways, depending on the make target parameters. I would like to verify that the definition is correct for the target. And I would not want to create a list of #if AAA = 1 ... #warning "is 1"... –elomage Sep 28 '12 at 9:44 Also, this is for the embedded world with no displays, so I can not easily test the macro value by adding something like printf( #AAA ); and check it at runtime. –elomage Sep 28 '12 at 9:58 So you do #if A == 1\#error A = 1\#elif A == 2\#error A = 2\#endif. –Alexey Frunze Sep 28 '12 at 10:00 @AlexeyFrunze That is exactly what I want to avoid - see my comment above. I may not know all the possible values, or there might be too many of those. –elomage Sep 28 '12 at 10:09 | show 1 more comment 4 Answers 4 active oldest votes up vote 26 down vote accepted You can use the preprocessor directive #pragma message. Example: #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) #define AAA 123 #pragma message "content of AAA: " STR(AAA) int main() { return 0; } The
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. https://en.wikipedia.org/wiki/C_preprocessor (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 http://www.barrgroup.com/embedded-systems/how-to/c-preprocessor-error-directive 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 c preprocessor 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 c preprocessor macro 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
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 Software Safety Registration for Fall Training Courses Now Open. See our complete training 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 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. 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