Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 Jul 2000 12:25:59 +1000
From:      Greg Black <gjb@acm.org>
To:        Mark Ovens <marko@FreeBSD.ORG>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: ANSI compliance, gcc(1) and FreeBSD 
Message-ID:  <nospam-398392378405e1c@maxim.gba.oz.au>
In-Reply-To: <20000729115153.C236@parish>  of Sat, 29 Jul 2000 11:51:53 %2B0100
References:  <20000729115153.C236@parish> 

next in thread | previous in thread | raw e-mail | index | archive | help
> 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 -- <gjb@acm.org>


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




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