Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 1 Sep 2001 23:40:03 +0200
From:      Erik Trulsson <ertr1013@student.uu.se>
To:        Archie Cobbs <archie@dellroad.org>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: gcc -D flag
Message-ID:  <20010901234003.A14485@student.uu.se>
In-Reply-To: <200109012129.f81LT0M54076@arch20m.dellroad.org>
References:  <200109012129.f81LT0M54076@arch20m.dellroad.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Sep 01, 2001 at 02:29:00PM -0700, Archie Cobbs wrote:
> Can someone tell me what I'm missing here?
> 
>     $ cat > foo.c
>     int main(int ac, char **av) { return 0; }
>     #if FOO == BAR
>     #error
>     #endif
>     $ cc -o foo -Wall -DFOO=BAR foo.c
>     foo.c:3: #error 
>     $ cc -o foo -Wall foo.c
>     foo.c:3: #error 
>     $ cc -o foo -Wall -DFOO=NOTBAR foo.c
>     foo.c:3: #error 
> 
> Seems like #if FOO == BAR is being evalutated as true no matter what.
> 
> This is with FreeBSD 4.3-REL, gcc 2.95.3.
> 

The '==' operator works on numbers not strings. (This is true both for
the preprocessor and 'normal' C.)
The preprocessor considers all tokens that are undefined to have the
numeric value 0.

So in all three cases you actually end up with
#if 0 == 0
#error
#endif

Try using -DFOO=7 -DBAR=75 or some other number(s) instead and see if
things don't work better. (They should.)



-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010901234003.A14485>