Does your compiler get this program right?
    Maarten Litmaath 
    maart at cs.vu.nl
       
    Fri Nov 25 04:57:25 AEST 1988
    
    
  
In article <4082 at cs.utexas.edu> meyering at cs.utexas.edu (Jim Meyering) writes:
\In article <2298 at cbnews.ATT.COM> lvc at 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.
It IS a bug!
\	[...deleted commentary, code]
\	>*f++ += *g++;		/* miscompiled line */
\
\The standard does not specify the order of evaluation for such
\statements.
There is NO problem concerning evaluation order! Remember: `a += b' means
`a = a + b, BUT evaluate a only ONCE!'
\...
\	*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.
Readability? Hahaha! No, really :-(
`*f++ += *g++' is perfectly readable and valid C. It's constructs like this
one that make C as powerful as it is. Are you a Pascal or Modula freak?
Consider `LongVariableName = LongVariableName + 3': do you find this gem
more readable? More typable?
If there are side effects, you cannot even use the `Pascal construct'.
-- 
fcntl(fd, F_SETFL, FNDELAY):          |Maarten Litmaath @ VU Amsterdam:
      let's go weepin' in the corner! |maart at cs.vu.nl, mcvax!botter!maart
    
    
More information about the Comp.lang.c
mailing list