Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Feb 1997 20:58:43 +0100
From:      j@uriah.heep.sax.de (J Wunsch)
To:        freebsd-chat@freebsd.org (FreeBSD chat list)
Subject:   Re: cvs commit: CVSROOT avail
Message-ID:  <Mutt.19970204205843.j@uriah.heep.sax.de>
In-Reply-To: <3.0.32.19970204121616.00ba8e30@dimaga.com>; from Eivind Eklund on Feb 4, 1997 12:16:17 %2B0100
References:  <3.0.32.19970204121616.00ba8e30@dimaga.com>

next in thread | previous in thread | raw e-mail | index | archive | help
As Eivind Eklund wrote:

> >> or at least
> >> if ( bar && (foo = *bar))
> >> 
> >> (as opposed to:
> >> if  ( bar && foo = *bar)
> >> 
> >> in complicated conditionals.
> >
> >That's actually a _really_ bad example, as it only makes sense with
> >guaranteed left-to-right evaluation 8)
> 
> ... which is quite all right, as ANSI guarantee left-to-right evaluation
> for "&&", "||", "," and "?:" (the conditional is evaluated before the
> result - weird, uh? ;)

Except, the latter of the both is of course wrong. :-)

j@uriah 130% cat foo.c 
int
mumble(void)
{
        int foo;
        char *bar;

        if (bar && foo = *foo) {
                return 1;
        }
        return 0;
}
j@uriah 131% cc -c foo.c
foo.c: In function `mumble':
foo.c:7: invalid type argument of `unary *'

SEE ALSO
	/usr/share/misc/operators

:-)

(The assignment has less priority than the &&, hence that statement
tried to assign something to the expression ``bar && foo''.)

-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Mutt.19970204205843.j>