3 ms·
well, this would mean you'd get feedback every time you declare a variable without giving it an initial value? (even if the value is never read from before bein
by foxhill 12y ago
well, this would mean you'd get feedback every time you declare a variable without giving it an initial value? (even if the value is never read from before being written to - i.e is entirely safe to do?)
or how about when you write a for loop?
for(int i=0; i<LIMIT; i++)
..
the compiler assumes that i cannot overflow in this case, because that would be undefined behaviour. on the most obvious level, it doesn't need to do an overflow check on each loop iteration, if it exploits undefined behaviour. and no, it simply can't check the value of LIMIT before the loop, because i may be changed in the loop body, or LIMIT itself may change. this also allows a myriad of other loop optimisations. pipelining, vectorization, unrolling..
i don't think you realise just how often undefined behaviour is used in compiler optimisations.
- Kliment 12y agoYes, and having the compiler tell me these things would be welcome. I'm not saying I don't WANT those optimizations, I just want to be aware when they happen.
- foxhill 12y agofor even simple programs, this would produce a very large output. we've become accustomed to the idea that C is a low level language, but actually it's somewhat high level. optimisations are in your code everywhere, and if a C compiler were to list even only the ones that exploit undefined behaviour.. well, it would essentially be noise.