Skip to main content
9 events
when toggle format what by license comment
Nov 30, 2018 at 9:04 comment added Jot It only happens when x is zero and p is non-zero. When the 4294967295 is printed, the sizeof(result) is still 2.
Nov 29, 2018 at 23:06 comment added marcelm "In your opinion the compiler can insert code to whistle a tune when dividing by zero? I don't think so." - When you invoke Undefined Behaviour, everything goes, including unexpectedly large variables, tune whistling, or formatting your hard drive. Welcome to the wonderful world of C and C++. It would be interesting though to see if the same "variable promotion" occurs without UB.
Nov 29, 2018 at 16:38 history edited Jot CC BY-SA 4.0
added 123 characters in body
Nov 29, 2018 at 16:34 comment added Jot @EdgarBonet, thanks, interesting to read that. The things they mention are straightforward. What happens here is that runtime a certain function is called, and when the compiler optimizes it, a different (overloaded) function is called. That is one step further into weirdness.
Nov 29, 2018 at 11:56 comment added Edgar Bonet Although the compiler may not deliberately do silly things, strange things do happen when you invoke undefined behavior. See for example the beginning of this blog post (the whole post series is a must-read for any C or C++ programmer). Weird? Yes. Bug? No.
Nov 29, 2018 at 11:06 comment added Jot @EdgarBonet I think it should do whatever in the same way. In your opinion the compiler can insert code to whistle a tune when dividing by zero? I don't think so. Changing an int to unsigned long is too weird in my opinion.
Nov 29, 2018 at 8:33 comment added Edgar Bonet The handling of undefined behavior by the compiler is never a bug because, by definition, whatever the compiler does is acceptable per the language standard.
Nov 29, 2018 at 6:47 history edited Jot CC BY-SA 4.0
added 2 characters in body; added 15 characters in body
Nov 29, 2018 at 6:40 history answered Jot CC BY-SA 4.0