Date: Sat, 1 Sep 2001 14:44:22 -0700 (PDT) From: Archie Cobbs <archie@dellroad.org> To: Erik Trulsson <ertr1013@student.uu.se> Cc: freebsd-questions@freebsd.org Subject: Re: gcc -D flag Message-ID: <200109012144.f81LiMM54181@arch20m.dellroad.org> In-Reply-To: <20010901234003.A14485@student.uu.se> "from Erik Trulsson at Sep 1, 2001 11:40:03 pm"
next in thread | previous in thread | raw e-mail | index | archive | help
Erik Trulsson writes:
> > 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.)
Thanks! That did it.
-Archie
__________________________________________________________________________
Archie Cobbs * Packet Design * http://www.packetdesign.com
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?200109012144.f81LiMM54181>
