Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using 'defined' with 'ifdef'?

consider the snippet below:

#ifdef AAA && (defined BBB)
...
#endif

gcc-4.5.2 complains on this line:

extra tokens at the end of #ifdef directive.

Is it illegal to combine ifdef and defined ?

Thanks!

like image 924
Mark Avatar asked Dec 04 '22 07:12

Mark


2 Answers

The #ifdef requires a single identifier and is equivalent to #if defined(identifier).

You need to use the #if directive if you have a more complex expression:

#if (defined AAA) && (defined BBB) // true if AAA and BBB are both defined
#if AAA && (defined BBB)           // true if AAA is true and BBB is defined
like image 120
James McNellis Avatar answered Dec 19 '22 09:12

James McNellis


#ifdef will only work on one token. If you want to use more than one then write

#if defined(AAA) && defined(BBB)

like image 31
Nobody moving away from SE Avatar answered Dec 19 '22 09:12

Nobody moving away from SE