Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Memories of you remind me of you. -- Karl Lehenbauer


devel / comp.lang.c / Re: Is the output of this program compiler dependent?

SubjectAuthor
* Re: Is the output of this program compiler dependent?Satan
+- Re: Is the output of this program compiler dependent?Richard Damon
+- Re: Is the output of this program compiler dependent?James Kuyper
`* Re: Is the output of this program compiler dependent?David Brown
 +* Re: Is the output of this program compiler dependent?Ben Bacarisse
 |`* Re: Is the output of this program compiler dependent?David Brown
 | +- Re: Is the output of this program compiler dependent?Öö Tiib
 | `- Re: Is the output of this program compiler dependent?James Kuyper
 `- Re: Is the output of this program compiler dependent?James Kuyper

1
Re: Is the output of this program compiler dependent?

<ss2okf$i0l$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19998&group=comp.lang.c#19998

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!bU2I7+U2Lztfeei1gwcHPg.user.46.165.242.91.POSTED!not-for-mail
From: sat...@dot.com (Satan)
Newsgroups: comp.lang.c
Subject: Re: Is the output of this program compiler dependent?
Date: Mon, 17 Jan 2022 03:39:30 +0000
Organization: Aioe.org NNTP Server
Message-ID: <ss2okf$i0l$1@gioia.aioe.org>
References: <ss2nci$a2k$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain;
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="18453"; posting-host="bU2I7+U2Lztfeei1gwcHPg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Satan - Mon, 17 Jan 2022 03:39 UTC

Sorry this was posted on the wrong newsgroup so I am posting it here!

On 17/01/2022 03:00, Satan wrote:
> I read somewhere that the parameters of functions are evaluated right >>
> to left but it all depends on the compiler. Therefore, does this mean
> that the output of this program is "undefined" meaning there is no
> definite answer!
>
> #include <stdio.h>
>
> void fun(int, int);
>
> int main()
> {
> int i = 5;
> fun(--i, i++);
> fun(++i, i--);
> printf("From Main: %d\n", i++);
>
> return 0;
> }
>
> void fun(int x, int y)
> {
> printf("From Function: %d %d\n", x++, y--);
> }
>

Re: Is the output of this program compiler dependent?

<p76FJ.6202$rQ.3610@fx18.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19999&group=comp.lang.c#19999

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx18.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.5.0
Subject: Re: Is the output of this program compiler dependent?
Content-Language: en-US
Newsgroups: comp.lang.c
References: <ss2nci$a2k$1@gioia.aioe.org> <ss2okf$i0l$1@gioia.aioe.org>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <ss2okf$i0l$1@gioia.aioe.org>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 45
Message-ID: <p76FJ.6202$rQ.3610@fx18.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sun, 16 Jan 2022 23:19:36 -0500
X-Received-Bytes: 2283
 by: Richard Damon - Mon, 17 Jan 2022 04:19 UTC

On 1/16/22 10:39 PM, Satan wrote:
> Sorry this was posted on the wrong newsgroup so I am posting it here!
>
>
> On 17/01/2022 03:00, Satan wrote:
>> I read somewhere that the parameters of functions are evaluated right >>
>> to left but it all depends on the compiler. Therefore, does this mean
>> that the output of this program is "undefined" meaning there is no
>> definite answer!
>>
>> #include <stdio.h>
>>
>> void fun(int, int);
>>
>> int main()
>> {
>> int i = 5;
>> fun(--i, i++);
>> fun(++i, i--);
>> printf("From Main: %d\n", i++);
>>
>> return 0;
>> }
>>
>> void fun(int x, int y)
>> {
>> printf("From Function: %d %d\n", x++, y--);
>> }
>>
>
>
>
>

Yes, there is no sequencing between the evaluation of the various
parameters to the function, to those calls invoke undefined behavior.

Implementations might give additional promises, but that is beyond the
control of the standard, and there may be a 'normal' order they follow,
but that still doesn't make it a requirement, and you might get burned
by a case where the implementation did it different in some case because
of ...reasons... so do go by what seems to work.

