What is the difference (if any) between the two following preprocessor control statements.
#if
and
#ifdef
There are 4 Main Types of Preprocessor Directives: Macros. File Inclusion. Conditional Compilation. Other directives.
Preprocessor directives appear in source code. There are many different directives. One of them is #include , which is used to include a header file. Header files contain a collection of declarations, often for functions and types (and sometimes variables) found in a library.
What Does Preprocessor Directive Mean? Preprocessor directives are lines included in a program that begin with the character #, which make them different from a typical source code text. They are invoked by the compiler to process some programs before compilation.
Question1: What is Difference between Preprocessor and Compiler? Answer: Though, the preprocessor is the first to look at the source code file and performs several preprocessing operations before it's compiled by the compiler. Nevertheless, compiler sets the source code file, say “hello.
You can demonstrate the difference by doing:
#define FOO 0 #if FOO // won't compile this #endif #ifdef FOO // will compile this #endif
#if
checks for the value of the symbol, while #ifdef
checks the existence of the symbol (regardless of its value).
#ifdef FOO
is a shortcut for:
#if defined(FOO)
#if
can also be used for other tests or for more complex preprocessor conditions.
#if defined(FOO) || defined(BAR)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With