Undoc'd Feature?
|
07-08-2022, 08:32 PM
(This post was last modified: 07-08-2022 08:42 PM by jte.)
Post: #20
|
|||
|
|||
RE: Undoc'd Feature?
(07-08-2022 05:00 AM)Wes Loewer Wrote: ⋮ A+ In theory, some of the numbered steps could be broken down into smaller pieces when machine code is being generated (e.g., if an integer was larger than the architecture’s register size [such as 32-bit ints on a 16-bit CPU or 64-bit “long long” integers on a 32-bit CPU]); these smaller steps could be interleaved by the compiler (maybe assign half of an integer, do an increment on a lower half, do a carry into the upper half, assign the other half of an integer). (Or… if we reach even further into theoretical possibilities: perhaps the machine code for a routine has all machine registers fully employed and the compiler doesn’t want to use a register simply to hold a “1” and knows that two registers always differ by 1 [and the architecture doesn’t have an increment instruction the compiler likes… how far can we reach? ], it could use those two registers to effect a ++ with something like “+=5” and a “-=4”… and then slap the assignment given in the source code right in the middle of that.) This topic always reminds me of a disagreement I had, as an undergraduate, with another undergraduate (around 30 years ago, now!), over the validity of xor-swapping with chained xor-assignment (“a ^= b ^= a ^= b”) in C — my point being that the lack of sequence points had such code also veering into undefined behaviour. (Values are being used before they are known to have settled post-assignment.) Funnily enough, when I mentioned this to my daughter when we went running yesterday, I noted that ”the other undergraduate” need only have waited 30 years for me to be more convinced of his argument, as C++17 introduces additional sequencing constraints involving assignment operators. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)