Buy GNU books!
|[ < ]||[ > ]||[ << ]||[ Up ]||[ >> ]||[Top]||[Contents]||[Index]||[ ? ]|
When supporting configuration options already known when building your
program we prefer using
if (... ) over conditional compilation,
as in the former case the compiler is able to perform more extensive
checking of all possible code paths.
For example, please write
if (HAS_FOO) ... else ...
#ifdef HAS_FOO ... #else ... #endif
A modern compiler such as GCC will generate exactly the same code in both cases, and we have been using similar techniques with good success in several projects.
While this is not a silver bullet solving all portability problems, following this policy would have saved the GCC project alone many person hours if not days per year.
In the case of function-like macros like
GCC which cannot be simply used in
if( ...) statements, there is
an easy workaround. Simply introduce another macro
HAS_REVERSIBLE_CC_MODE as in the following example:
#ifdef REVERSIBLE_CC_MODE #define HAS_REVERSIBLE_CC_MODE 1 #else #define HAS_REVERSIBLE_CC_MODE 0 #endif
|webmaster donations bookstore||delorie software privacy|
|Copyright © 2003 by The Free Software Foundation||Updated Jun 2003|