[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

#if vs #ifdef

From: Rob Browning
Subject: #if vs #ifdef
Date: Thu, 27 Mar 2003 00:18:08 -0600
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i386-pc-linux-gnu)

The GNU Coding Standards suggest always #defining a symbol to a value
and using #if tests rather than either defining or not defining that
symbol and using #ifdef or #ifndef.  i.e. instead of "#define FOO",
use "#define FOO 1", and use "#define FOO 0" rather than not defining
it at all.

One reason for this recommendation is that they then encourage you to
write code like this:


rather than using #if/#ifdef/etc. at all.  Their argument is that all
reasonable compilers will generate the same code either way, and using
C code rather than the preprocessor can substantially improve the
readability of the code and allow the C compiler to do more thorough
analysis of all code paths.

Thoughts?  Since I just added new public defines, this seems a good
time to ask.


Rob Browning
rlb,, and
GPG starting 2002-11-03 = 14DD 432F AE39 534D B592  F9A0 25C8 D377 8C7E 73A4

reply via email to

[Prev in Thread] Current Thread [Next in Thread]