No sequence points in assignment

Ronald Guilmette rfg at ics.uci.edu
Mon Sep 18 13:57:04 AEST 1989


In article <5059 at merlin.usc.edu> jeenglis at nunki.usc.edu (Joe English) writes:
>karzes at mfci.UUCP (Tom Karzes) writes:
>>I have a question about assignment expressions.  According to the standard,
>>an assignment expression does not introduce a sequence point, although the
>>side effect of updating the stored value of the left operand must occur
>>between the previous sequence point and the next sequence point.  This
>>seems to imply that in an expression with multiple assignments, the actual
>>assignments may occur in any order provided the stored values can be
>>determined and the assignments all take place between the previous
>>sequence point and the next sequence point.  If this interpretation is
>>correct, it seems to me that it can lead to some counter intuitive
>>results.  For example, consider the following statement:
>>
>>    x = a + (x = b);
>>
>>Could the assignment for (x = b) be performed after the outer
>>assignment?

>
>As far as I know, yes.  I have a question, though:  Does it really
>matter?  There seems to be a lot of traffic lately asking questions
>like:  "Will (obviously buggy and weird code) work like you would
>expect it to, or is the compiler allowed to do something other than
>What I Mean?" 
>
>I fail to see how these questions are relevant...

If you don't understand why such questions *are* relevent to this newsgroup
then maybe you are reading the wrong newsgroup.  You obviously don't
understand what the standardization effort is all about.

Consider this.  You are given a piece of code and asked to port it to your
company's new ZLOP-19 micro-supercomputer.  The guy who wrote the code (let's
call him Fred) left the company six months ago.  You recompile the code on
the ZLOP-19 and run it.  It issues a prompt and core dumps.  You spend an
hour with your favorite debugger and track the problem to the following
statement:

	x = a + (x = b);

Now you know this program worked fine on the good ol' VAX, so what is the
problem?  Should you (a) tell your boss that Fred was a turkey who wrote
non-ANSI (and non-portable) code and then change the code or (b) contact your
compiler vendor to file a bug report.

Only the "standard" can help you decide on the proper action.

// rfg



More information about the Comp.std.c mailing list