From owner-freebsd-questions Sat Sep 1 14:40:37 2001 Delivered-To: freebsd-questions@freebsd.org Received: from maild.telia.com (maild.telia.com [194.22.190.101]) by hub.freebsd.org (Postfix) with ESMTP id 47BF837B40A for ; Sat, 1 Sep 2001 14:40:26 -0700 (PDT) Received: from d1o913.telia.com (d1o913.telia.com [195.252.44.241]) by maild.telia.com (8.11.2/8.11.0) with ESMTP id f81LePY26390 for ; Sat, 1 Sep 2001 23:40:25 +0200 (CEST) Received: from ertr1013.student.uu.se (h185n2fls20o913.telia.com [212.181.163.185]) by d1o913.telia.com (8.8.8/8.8.8) with SMTP id XAA16866 for ; Sat, 1 Sep 2001 23:40:23 +0200 (CEST) Received: (qmail 14512 invoked by uid 1001); 1 Sep 2001 21:40:03 -0000 Date: Sat, 1 Sep 2001 23:40:03 +0200 From: Erik Trulsson To: Archie Cobbs Cc: freebsd-questions@freebsd.org Subject: Re: gcc -D flag Message-ID: <20010901234003.A14485@student.uu.se> Mail-Followup-To: Archie Cobbs , freebsd-questions@freebsd.org References: <200109012129.f81LT0M54076@arch20m.dellroad.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200109012129.f81LT0M54076@arch20m.dellroad.org> User-Agent: Mutt/1.3.21i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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.) -- Erik Trulsson ertr1013@student.uu.se To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message