Undoc'd Feature?
|
07-17-2022, 01:05 PM
Post: #39
|
|||
|
|||
RE: Undoc'd Feature?
(07-10-2022 12:48 PM)RPNerd Wrote: Actually, no, it would yield 6 (store 5 in a and then increment a), which is possibly what the M$ compiler is doing. This is wrong, IMO, because the C/C++ standard clearly states that the result of an expression consisting of a post-incremented variable is the initial value of that variable. We are therefore totally justified in expecting "a = a++;" to assign to the variable a the value of the expression "a++", i.e.: the initial value of a. The evaluation should happen before the assignment. It does not seem to be an optimization issue. Even without optimizations turned on, the compiler gives the same results. Here's a simple, intentionally undefined example that indicates what each compiler is probably doing. Code: a = 5; gcc/clang/intel all print 5670 ms prints 5553 So gcc/clang/intel are evaluating then incrementing each time left to right, while MS doesn't process the three ++'s until after the = assignment. (07-14-2022 05:22 PM)ijabbott Wrote: This is ironic given that Microsoft proposed the new rules in the first place! See accepted paper P0145R3. Very ironic indeed. A good read though. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)