*BSD News Article 82586


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!news.Hawaii.Edu!news.uoregon.edu!hammer.uoregon.edu!news-peer.gsl.net!news.gsl.net!howland.erols.net!www.nntp.primenet.com!nntp.primenet.com!dispatch.news.demon.net!demon!awfulhak.demon.co.uk!awfulhak.demon.co.uk!awfulhak.demon.co.uk!not-for-mail
From: brian@anorak.coverform.lan (Brian Somers)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: Compiler bug?
Date: 10 Nov 1996 01:33:54 -0000
Organization: Coverform Ltd.
Lines: 41
Sender: brian@awfulhak.demon.co.uk
Message-ID: <563be2$i7b@anorak.coverform.lan>
References: <55p7ck$r2l@csgrad.cs.vt.edu>
    <55qdup$8jv@sol.ctr.columbia.edu>
Reply-To: brian%anorak.coverform.lan@awfulhak.demon.co.uk
NNTP-Posting-Host: anorak.coverform.lan
X-NNTP-Posting-Host: awfulhak.demon.co.uk
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Newsreader: knews 0.9.8

In article <55qdup$8jv@sol.ctr.columbia.edu>,
	wpaul@ctr.columbia.edu (Bill Paul) writes:
: Daring to challenge the will of the almighty Leviam00se, Tommy Johnson
: (tjohnson@csgrad.cs.vt.edu) had the courage to say:
: 
>: This program doesn't work as I think it should.   On line 10, b is not 
>: incremented between the first and second b++'s, though it is correct
>: after the entire expression.
[.....]
: [chop]
>:         a=c[b++]|((c[b++])<<8);
: [chop]
: 
: I believe you have invoked undefined compiler behavior with this code.
[.....]
: (No, I can't quote the exact part of the ANSI spec that says this code
: is bogus; I just know that it is.)
: 
: You need to rewrite your code so that you do not have two b++'s in the
: same statement; then it should behave the same regardless of the platform
: or compiler. This should as you expect:
: 
: a = c[b++];
: a |= ((c[b++])<<8);
[.....]

Yep - I agree completely.

The spec says that the variable will be incremented sometime after its
value is taken.  It warns that "when" is undefined and says that code
such as

    foo( x++, x++ )

will not port.

-- 
Brian <brian%anorak.coverform.lan@awfulhak.demon.co.uk>
      <http://www.awfulhak.demon.co.uk/>
Don't _EVER_ lose your sense of humour....
.