(I am working on a SDK wherein I have the code of the particular SDK in reference and I am not able to trace out the flow of the program.)
What does
#if defined (AR7x00)
mean? Specifically, what is the purpose of parentheses in a such a preprocessor operator?
These three preprocessor directives:
#if defined (AR7x00)
#if defined AR7x00
#ifdef AR7x00
all mean exactly the same thing: that the following code is to be processed only if the macro AR7x00
is currently defined.
The #ifdef ...
directive is simply a convenient alternative to #if defined ...
. There's also a #ifndef ...
directive; #ifndef FOO
is equivalent to #if ! defined FOO
.
As for the parentheses, the syntax for the defined
operator allows for either an identifier, or an identifier in parentheses, with no difference in meaning. I'm not entirely sure why the parentheses are optional; I suspect it's just historical. (The language reference in the 1978 first edition of K&R doesn't mention the defined
operator. The second edition shows both forms, with and without parentheses.)
Strictly speaking, these are not grouping parentheses of the kind you see in ordinary expressions; they're specifically part of the syntax of the defined
operator, which can only be used in preprocessor #if
directives. In particular, this:
#if defined ((AR7x00))
is a syntax error.
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