Boolean in ifdef: is "#ifdef A && B" the same as "#if defined(A) && defined(B)"?

criddell picture criddell · Aug 21, 2009 · Viewed 86.4k times · Source

In C++, is this:

#ifdef A && B

the same as:

#if defined(A) && defined(B)

?

I was thinking it wasn't, but I haven't been able to find a difference with my compiler (VS2005).

Answer

Evan Teran picture Evan Teran · Aug 21, 2009

They are not the same. The first one doesn't work (I tested in gcc 4.4.1). Error message was:

test.cc:1:15: warning: extra tokens at end of #ifdef directive

If you want to check if multiple things are defined, use the second one.