> 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 -- <[EMAIL PROTECTED]>
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message