From owner-freebsd-questions Sat Sep 1 14:45: 6 2001 Delivered-To: freebsd-questions@freebsd.org Received: from InterJet.dellroad.org (adsl-63-194-81-26.dsl.snfc21.pacbell.net [63.194.81.26]) by hub.freebsd.org (Postfix) with ESMTP id 5C76437B408 for ; Sat, 1 Sep 2001 14:45:03 -0700 (PDT) Received: from arch20m.dellroad.org (arch20m.dellroad.org [10.1.1.20]) by InterJet.dellroad.org (8.9.1a/8.9.1) with ESMTP id OAA91497; Sat, 1 Sep 2001 14:44:23 -0700 (PDT) Received: (from archie@localhost) by arch20m.dellroad.org (8.11.3/8.11.3) id f81LiMM54181; Sat, 1 Sep 2001 14:44:22 -0700 (PDT) (envelope-from archie) From: Archie Cobbs Message-Id: <200109012144.f81LiMM54181@arch20m.dellroad.org> Subject: Re: gcc -D flag In-Reply-To: <20010901234003.A14485@student.uu.se> "from Erik Trulsson at Sep 1, 2001 11:40:03 pm" To: Erik Trulsson Date: Sat, 1 Sep 2001 14:44:22 -0700 (PDT) Cc: freebsd-questions@freebsd.org X-Mailer: ELM [version 2.4ME+ PL82 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII 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 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