This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Use command line defines vs defining in header files.
On Mon, Aug 28, 2000 at 03:31:46PM -0500, Matt Minnis wrote:
> On a similar note, why is #ifdef XXX used more than #if XXX?
>
> Is there a technical reason or just that's the way it has been done?
The two are not the same thing.
#if name
tests if name != 0 (with undefined names being 0, though I believe some pre-ISO
C compilers would give an error or a warning if name was not defined), while
#ifdef name
would be positive even if name was defined as either the empty string, or 0.
In addition, if name is not defined as an integer constant expression (for
example, it contains a call or a structure member reference), the plain #if
would barf on it.
#if defined(name)
is indeed equivalent to #ifdef name, but it is clunkier.
--
Michael Meissner, Red Hat, Inc.
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work: meissner@redhat.com phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org fax: +1 978-692-4482