Remember, doing what you expected is perfectly fine possible undefined
behavior, but you shouldn't count on it.

Re: Is the output of this program compiler dependent?

<ss2r1r$e28$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20000&group=comp.lang.c#20000

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Is the output of this program compiler dependent?
Date: Sun, 16 Jan 2022 23:24:26 -0500
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <ss2r1r$e28$1@dont-email.me>
References: <ss2nci$a2k$1@gioia.aioe.org> <ss2okf$i0l$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 17 Jan 2022 04:24:27 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="fd482cf1ea24e5ecb0e212548399ef82";
logging-data="14408"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+w8ai42HA3GxJAQpH0MKAnowtK24CUgVI="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:RaXUc1HncicIvZ7121ic3avjyhQ=
In-Reply-To: <ss2okf$i0l$1@gioia.aioe.org>
Content-Language: en-US
 by: James Kuyper - Mon, 17 Jan 2022 04:24 UTC

On 1/16/22 10:39 PM, Satan wrote:
> Sorry this was posted on the wrong newsgroup so I am posting it here!
>
>
> On 17/01/2022 03:00, Satan wrote:
>> I read somewhere that the parameters of functions are evaluated right >>
>> to left but it all depends on the compiler. Therefore, does this mean
>> that the output of this program is "undefined" meaning there is no
>> definite answer!
>>
>> #include <stdio.h>
>>
>> void fun(int, int);
>>
>> int main()
>> {
>> int i = 5;
>> fun(--i, i++);
>> fun(++i, i--);
>> printf("From Main: %d\n", i++);
>>
>> return 0;
>> }
>>
>> void fun(int x, int y)
>> {
>> printf("From Function: %d %d\n", x++, y--);>> }

"Except as specified later, side effects and value computations of
subexpressions are unsequenced." (6.5p3).

The description of function call expressions is "later", but does not
specify the sequencing of the argument sub-expressions relative to each
other, so they are unsequenced. That doesn't matter for your printf()
calls. However, it does matter for your calls to fun().

"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." (6.5p2).

`i` is a scalar object, and both of your calls to fun() involve two
different sub-expressions with side effects on `i`, and there are
multiple permitted orderings of those sub-expressions, so the behavior
of your code is undefined.

`undefined behavior` is a much stronger statement than "unspecified". It
means that the C standard imposes NO requirements on the behavior of
your program.

Re: Is the output of this program compiler dependent?

<ss36s7$ask$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20002&group=comp.lang.c#20002

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Is the output of this program compiler dependent?
Date: Mon, 17 Jan 2022 08:46:14 +0100
Organization: A noiseless patient Spider
Lines: 89
Message-ID: <ss36s7$ask$1@dont-email.me>
References: <ss2nci$a2k$1@gioia.aioe.org> <ss2okf$i0l$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 17 Jan 2022 07:46:15 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1f3da9c03866acc468cd6738a39f9dee";
logging-data="11156"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/kGGpZi0+7tPYEW09WWIGm2LL0lv2gRAQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:I4zzuVh/bTns7HnblSJJHv9rlVc=
In-Reply-To: <ss2okf$i0l$1@gioia.aioe.org>
Content-Language: en-GB
 by: David Brown - Mon, 17 Jan 2022 07:46 UTC

On 17/01/2022 04:39, Satan wrote:
> Sorry this was posted on the wrong newsgroup so I am posting it here!
>
>
> On 17/01/2022 03:00, Satan wrote:
>> I read somewhere that the parameters of functions are evaluated right >>
>> to left but it all depends on the compiler. Therefore, does this mean
>> that the output of this program is "undefined" meaning there is no
>> definite answer!
>>

Your conclusion is correct, but the reasoning is slightly wrong.

First, the order of evaluation of parameters to a function is
"indeterminately sequenced". (As is the function identifier itself,
which could be a function pointer.)

