0

Is there a way for me to do the following in C?

#ifdef MACRO_1 && MACRO_2
...
#endif

Writing this directly causes a compilation error.

Jeeter
  • 5,887
  • 6
  • 44
  • 67
  • @PaulR I would argue that while the answer linked answers both questions, the question linked is not the same – Jeeter Jul 13 '17 at 22:20
  • I think it's close enough, but I'll check for other duplicates which might be closer. Feel free to vote to re-open though - that's how the system works, after all... – Paul R Jul 13 '17 at 22:22

1 Answers1

4

This SO answer on - Is #if defined MACRO equivalent to #ifdef MACRO? explains it wonderfully.

Instead of using #ifdef, use #if defined(...). Since defined(...) will evaluate to a 0 or 1, it'll behave as a normal #if

Code would look like the following:

#if defined(MACRO_1) && defined(MACRO_2)
...
#endif
Jeeter
  • 5,887
  • 6
  • 44
  • 67