This comment, while adding detail, does nothing to improve upon the original statement, which was perfectly valid, and adds nothing to the discussion. This is irrelevant pedantry that a certain stripe of c pedant delights in bludgeoning the rest of us with.
quietbritishjim|7 years ago
If you still think this is all pedantry that can't happen in practice, here's an example where compilers are known to do strange things when the behaviour is undefined:
In this snippet of code, you might think that you're safe so long as you don't look at the return value of baz(). But in fact the optimiser may conclude that param must be zero (because anything else would be undefined behaviour), so baz() is always called with a parameter of zero even if bar has another argument. An problem very similar to this was discussed as a source of possible vulnerabilities in the Linux kernel [1] (although I don't know if any actual vulnerabilities were found).[1] https://lwn.net/Articles/575563/
throwaway713824|7 years ago
[deleted]
FartyMcFarter|7 years ago
gcc 8.2: https://godbolt.org/z/ZcsChr
clang 3.8: https://godbolt.org/z/pVDCPi
It looks like at least gcc disagrees that reading uninitialized variables is a way to find out what's in memory.
unknown|7 years ago
[deleted]