So if you have "foo(A, B)", then the compiler must either evaluate "A"
before evaluating "B", or evaluate "B" before evaluating "A". It can
pick either. It doesn't even have to have a fixed order in the code -
it could swap the orders between different calls. But logically it has
to do one completely before doing the other. (As always, the compiler
can generate mixtures of the evaluations as long as the results match
the logical requirements.)

Some more limited compilers have fixed evaluation order of function
parameters. More optimising compilers will choose whatever works best
at the time.

But it is not the unspecified ordering of evaluation of the arguments
that is the problem in your code. It is a matter of "sequence points".
These can be thought of as barriers in the code - logically, when the
code hits a sequence point, everything before it must be finished and
then you can start on everything after it. The end of a statement is a
sequence point - so for "i++; i--;" the increment has to be completed
before the decrement can be done, and everything works out safely.

There is no sequence point between evaluating the arguments of a function.

Between sequence points, you are limited in what you can do as the state
of the program has to be consistent. For any given object, you can
either write to it once, or read from it (as often as you like) - you
can't do both, and you can't write more than once. This makes sense if
you think about it.

("++i" is treated as "(i += 1)" or "(i = i + 1)", and there is a
sequence pointer at the assignment operator.)

So the trouble with "fun(--i, i++);" is /not/ a matter of which function
argument is evaluated first. It is that you are mixing multiple reads
and writes to "i" without a clear ordering - and that is undefined
behaviour.

