*BSD News Article 83716


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!nntp.coast.net!howland.erols.net!feed1.news.erols.com!news.idt.net!newsfeed.internetmci.com!news.sprintlink.net!news-peer.sprintlink.net!cs.utexas.edu!uwm.edu!alpha1.csd.uwm.edu!bacon
From: bacon@alpha1.csd.uwm.edu (Jason Wayne Bacon)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: Compiler bug?
Date: 27 Nov 1996 17:04:14 GMT
Organization: University of Wisconsin - Milwaukee
Lines: 34
Message-ID: <57hsae$cpm@uwm.edu>
References: <55tf99$6b5@garuda.synet.net>
Reply-To: bacon@alpha1.csd.uwm.edu
NNTP-Posting-Host: 129.89.169.1
Originator: bacon@alpha1.csd.uwm.edu

From article <55tf99$6b5@garuda.synet.net>, by imdave@synet.net (Dave Bodenstab):
> In article <3280F04E.4D5A@cococo.net>, Kelley  <kelley@cococo.net> wrote:
>  >Tommy Johnson wrote:
>  >> 
>  >> 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.
>  >> 
>  >>  <snip>
>  >>
>  >>         a=c[b++]|((c[b++])<<8);
> 
> This statement violates standard C.  Consult the C standards for exact det
> but the bottom line is that there is no rule to define *when* each `b++' is
> evaluated.

The behaviour of this statement *is* well defined.
The | operator evaluates left to right, so the operations
*should* occur in the followign order:

	1. evaluate c[b] (left one)
	2. increment b
	3. evaluate c[b] (right one)
	4. increment b again
	5. shift left
	6. bitwise OR

I had a similar problem with gcc 2.5.6 being unable to correctly evaluate
a complex expression, because it got confused about operator precedence.
The program worked fine on several different systems, and even some
other versions of gcc.  I'd suggest breaking it up into a few separate 
statements.

-Jason