Path: utzoo!attcan!uunet!nuchat!moray!mybest!ut-emx!cs.utexas.edu!meyering From: meyering@cs.utexas.edu (Jim Meyering) Newsgroups: comp.lang.c Subject: Re: Does your compiler get this program right? Summary: standard doesn't define "right" Keywords: float, increment Message-ID: <4082@cs.utexas.edu> Date: 23 Nov 88 23:29:47 GMT References: <2298@cbnews.ATT.COM> Organization: U. Texas CS Dept., Austin, Texas Lines: 29 In article <2298@cbnews.ATT.COM> lvc@cbnews.ATT.COM (Lawrence V. Cipriani) writes: >A friend of mine found a bug in his C compiler. He found It's not a bug. [...deleted commentary, code] >*f++ += *g++; /* miscompiled line */ The standard does not specify the order of evaluation for such statements. It's easier to see the ambiguity if you try to rewrite it without the += notation. Which do you choose? 1) *f++ = *f++ + *g++; 2) *f++ = *f + *g++; 3) *f = *f++ + *g++; It can't be (1) since the side effect, f++, may be realized only once, but it's up to the compiler writer to choose between (2) and (3). You might be interested to know that while the Sun3/os3.2 (or an HP, don't remember which) C compiler produced code that gave the "correct" results for your code, when I replaced that statement by the two: *f += *g++; or *f = *f + *g++; f++; f++; I found that the size of the object code was actually reduced. Chalk one up for readability *and* efficiency.