Undoc'd Feature?
|
07-12-2022, 01:49 PM
(This post was last modified: 07-12-2022 01:50 PM by Wes Loewer.)
Post: #32
|
|||
|
|||
RE: Undoc'd Feature?
(07-11-2022 07:49 PM)ijabbott Wrote: Not really. For `i = i++ + 1;`, the `i++` part says that the old value of `i` plus 1 will be be stored in `i`, and the `i = i + 1` part also says that the old value of `i` plus 1 will be stored in `i`, so there is no conflict (in C++17, but undefined in C17). So are you saying that (i = i++ + 2) would also be undefined since it is ambiguous whether i gets incremented by 1 or by 2? My (perhaps flawed) understanding was that this is defined to follow the following sequence. Say i=5 to start. 1) i is evaluated to 5 2) 2 is added to 5 to get 7 3) i is incremented to 6 4) the value of 7 is stored in i Or maybe steps 2 and 3 might be reversed, but in either case, i ends up equaling 7, so compilers are free to ignore the ++. (07-11-2022 07:49 PM)ijabbott Wrote: (The other reason is that the storage to `i` by `i++` is unsequenced relative to the evaluation of `i` in the `... + i`.) I'm certainly no expert in these matters, but my understanding was that this is the only reason that (i = i++ + i) was undefined. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)