May be it is another trap or pitfall of C. But at least, The compiler should give a warning to programmers.
May be it is another trap or pitfall of C. But at least, The compiler should give a warning to programmers.
I do not agree, this has nothing to do with C, this is an optimization issue and the standard says nothing about it. Plus this is a 'known' problem (or it should be): when you try to optimize (too much) some code, you're no longer ensured to get a correct result (except if you select carefully which optimizations you want and if you know what the optimizer will do). Nobody forces you to use the optimizer, this is a bonus (to use with caution).May be it is another trap or pitfall of C.
There is the -Wstrict-aliasing warning despite it does not help much in this case. Last versions of gcc surely have better support (-Wstrict-aliasing=2), but I didn't try.The compiler should give a warning to programmers.