Note that "undefined behaviour" does not just mean there is no definite
answer - it means that /anything/ can happen. It's not just a matter of
getting different integers printed when using different compilers
(though that's the most likely outcome) - maybe you'll get nothing at
all, or a crash, or demons will fly out of your nose. Trying to execute
undefined behaviour is a really bad thing!

>> #include <stdio.h>
>>
>> void fun(int, int);
>>
>> int main()
>> {
>> int i = 5;
>> fun(--i, i++);
>> fun(++i, i--);
>> printf("From Main: %d\n", i++);
>>
>> return 0;
>> }
>>
>> void fun(int x, int y)
>> {
>> printf("From Function: %d %d\n", x++, y--);
>> }
>>
>
>
>
>

Re: Is the output of this program compiler dependent?

<87fspm5yjb.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20003&group=comp.lang.c#20003

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Is the output of this program compiler dependent?
Date: Mon, 17 Jan 2022 12:36:56 +0000
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <87fspm5yjb.fsf@bsb.me.uk>
References: <ss2nci$a2k$1@gioia.aioe.org> <ss2okf$i0l$1@gioia.aioe.org>
<ss36s7$ask$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="ab704c70d1bdbef5793a106f0a9c6472";
logging-data="24554"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198YeJp15l1tOlDh+/gvOOWMi/bFQJpET4="
Cancel-Lock: sha1:mVy8Znxmoz8elqeaL7dVsv1Wqc4=
sha1:F2mp0U1sNS91RcVKLq059+7Zgxk=
X-BSB-Auth: 1.f5d167256b38d690ebe3.20220117123656GMT.87fspm5yjb.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 17 Jan 2022 12:36 UTC

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.

--
Ben.

Re: Is the output of this program compiler dependent?

<ss3ua0$c7i$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20011&group=comp.lang.c#20011

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Is the output of this program compiler dependent?
Date: Mon, 17 Jan 2022 15:26:07 +0100
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <ss3ua0$c7i$1@dont-email.me>
References: <ss2nci$a2k$1@gioia.aioe.org> <ss2okf$i0l$1@gioia.aioe.org>
<ss36s7$ask$1@dont-email.me> <87fspm5yjb.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 17 Jan 2022 14:26:08 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1f3da9c03866acc468cd6738a39f9dee";
logging-data="12530"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/PEz1zJqZL0+IwlE+qjsxsmnYo9WMrFV0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:WKeuIM9Pytzagj9FVU9+YA/CsR0=
In-Reply-To: <87fspm5yjb.fsf@bsb.me.uk>
Content-Language: en-GB
 by: David Brown - Mon, 17 Jan 2022 14:26 UTC

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?

Re: Is the output of this program compiler dependent?

<8ec124ca-e043-4f82-95af-f1c9b46087c9n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20012&group=comp.lang.c#20012

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:5ce:: with SMTP id d14mr17439941qtb.412.1642435488243;
Mon, 17 Jan 2022 08:04:48 -0800 (PST)
X-Received: by 2002:a05:620a:1987:: with SMTP id bm7mr11628454qkb.450.1642435488108;
Mon, 17 Jan 2022 08:04:48 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 17 Jan 2022 08:04:47 -0800 (PST)
In-Reply-To: <ss3ua0$c7i$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=94.246.251.164; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 94.246.251.164
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>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8ec124ca-e043-4f82-95af-f1c9b46087c9n@googlegroups.com>
Subject: Re: Is the output of this program compiler dependent?
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Mon, 17 Jan 2022 16:04:48 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 34
 by: Öö Tiib - Mon, 17 Jan 2022 16:04 UTC

On Monday, 17 January 2022 at 16:26:22 UTC+2, David Brown wrote:
> On 17/01/2022 13:36, Ben Bacarisse wrote:
> > David Brown <david...@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?

Hmm? As neither i nor i + 1 changes value of i these can be evaluated
unsequenced, yet the outcome of i = i + 1 will be still always same as
assignment itself can happen only after both have been evaluated.

Re: Is the output of this program compiler dependent?

<ss4kt1$csn$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20020&group=comp.lang.c#20020

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Is the output of this program compiler dependent?
Date: Mon, 17 Jan 2022 15:51:45 -0500
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <ss4kt1$csn$1@dont-email.me>
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>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 17 Jan 2022 20:51:45 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="fd482cf1ea24e5ecb0e212548399ef82";
logging-data="13207"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18uE7Rt3cNAkgkog2Kc3O0JxxrDCWE5nWU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:UNXNXJtjlLwRTyt1WiX259pFelQ=
In-Reply-To: <ss3ua0$c7i$1@dont-email.me>
Content-Language: en-US
 by: James Kuyper - Mon, 17 Jan 2022 20:51 UTC

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.

Re: Is the output of this program compiler dependent?

<ss4kub$csn$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20021&group=comp.lang.c#20021

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Is the output of this program compiler dependent?
Date: Mon, 17 Jan 2022 15:52:27 -0500
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <ss4kub$csn$2@dont-email.me>
References: <ss2nci$a2k$1@gioia.aioe.org> <ss2okf$i0l$1@gioia.aioe.org>
<ss36s7$ask$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 17 Jan 2022 20:52:27 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="fd482cf1ea24e5ecb0e212548399ef82";
logging-data="13207"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195bxyw+gLI+LezULsmxtc2x4cMoyuYSBc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:75g5DUselSifLYh8IsFsynrJcP4=
In-Reply-To: <ss36s7$ask$1@dont-email.me>
Content-Language: en-US
 by: James Kuyper - Mon, 17 Jan 2022 20:52 UTC

On 1/17/22 2:46 AM, David Brown wrote:
....
> First, the order of evaluation of parameters to a function is

I think you mean "arguments" rather than "parameters".

> "indeterminately sequenced". (As is the function identifier itself,
> which could be a function pointer.)

"Except as specified later, side effects and value computations of
subexpressions are unsequenced." (6.5p3). The description of Function
calls (6.5.2.2) specifies that there is a sequence point separating
evaluation of the function designator and the function arguments from
the evaluation of the function call itself, but says nothing about the
sequencing of the function designator and the arguments relative to each
other, so 6.5p3 applies to those.

This matters because evaluations that are unsequenced can be
interleaved, but evaluations that are indeterminately sequenced cannot
be be interleaved (footnote 13).

Evaluations in a calling function can be indeterminately sequenced
relative to the called function (6.5.2.2p10), and evaluations in an
initializer list are indeterminately sequenced relative to each other
(6.7.9p23). In all other cases, evaluations are either sequenced or
unsequenced relative to each other, but never indeterminately sequenced.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor