Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #119321 > unrolled thread
| Started by | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| First post | 2024-05-23 16:14 +0200 |
| Last post | 2024-07-23 10:01 -0400 |
| Articles | 20 on this page of 53 — 12 participants |
Back to article view | Back to comp.lang.c++
is "x *= ++f * ++f" a valid statement ? Bonita Montero <Bonita.Montero@gmail.com> - 2024-05-23 16:14 +0200
Re: is "x *= ++f * ++f" a valid statement ? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2024-06-18 18:53 -0700
Re: is "x *= ++f * ++f" a valid statement ? Bonita Montero <Bonita.Montero@gmail.com> - 2024-06-19 17:40 +0200
Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-21 16:55 -0500
Re: is "x *= ++f * ++f" a valid statement ? PLO Richard Damon <richard@damon-family.org> - 2024-06-21 18:10 -0400
Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-21 18:06 -0500
Re: is "x *= ++f * ++f" a valid statement ? PLO Richard Damon <richard@damon-family.org> - 2024-06-21 20:14 -0400
Re: is "x *= ++f * ++f" a valid statement ? PLO Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-21 17:35 -0700
Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-21 22:58 -0500
Re: is "x *= ++f * ++f" a valid statement ? PLO Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-21 23:18 -0700
Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-22 07:38 -0500
Re: is "x *= ++f * ++f" a valid statement ? PLO Richard Damon <richard@damon-family.org> - 2024-06-22 09:45 -0400
Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-22 09:13 -0500
Re: is "x *= ++f * ++f" a valid statement ? PLO Richard Damon <richard@damon-family.org> - 2024-06-22 10:23 -0400
Re: is "x *= ++f * ++f" a valid statement ? PLO Mikko <mikko.levanto@iki.fi> - 2024-06-23 11:48 +0300
Re: is "x *= ++f * ++f" a valid statement ? PLO Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-22 17:54 -0700
Re: is "x *= ++f * ++f" a valid statement ? PLO James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-06-21 23:42 -0400
Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-21 23:02 -0500
Re: is "x *= ++f * ++f" a valid statement ? PLO David Brown <david.brown@hesbynett.no> - 2024-06-22 13:09 +0200
Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-22 07:40 -0500
Re: is "x *= ++f * ++f" a valid statement ? PLO Richard Damon <richard@damon-family.org> - 2024-06-22 09:56 -0400
Re: is "x *= ++f * ++f" a valid statement ? PLO "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-06-22 12:14 -0700
Re: is "x *= ++f * ++f" a valid statement ? PLO David Brown <david.brown@hesbynett.no> - 2024-06-22 16:52 +0200
Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-22 11:27 -0500
Re: is "x *= ++f * ++f" a valid statement ? PLO Richard Damon <richard@damon-family.org> - 2024-06-22 13:20 -0400
Re: is "x *= ++f * ++f" a valid statement ? PLO Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-22 17:55 -0700
Re: is "x *= ++f * ++f" a valid statement ? PLO David Brown <david.brown@hesbynett.no> - 2024-06-23 14:46 +0200
Re: is "x *= ++f * ++f" a valid statement ? PLO James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-06-22 15:48 -0400
Re: is "x *= ++f * ++f" a valid statement ? Richard Damon <richard@damon-family.org> - 2024-06-18 22:27 -0400
Re: is "x *= ++f * ++f" a valid statement ? olcott <polcott333@gmail.com> - 2024-06-22 21:51 -0500
Re: is "x *= ++f * ++f" a valid statement ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-22 21:51 -0700
Re: is "x *= ++f * ++f" a valid statement ? Richard Damon <richard@damon-family.org> - 2024-06-23 07:32 -0400
Re: is "x *= ++f * ++f" a valid statement ? olcott <polcott333@gmail.com> - 2024-06-23 07:59 -0500
Re: is "x *= ++f * ++f" a valid statement ? Richard Damon <richard@damon-family.org> - 2024-06-23 14:25 -0400
Re: is "x *= ++f * ++f" a valid statement ? olcott <polcott333@gmail.com> - 2024-06-23 14:18 -0500
Re: is "x *= ++f * ++f" a valid statement ? Richard Damon <richard@damon-family.org> - 2024-06-23 16:23 -0400
Re: is "x *= ++f * ++f" a valid statement ? David Brown <david.brown@hesbynett.no> - 2024-06-24 09:11 +0200
Re: is "x *= ++f * ++f" a valid statement ? what@tf.com (testuseri2p) - 2024-07-22 17:51 +0000
Re: is "x *= ++f * ++f" a valid statement ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-07-22 14:58 -0700
Re: is "x *= ++f * ++f" a valid statement ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-07-22 21:57 -0400
Re: is "x *= ++f * ++f" a valid statement ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-07-22 20:40 -0700
Re: is "x *= ++f * ++f" a valid statement ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-07-23 10:15 -0400
Re: is "x *= ++f * ++f" a valid statement ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-07-23 07:28 -0700
Re: is "x *= ++f * ++f" a valid statement ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-07-23 14:42 -0700
Re: is "x *= ++f * ++f" a valid statement ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-07-23 15:05 -0700
Re: is "x *= ++f * ++f" a valid statement ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-08-11 06:22 -0700
Re: is "x *= ++f * ++f" a valid statement ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-08-11 14:09 -0700
Re: is "x *= ++f * ++f" a valid statement ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-08-11 06:11 -0700
Re: is "x *= ++f * ++f" a valid statement ? Chris Ahlstrom <OFeem1987@teleworm.us> - 2024-08-11 09:25 -0400
Re: is "x *= ++f * ++f" a valid statement ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-08-11 14:17 -0400
Re: is "x *= ++f * ++f" a valid statement ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-07-23 07:32 -0700
Re: is "x *= ++f * ++f" a valid statement ? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2024-07-22 19:53 -0700
Re: is "x *= ++f * ++f" a valid statement ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-07-23 10:01 -0400
Page 1 of 3 [1] 2 3 Next page →
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2024-05-23 16:14 +0200 |
| Subject | is "x *= ++f * ++f" a valid statement ? |
| Message-ID | <v2nivh$1pl7o$1@raubtier-asyl.eternal-september.org> |
Is "x *= ++f * ++f" a valid statement ? Or is there implementation defined behaviour ?
[toc] | [next] | [standalone]
| From | Andrey Tarasevich <andreytarasevich@hotmail.com> |
|---|---|
| Date | 2024-06-18 18:53 -0700 |
| Message-ID | <v4tdm0$1ofb8$1@dont-email.me> |
| In reply to | #119321 |
On 05/23/24 7:14 AM, Bonita Montero wrote: > Is "x *= ++f * ++f" a valid statement ? > Or is there implementation defined behaviour ? The question is meaningless without knowing the types of objects involved. It has no specific answer -- Best regards, Andrey
[toc] | [prev] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2024-06-19 17:40 +0200 |
| Message-ID | <v4uu5q$21ncg$1@raubtier-asyl.eternal-september.org> |
| In reply to | #119475 |
Am 19.06.2024 um 03:53 schrieb Andrey Tarasevich: > On 05/23/24 7:14 AM, Bonita Montero wrote: >> Is "x *= ++f * ++f" a valid statement ? >> Or is there implementation defined behaviour ? > > The question is meaningless without knowing the types of objects > involved. It has no specific answer You feel uncertain for nothing.
[toc] | [prev] | [next] | [standalone]
| From | olcott <polcott333@gmail.com> |
|---|---|
| Date | 2024-06-21 16:55 -0500 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <v54ss8$3bqqj$1@dont-email.me> |
| In reply to | #119475 |
On 6/18/2024 8:53 PM, Andrey Tarasevich wrote: > On 05/23/24 7:14 AM, Bonita Montero wrote: >> Is "x *= ++f * ++f" a valid statement ? >> Or is there implementation defined behaviour ? > > The question is meaningless without knowing the types of objects > involved. It has no specific answer > If it works correctly for int then it is syntactically correct: int x = 1; int f = 1; x = 1 * (2 * 3); ++f could be defined as exit(0) for some UDT. -- Copyright 2024 Olcott "Talent hits a target no one else can hit; Genius hits a target no one else can see." Arthur Schopenhauer
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <richard@damon-family.org> |
|---|---|
| Date | 2024-06-21 18:10 -0400 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <v54tpa$lkkc$14@i2pn2.org> |
| In reply to | #119480 |
On 6/21/24 5:55 PM, olcott wrote: > On 6/18/2024 8:53 PM, Andrey Tarasevich wrote: >> On 05/23/24 7:14 AM, Bonita Montero wrote: >>> Is "x *= ++f * ++f" a valid statement ? >>> Or is there implementation defined behaviour ? >> >> The question is meaningless without knowing the types of objects >> involved. It has no specific answer >> > > If it works correctly for int then it is > syntactically correct: > int x = 1; > int f = 1; > x = 1 * (2 * 3); > > ++f could be defined as exit(0) for some UDT. > But, the DEFINITON of ++ doesn't requring that one of the f's are incremented first, then you use the value, then the othero one. (unless the rules were actually changed). x *= ++f + ++f could be implemented as f = f+1; f = f+1; x *= f * f; it could even be done as ; tf1 = f+1 tf2 = f+1; x *= tf1 + tf2; f = tf1; f = tf2; so, we have no promise that f even increases by 2 At least this is what it could be under the original rules. I would have to see if it was tightened when threading was allowed.
[toc] | [prev] | [next] | [standalone]
| From | olcott <polcott333@gmail.com> |
|---|---|
| Date | 2024-06-21 18:06 -0500 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <v5512d$3cgv7$2@dont-email.me> |
| In reply to | #119481 |
On 6/21/2024 5:10 PM, Richard Damon wrote: > On 6/21/24 5:55 PM, olcott wrote: >> On 6/18/2024 8:53 PM, Andrey Tarasevich wrote: >>> On 05/23/24 7:14 AM, Bonita Montero wrote: >>>> Is "x *= ++f * ++f" a valid statement ? >>>> Or is there implementation defined behaviour ? >>> >>> The question is meaningless without knowing the types of objects >>> involved. It has no specific answer >>> >> >> If it works correctly for int then it is >> syntactically correct: >> int x = 1; >> int f = 1; >> x = 1 * (2 * 3); >> >> ++f could be defined as exit(0) for some UDT. >> > > But, the DEFINITON of ++ doesn't requring that one of the f's are > incremented first, then you use the value, then the othero one. (unless > the rules were actually changed). > When we assume the *= assigns the result of the RHS * the LHS to the LHS "x *= ++f * ++f" means x = x * (++f * ++f) thus cannot have implementation defined behavior. -- Copyright 2024 Olcott "Talent hits a target no one else can hit; Genius hits a target no one else can see." Arthur Schopenhauer
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <richard@damon-family.org> |
|---|---|
| Date | 2024-06-21 20:14 -0400 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <v5550g$lkkc$16@i2pn2.org> |
| In reply to | #119482 |
On 6/21/24 7:06 PM, olcott wrote: > On 6/21/2024 5:10 PM, Richard Damon wrote: >> On 6/21/24 5:55 PM, olcott wrote: >>> On 6/18/2024 8:53 PM, Andrey Tarasevich wrote: >>>> On 05/23/24 7:14 AM, Bonita Montero wrote: >>>>> Is "x *= ++f * ++f" a valid statement ? >>>>> Or is there implementation defined behaviour ? >>>> >>>> The question is meaningless without knowing the types of objects >>>> involved. It has no specific answer >>>> >>> >>> If it works correctly for int then it is >>> syntactically correct: >>> int x = 1; >>> int f = 1; >>> x = 1 * (2 * 3); >>> >>> ++f could be defined as exit(0) for some UDT. >>> >> >> But, the DEFINITON of ++ doesn't requring that one of the f's are >> incremented first, then you use the value, then the othero one. >> (unless the rules were actually changed). >> > > When we assume the *= assigns > the result of the RHS * the LHS to the LHS > "x *= ++f * ++f" > > means x = x * (++f * ++f) > thus cannot have implementation defined behavior. > > Sure it can, because the order of the parts of the operation of the two ++f is unspecified. In fact, the implementation doesn't need to define it at all, it is just unspecified (and it used to invoke Undefined Behavior, I am not sure if that clause is still there) Detail explaination of the operation of ++f has effectively 4 steps 1) read the value of f 2) increment the value read 3) write that value back into f 4) use that value in the expression Sequence wise, we have that 1 is before 2 is before 3, and 2 is before 4, but 3 and 4 are not ordered with respect to one another. And, the sequence of operations between the two different ++f operations have no sequeenc between each other, only that both of their step 4 are working at the same time to make the final result of that operation. Thus, both reads of the value might occur before either write backs of either updated value, and thus f is only increased by 1 by the statement. In fact, the optimizer could well see that option and just read the value once increment it once, and write it back just once.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2024-06-21 17:35 -0700 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <87v821vmon.fsf@nosuchdomain.example.com> |
| In reply to | #119482 |
olcott <polcott333@gmail.com> writes:
> On 6/21/2024 5:10 PM, Richard Damon wrote:
>> On 6/21/24 5:55 PM, olcott wrote:
>>> On 6/18/2024 8:53 PM, Andrey Tarasevich wrote:
>>>> On 05/23/24 7:14 AM, Bonita Montero wrote:
>>>>> Is "x *= ++f * ++f" a valid statement ?
>>>>> Or is there implementation defined behaviour ?
>>>>
>>>> The question is meaningless without knowing the types of objects
>>>> involved. It has no specific answer
>>>>
>>>
>>> If it works correctly for int then it is
>>> syntactically correct:
>>> int x = 1;
>>> int f = 1;
>>> x = 1 * (2 * 3);
Yes, it's syntactically valid, but that wasn't the question.
>>> ++f could be defined as exit(0) for some UDT.
>>>
>> But, the DEFINITON of ++ doesn't requring that one of the f's are
>> incremented first, then you use the value, then the othero
>> one. (unless the rules were actually changed).
>>
>
> When we assume the *= assigns
> the result of the RHS * the LHS to the LHS
> "x *= ++f * ++f"
>
> means x = x * (++f * ++f)
> thus cannot have implementation defined behavior.
We don't have to assume anything. The meaning of "*=" is well known
(and you left out the fact that x is evaluated only once).
It doesn't have implementation-defined behavior. It has undefined
behavior. The C++ standard says so:
If a side effect on a memory location is unsequenced relative to
either another side effect on the same memory location or a value
computation using the value of any object in the same memory
location, and they are not potentially concurrent, the behavior is
undefined.
If x and f are objects of type int, then the evaluation of `++f * ++f`
has undefined behavior because the two modifications of f are
unsequenced. There isn't some limited number of possible behaviors.
The standard says nothing about what happens when the expression is
evaluated.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | olcott <polcott333@gmail.com> |
|---|---|
| Date | 2024-06-21 22:58 -0500 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <v55i5p$3j9dh$1@dont-email.me> |
| In reply to | #119484 |
On 6/21/2024 7:35 PM, Keith Thompson wrote: > olcott <polcott333@gmail.com> writes: >> On 6/21/2024 5:10 PM, Richard Damon wrote: >>> On 6/21/24 5:55 PM, olcott wrote: >>>> On 6/18/2024 8:53 PM, Andrey Tarasevich wrote: >>>>> On 05/23/24 7:14 AM, Bonita Montero wrote: >>>>>> Is "x *= ++f * ++f" a valid statement ? >>>>>> Or is there implementation defined behaviour ? >>>>> >>>>> The question is meaningless without knowing the types of objects >>>>> involved. It has no specific answer >>>>> >>>> >>>> If it works correctly for int then it is >>>> syntactically correct: >>>> int x = 1; >>>> int f = 1; >>>> x = 1 * (2 * 3); > > Yes, it's syntactically valid, but that wasn't the question. > >>>> ++f could be defined as exit(0) for some UDT. >>>> >>> But, the DEFINITON of ++ doesn't requring that one of the f's are >>> incremented first, then you use the value, then the othero >>> one. (unless the rules were actually changed). >>> >> >> When we assume the *= assigns >> the result of the RHS * the LHS to the LHS >> "x *= ++f * ++f" >> >> means x = x * (++f * ++f) >> thus cannot have implementation defined behavior. > > We don't have to assume anything. The meaning of "*=" is well known > (and you left out the fact that x is evaluated only once). > > It doesn't have implementation-defined behavior. It has undefined > behavior. The C++ standard says so: > > If a side effect on a memory location is unsequenced relative to > either another side effect on the same memory location or a value > computation using the value of any object in the same memory > location, and they are not potentially concurrent, the behavior is > undefined. > > If x and f are objects of type int, then the evaluation of `++f * ++f` > has undefined behavior because the two modifications of f are > unsequenced. There isn't some limited number of possible behaviors. > The standard says nothing about what happens when the expression is > evaluated. > That is weird I wold have chosen left to right sequence. I thought that the order of arithmetic operations specifies left to right sequence. -- Copyright 2024 Olcott "Talent hits a target no one else can hit; Genius hits a target no one else can see." Arthur Schopenhauer
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2024-06-21 23:18 -0700 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <87r0cpv6tp.fsf@nosuchdomain.example.com> |
| In reply to | #119486 |
olcott <polcott333@gmail.com> writes:
[...]
> That is weird I wold have chosen left to right sequence.
> I thought that the order of arithmetic operations specifies
> left to right sequence.
You may well have thought that. You were wrong. Do you understand that
now?
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | olcott <polcott333@gmail.com> |
|---|---|
| Date | 2024-06-22 07:38 -0500 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <v56gk9$3olbi$1@dont-email.me> |
| In reply to | #119488 |
On 6/22/2024 1:18 AM, Keith Thompson wrote: > olcott <polcott333@gmail.com> writes: > [...] >> That is weird I wold have chosen left to right sequence. >> I thought that the order of arithmetic operations specifies >> left to right sequence. > > You may well have thought that. You were wrong. Do you understand that > now? > "x *= ++f * ++f" int x = 5; int y = 3; For the calculation is question is seems to make no difference to the result. x = 5 * (4 * 5) x = 5 * (5 * 4) -- Copyright 2024 Olcott "Talent hits a target no one else can hit; Genius hits a target no one else can see." Arthur Schopenhauer
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <richard@damon-family.org> |
|---|---|
| Date | 2024-06-22 09:45 -0400 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <v56khk$onl4$5@i2pn2.org> |
| In reply to | #119491 |
On 6/22/24 8:38 AM, olcott wrote: > On 6/22/2024 1:18 AM, Keith Thompson wrote: >> olcott <polcott333@gmail.com> writes: >> [...] >>> That is weird I wold have chosen left to right sequence. >>> I thought that the order of arithmetic operations specifies >>> left to right sequence. >> >> You may well have thought that. You were wrong. Do you understand that >> now? >> > > "x *= ++f * ++f" > int x = 5; > int y = 3; > > For the calculation is question is seems to make no difference to the > result. > x = 5 * (4 * 5) > x = 5 * (5 * 4) > > In this case no, but if the operation was - it would, And, as pointed out there is no requirement on the ordering of even the sub-parts except determinism (we can't use a value we haven't computed yet). This means the ++ can be interleaved. And, because of the EXPLICIT requirement on updates to a value needing to be ordered to avoid undefined behavior, the compiler, seeing that Undefined Behavior exist there can do ANYTHING it wants with that code.
[toc] | [prev] | [next] | [standalone]
| From | olcott <polcott333@gmail.com> |
|---|---|
| Date | 2024-06-22 09:13 -0500 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <v56m66$3or0r$9@dont-email.me> |
| In reply to | #119494 |
On 6/22/2024 8:45 AM, Richard Damon wrote: > On 6/22/24 8:38 AM, olcott wrote: >> On 6/22/2024 1:18 AM, Keith Thompson wrote: >>> olcott <polcott333@gmail.com> writes: >>> [...] >>>> That is weird I wold have chosen left to right sequence. >>>> I thought that the order of arithmetic operations specifies >>>> left to right sequence. >>> >>> You may well have thought that. You were wrong. Do you understand that >>> now? >>> >> >> "x *= ++f * ++f" >> int x = 5; >> int y = 3; >> >> For the calculation is question is seems to make no difference to the >> result. >> x = 5 * (4 * 5) >> x = 5 * (5 * 4) >> >> > > In this case no, but if the operation was - it would, > > And, as pointed out there is no requirement on the ordering of even the > sub-parts except determinism (we can't use a value we haven't computed > yet). This means the ++ can be interleaved. > > And, because of the EXPLICIT requirement on updates to a value needing > to be ordered to avoid undefined behavior, In other words you fail to comprehend that: (5 * 4) == (4 * 5) > the compiler, seeing that > Undefined Behavior exist there can do ANYTHING it wants with that code. -- Copyright 2024 Olcott "Talent hits a target no one else can hit; Genius hits a target no one else can see." Arthur Schopenhauer
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <richard@damon-family.org> |
|---|---|
| Date | 2024-06-22 10:23 -0400 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <v56mp7$onl3$6@i2pn2.org> |
| In reply to | #119497 |
On 6/22/24 10:13 AM, olcott wrote: > On 6/22/2024 8:45 AM, Richard Damon wrote: >> On 6/22/24 8:38 AM, olcott wrote: >>> On 6/22/2024 1:18 AM, Keith Thompson wrote: >>>> olcott <polcott333@gmail.com> writes: >>>> [...] >>>>> That is weird I wold have chosen left to right sequence. >>>>> I thought that the order of arithmetic operations specifies >>>>> left to right sequence. >>>> >>>> You may well have thought that. You were wrong. Do you understand >>>> that >>>> now? >>>> >>> >>> "x *= ++f * ++f" >>> int x = 5; >>> int y = 3; >>> >>> For the calculation is question is seems to make no difference to the >>> result. >>> x = 5 * (4 * 5) >>> x = 5 * (5 * 4) >>> >>> >> >> In this case no, but if the operation was - it would, >> >> And, as pointed out there is no requirement on the ordering of even >> the sub-parts except determinism (we can't use a value we haven't >> computed yet). This means the ++ can be interleaved. >> >> And, because of the EXPLICIT requirement on updates to a value needing >> to be ordered to avoid undefined behavior, > > In other words you fail to comprehend that: (5 * 4) == (4 * 5) no, the issue is that the two ++f are unsequenced, so one possible result (ignore the allowance of total undefined behavior) is (4*4), sine the code COULD be compiled to the equivalent of: int __t1 = f; int __t2 = __t1+1; int __t3 = f; int __t4 = __t3+1; x *= __t2 * __t4; f = __t2; f = __t4; > >> the compiler, seeing that Undefined Behavior exist there can do >> ANYTHING it wants with that code. >
[toc] | [prev] | [next] | [standalone]
| From | Mikko <mikko.levanto@iki.fi> |
|---|---|
| Date | 2024-06-23 11:48 +0300 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <v58nhm$8ue9$1@dont-email.me> |
| In reply to | #119494 |
On 2024-06-22 13:45:24 +0000, Richard Damon said: > On 6/22/24 8:38 AM, olcott wrote: >> On 6/22/2024 1:18 AM, Keith Thompson wrote: >>> olcott <polcott333@gmail.com> writes: >>> [...] >>>> That is weird I wold have chosen left to right sequence. >>>> I thought that the order of arithmetic operations specifies >>>> left to right sequence. >>> >>> You may well have thought that. You were wrong. Do you understand that >>> now? >>> >> >> "x *= ++f * ++f" >> int x = 5; >> int y = 3; >> >> For the calculation is question is seems to make no difference to the result. >> x = 5 * (4 * 5) >> x = 5 * (5 * 4) >> >> > > In this case no, but if the operation was - it would, > > And, as pointed out there is no requirement on the ordering of even the > sub-parts except determinism (we can't use a value we haven't computed > yet). This means the ++ can be interleaved. > > And, because of the EXPLICIT requirement on updates to a value needing > to be ordered to avoid undefined behavior, the compiler, seeing that > Undefined Behavior exist there can do ANYTHING it wants with that code. For example, a valid interpretation is to store the value 17 in z. -- Mikko
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2024-06-22 17:54 -0700 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <878qywv5qk.fsf@nosuchdomain.example.com> |
| In reply to | #119491 |
olcott <polcott333@gmail.com> writes:
> On 6/22/2024 1:18 AM, Keith Thompson wrote:
>> olcott <polcott333@gmail.com> writes:
>> [...]
>>> That is weird I wold have chosen left to right sequence.
>>> I thought that the order of arithmetic operations specifies
>>> left to right sequence.
>> You may well have thought that. You were wrong. Do you understand
>> that now?
>
> "x *= ++f * ++f"
> int x = 5;
> int y = 3;
>
> For the calculation is question is seems to make no difference to the
> result.
> x = 5 * (4 * 5)
> x = 5 * (5 * 4)
So no, you don't understand. Do you want to?
I already quoted the wording from the ISO C++ standard (the document
that defines the language) that clearly states that the behavior
is undefined. I'm not trying to convince you that it should or
shouldn't be, I'm telling you that it is.
The specification that the behavior is undefined is not based on
examining some finite number of possible outcomes and determining
whether they all happen to be the same. The behavior is undefined
because the two modifications of f are unsequenced.
Apparently you don't believe me. I can't do anything about that.
There are valid reasons for the way it's currently defined.
You don't seem to care about those reasons.
I had already configured my newsreader to filter out anything
you post in this newsgroup, but you've changed your email address
yet again. I plan to update my filter soon.
(Anyone who takes olcott seriously is advised to take a look at his
posts in comp.theory.)
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@alumni.caltech.edu> |
|---|---|
| Date | 2024-06-21 23:42 -0400 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <v55h6q$3j17k$1@dont-email.me> |
| In reply to | #119482 |
On 6/21/24 7:06 PM, olcott wrote: ... > When we assume the *= assigns > the result of the RHS * the LHS to the LHS > "x *= ++f * ++f" > > means x = x * (++f * ++f) > thus cannot have implementation defined behavior. You are correct about that conclusion, though I don't see what your premise has to do with it. The expression ++f * ++f has, all by itself, undefined behavior, independent of what larger expression it might be part of. "implementation-defined behavior" is defined by the standard as "behavior, for a well-formed program construct and correct data, that depends on the implementation and that each implementation documents" (3.13). Since this program is not well formed, implementations have no obligation to document what it's behavior will be, so it cannot be implementation-defined behavior. Repeating what I said in an earlier message (with one minor correction): "Except where noted, evaluations of operands of individual operators and of subexpressions of individual expressions are unsequenced." (6.9.1p10) Both ++f expressions are sub-expressions of the multiplication expression. Thus, the executions are unsequenced, which is not, in itself, a problem. However, they both have a side effect on the same memory location, and that is a problem, because that same clause goes on to say: "If a side effect on a memory location (6.7.1) is unsequenced relative to either another side effect on the same memory location or a value computation using the value of any object in the same memory location, and they are not potentially concurrent (6.9.2), the behavior is undefined." These two expressions are not potentially concurrent: they are in the same expression, so they must be in the same thread, and if they are in a signal handler, they must both be in the same signal handler. Therefore, the expression ++f * ++f has undefined behavior.
[toc] | [prev] | [next] | [standalone]
| From | olcott <polcott333@gmail.com> |
|---|---|
| Date | 2024-06-21 23:02 -0500 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <v55ic7$3j9dh$2@dont-email.me> |
| In reply to | #119485 |
On 6/21/2024 10:42 PM, James Kuyper wrote: > On 6/21/24 7:06 PM, olcott wrote: > ... >> When we assume the *= assigns >> the result of the RHS * the LHS to the LHS >> "x *= ++f * ++f" >> >> means x = x * (++f * ++f) >> thus cannot have implementation defined behavior. > > You are correct about that conclusion, though I don't see what your > premise has to do with it. The expression ++f * ++f has, all by itself, > undefined behavior, It would seem to be naturally defined to be Left to right ++f from 2 to 3 ++f from 3 to 4 3 * 4 > independent of what larger expression it might be > part of. "implementation-defined behavior" is defined by the standard as > "behavior, for a well-formed program construct and correct data, that > depends on the implementation and that each implementation documents" > (3.13). Since this program is not well formed, implementations have no > obligation to document what it's behavior will be, so it cannot be > implementation-defined behavior. > > Repeating what I said in an earlier message (with one minor correction): > > "Except where noted, evaluations of operands of individual operators and > of subexpressions of individual expressions are unsequenced." (6.9.1p10) > > Both ++f expressions are sub-expressions of the multiplication > expression. Thus, the executions are unsequenced, which is not, in > itself, a problem. However, they both have a side effect on the same > memory location, and that is a problem, because that same clause goes on > to say: > > "If a side effect on a memory location (6.7.1) is unsequenced relative > to either another side effect on the same memory location or a value > computation using the value of any object in the same memory location, > and they are not potentially concurrent (6.9.2), the behavior is undefined." > > These two expressions are not potentially concurrent: they are in the > same expression, so they must be in the same thread, and if they are in > a signal handler, they must both be in the same signal handler. > Therefore, the expression ++f * ++f has undefined behavior. -- Copyright 2024 Olcott "Talent hits a target no one else can hit; Genius hits a target no one else can see." Arthur Schopenhauer
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2024-06-22 13:09 +0200 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <v56bdu$3no6g$1@dont-email.me> |
| In reply to | #119487 |
On 22/06/2024 06:02, olcott wrote: > On 6/21/2024 10:42 PM, James Kuyper wrote: >> On 6/21/24 7:06 PM, olcott wrote: >> ... >>> When we assume the *= assigns >>> the result of the RHS * the LHS to the LHS >>> "x *= ++f * ++f" >>> >>> means x = x * (++f * ++f) >>> thus cannot have implementation defined behavior. >> >> You are correct about that conclusion, though I don't see what your >> premise has to do with it. The expression ++f * ++f has, all by itself, >> undefined behavior, > > It would seem to be naturally defined to be Left to right > ++f from 2 to 3 > ++f from 3 to 4 > 3 * 4 > Some programming languages define the order of evaluation for subexpressions like this. Neither C nor C++ do (except for specific operators, which do not include multiplication). It doesn't really matter what you consider "natural" or not - it matters what the standards say.
[toc] | [prev] | [next] | [standalone]
| From | olcott <polcott333@gmail.com> |
|---|---|
| Date | 2024-06-22 07:40 -0500 |
| Subject | Re: is "x *= ++f * ++f" a valid statement ? PLO |
| Message-ID | <v56gn3$3olbi$2@dont-email.me> |
| In reply to | #119490 |
On 6/22/2024 6:09 AM, David Brown wrote: > On 22/06/2024 06:02, olcott wrote: >> On 6/21/2024 10:42 PM, James Kuyper wrote: >>> On 6/21/24 7:06 PM, olcott wrote: >>> ... >>>> When we assume the *= assigns >>>> the result of the RHS * the LHS to the LHS >>>> "x *= ++f * ++f" >>>> >>>> means x = x * (++f * ++f) >>>> thus cannot have implementation defined behavior. >>> >>> You are correct about that conclusion, though I don't see what your >>> premise has to do with it. The expression ++f * ++f has, all by itself, >>> undefined behavior, >> >> It would seem to be naturally defined to be Left to right >> ++f from 2 to 3 >> ++f from 3 to 4 >> 3 * 4 >> > > Some programming languages define the order of evaluation for > subexpressions like this. Neither C nor C++ do (except for specific > operators, which do not include multiplication). > > It doesn't really matter what you consider "natural" or not - it matters > what the standards say. > > It would be bad for the standards to be counter-intuitive. -- Copyright 2024 Olcott "Talent hits a target no one else can hit; Genius hits a target no one else can see." Arthur Schopenhauer
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.c++
csiph-web