From owner-freebsd-hackers Sat Jul 29 19:27:51 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from maxim.gba.oz.au (gba.tmx.com.au [203.9.155.249]) by hub.freebsd.org (Postfix) with SMTP id 3ED6F37B875 for ; Sat, 29 Jul 2000 19:27:45 -0700 (PDT) (envelope-from gjb@acm.org) Received: (qmail 24134 invoked by uid 1001); 30 Jul 2000 12:25:59 +1000 X-Posted-By: GBA-Post 2.02.01 12-Dec-1999 X-PGP-Fingerprint: 5A91 6942 8CEA 9DAB B95B C249 1CE1 493B 2B5A CE30 Message-Id: Date: Sun, 30 Jul 2000 12:25:59 +1000 From: Greg Black To: Mark Ovens Cc: hackers@FreeBSD.ORG Subject: Re: ANSI compliance, gcc(1) and FreeBSD References: <20000729115153.C236@parish> In-reply-to: <20000729115153.C236@parish> of Sat, 29 Jul 2000 11:51:53 +0100 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > Apologies if this is the wrong list for this question but it seems the > best place to get a *definitive* answer. The best place to get a definitive answer about C is in the Standard. The best place to get a definitive answer about gcc is in the source. > In the ANSI Standard (K&R 2e, A7.14 & A7.15) As a point of fact, K&R-2, while largely correct, is not itself the Standard. > it states that, in the > case of the ``&&'' operator, the right operand is evaluated only if > the left operand evaluates to non-zero, and, for ``||'', the right > operand is evaluated only if the left operand evaluates to zero. This has been mandated ever since the days of the original language definition (K&R-1, 1978) and is absolutely required of anything that purports to be a C compiler -- and yes, gcc is conformant in this respect. > would the following > be acceptable if we wanted to guarantee that foobar was set to BAR > *only* if FOO was unset or NULL? > > if ((foobar = getenv("FOO")) != NULL || (foobar = getenv("BAR")) != NULL) The second getenv() will only be called if the first one returns NULL. Of course, if the second getenv() also returns NULL, then foobar will be set to NULL and the statement part of the "if" will not be executed. -- Greg Black -- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message