Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #164454

Re: Is the output of this program compiler dependent?

From James Kuyper <jameskuyper@alumni.caltech.edu>
Newsgroups comp.lang.c
Subject Re: Is the output of this program compiler dependent?
Date 2022-01-17 15:51 -0500
Organization A noiseless patient Spider
Message-ID <ss4kt1$csn$1@dont-email.me> (permalink)
References <ss2nci$a2k$1@gioia.aioe.org> <ss2okf$i0l$1@gioia.aioe.org> <ss36s7$ask$1@dont-email.me> <87fspm5yjb.fsf@bsb.me.uk> <ss3ua0$c7i$1@dont-email.me>

Show all headers | View raw


On 1/17/22 9:26 AM, David Brown wrote:
> On 17/01/2022 13:36, Ben Bacarisse wrote:
>> David Brown <david.brown@hesbynett.no> writes:
>>
>>> ("++i" is treated as "(i += 1)" or "(i = i + 1)", and there is a
>>> sequence pointer at the assignment operator.)
>>
>> No, there is no sequence point at assignment.
>>
> 
> Re-reading the section in the standards, I stand corrected.  Thank you.
> 
> I am trying to understand 6.5p2 here:
> 
> """
> If a side effect on a scalar object is unsequenced relative to either a
> different side effect on the same scalar object or a value computation
> using the value of the same scalar object, the behavior is undefined. If
> there are multiple allowable orderings of the subexpressions of an
> expression, the behavior is undefined if such an unsequenced side effect
> occurs in any of the orderings. 85)
> """
> 
> The footnote says that this allows expressions like "i = i + 1;" while
> rendering undefined "i = ++i + 1;".
> 
> (If there had been a sequence point at assignment, then this second
> statement would have had defined behaviour.)
> 
> But in "i = i + 1;", the store to "i" is a side-effect on "i".  The
> calculation "i + 1" is a value computation using the same scalar object.
>  With no sequence point, these are unsequenced - and therefore
> undefined.  What am I missing?

"The value computations of the operands of an operator are sequenced
before the value computation of the result of the operator." (6.5p1).

assignment:
"The side effect of updating the stored value of the left operand is
sequenced after the value computations of the left and right operands."
(6.5.16).

prefix increment and decrement:
"The expression ++E is equivalent to (E+=1)" (6.5.3.1p2). Therefore, per
6.5.16, the value computation is sequenced before the side effect of
updating the stored value.

A: value computation of ++i
B: update to value of i due to ++i
C: value computation of +
D: update to value of i due to =

A is sequenced before both B and C, and C is sequenced before D.
However, B is not sequenced relative to both C and D. Being unsequenced
relative to D is what renders the behavior undefined.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Is the output of this program compiler dependent? Satan <satan@dot.com> - 2022-01-17 03:39 +0000
  Re: Is the output of this program compiler dependent? Richard Damon <Richard@Damon-Family.org> - 2022-01-16 23:19 -0500
  Re: Is the output of this program compiler dependent? James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-01-16 23:24 -0500
  Re: Is the output of this program compiler dependent? David Brown <david.brown@hesbynett.no> - 2022-01-17 08:46 +0100
    Re: Is the output of this program compiler dependent? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-01-17 12:36 +0000
      Re: Is the output of this program compiler dependent? David Brown <david.brown@hesbynett.no> - 2022-01-17 15:26 +0100
        Re: Is the output of this program compiler dependent? Öö Tiib <ootiib@hot.ee> - 2022-01-17 08:04 -0800
        Re: Is the output of this program compiler dependent? James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-01-17 15:51 -0500
    Re: Is the output of this program compiler dependent? James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-01-17 15:52 -0500

csiph-web