🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #576

Re: No sequence points in assignment

#576
From: Joe English
Date: Wed, 13 Sep 1989 00:43
38 lines
2206 bytes
karzes@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?  Since it knows that the value of (x = b) is b,
>can't it delay the assignment of b to x?  I.e., could this
>statement be validly translated as "evaluate b, evaluate a,
>add, assign the result to x, assign the previous result, b,
>to x"?


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, unless you're trying to
write incredibly hairy expressions like using a temporary variable
multiple times in a single expression.  (Which you probably shouldn't
be doing in the first place!)

Just wondering,

--Joe English

  jeenglis@nunki.usc.edu
Technical Details
Message-ID: <5059@merlin.usc.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!usc!merlin.usc.edu!nunki.usc.edu!jeenglis
References: <1021@m3.mfci.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!usc!merlin.usc.edu!nunki.usc.edu!jeenglis
From: jeenglis@nunki.usc.edu (Joe English)
Newsgroups: comp.std.c
Subject: Re: No sequence points in assignment
Message-ID: <5059@merlin.usc.edu>
Date: 13 Sep 89 00:43:36 GMT
References: <1021@m3.mfci.UUCP>
Sender: news@merlin.usc.edu
Reply-To: jeenglis@nunki.usc.edu (Joe English)
Distribution: comp
Organization: University of Southern California, Los Angeles, CA
Lines: 38