Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dos and Don'ts of Conditional Compile [closed]

When is doing conditional compilation a good idea and when is it a horribly bad idea?

By conditional compile I mean using #ifdefs to only compile certain bits of code in certain conditions. The #defineds themselves may be in either a common header file or introduced via the -D compiler directive.

like image 251
doron Avatar asked Dec 17 '10 10:12

doron


1 Answers

The good ideas:

  • header guards (you can't do much better for portability)
  • conditional implementation (juggling with platform differences)
  • debug specific checks (asserts, etc...)
  • per suggestion: extern "C" { and } so that the same headers may be used by the C++ implementation and by the C clients of the API

The bad idea:

  • changing the API between compile flags, since it forces the client to changes its uses with the same compile flags... urk!
like image 110
Matthieu M. Avatar answered Oct 30 '22 09:10

Matthieu M.