Undoc'd Feature?
|
07-31-2022, 02:12 AM
Post: #41
|
|||
|
|||
RE: Undoc'd Feature?
(07-17-2022 01:05 PM)Wes Loewer Wrote: ⋮ As an additional data point, I thought I’d try an Intel compiler (ICC 2021.5.0, optimizations on) on the following function: Code: int Wes2(int a) I got the following as output: Code: Wes2(int): I thought I’d also try the following, slightly different, function: Code: int Wes3(int &a) This slightly different function has the compiler producing the following, noticably distinct, output: Code: Wes3(int&): (Without optimization, for this last function, the compiler is producing code that increments three distinct temporaries by one and then assigning, as a final value for “a”, one of those three incremented-once temporaries, post increment.) When one goes rooting around with undefined behaviour, one can certainly feel the hidden contours of the magic machinery behind the scenes. That said, after seeing the above, I tried a few other similar functions and there does seem to be some issues with the Intel compiler’s handling of assignment operations post-C++17. (Even with a command-line option given to specify the version of C++ wanted.) |
|||
07-31-2022, 10:13 AM
Post: #42
|
|||
|
|||
RE: Undoc'd Feature?
(07-31-2022 01:29 AM)jte Wrote: When I try that function out with MSVC++ v14.28 / 1928 (x64), optimizations on, I get the following: How careless of me. I incorrectly assumed that the compiler would default to the latest standard. I see now that even the current 2022 MS compiler (19.32.31332 for x64) still defaults to c++14. Thanks for pointing that out. |
|||
07-31-2022, 06:43 PM
Post: #43
|
|||
|
|||
RE: Undoc'd Feature?
(07-31-2022 02:12 AM)jte Wrote: [quote='Wes Loewer' pid='162310' dateline='1658063144'] Just for fun, I installed my old MS Quick C 2.51 from 1990 in DOSBox. It produces 7650. |
|||
07-31-2022, 07:25 PM
Post: #44
|
|||
|
|||
RE: Undoc'd Feature?
(07-31-2022 06:43 PM)Wes Loewer Wrote:(07-31-2022 02:12 AM)jte Wrote: [quote='Wes Loewer' pid='162310' dateline='1658063144'] At least all the digits are right! Tom L Cui bono? |
|||
08-01-2022, 03:48 AM
Post: #45
|
|||
|
|||
RE: Undoc'd Feature?
(07-31-2022 07:25 PM)toml_12953 Wrote:(07-31-2022 06:43 PM)Wes Loewer Wrote: gcc/clang/intel all print 5670 Since the expression was undefined, evaluating left-to-right or right-to-left are equally valid, or perhaps equally invalid. :-) |
|||
08-03-2022, 08:17 PM
Post: #46
|
|||
|
|||
RE: Undoc'd Feature?
(07-03-2022 09:38 AM)toml_12953 Wrote: If it's not actually doing a decrement, it's an awfully big coincidence that it should still work the same, no? That was my first thought too. i tried to find out, if it is possible to get the result of 876 without calculating the first solution correctly, but every change of the code causes an incorrect result or an infinite loop. So I don't think, that this is possible or I'm missing something. Calculator Benchmark |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)