4 ms·
It would be sane to ask that the literal expression "x - x" be optimised to 0, but I would never dream of asking that "y - x" be optimised to 0. Not unless the
by anon4 12y ago
It would be sane to ask that the literal expression "x - x" be optimised to 0, but I would never dream of asking that "y - x" be optimised to 0. Not unless the compiler can prove the values will be exactly the same in all circumstances and no, it's not allowed to just delete code that invokes undefined behaviour.
- pascal_cuoq 12y ago> no, it's not allowed to just delete code that invokes undefined behaviour. I think it is.
- cbd1984 12y ago> it's not allowed to just delete code that invokes undefined behaviour. In your mind, what does 'undefined behavior' mean? Because to the rest of us, it means "The standard says the compiler can do anything at all".
- TheLoneWolfling 12y agoI think he's also talking about my mythical C-like language that has somewhat sane rules for these things.
- cbd1984 12y ago> I think he's also talking about my mythical C-like language that has somewhat sane rules for these things. Oh, OK. It's important to realize, though, that if things get defined down too strictly, compilers will be hard-put to generate efficient code for more than one or two closely-related families of processors, which is important in a language designed to be useful for programming rather heterogeneous embedded systems (that is, more 'embedded' than ARM, perhaps with odd word sizes or similar).
- TheLoneWolfling 12y agoYep. Which is why I'm not taking about removing UB altogether, just talking about the more egregious examples of things that cause nasty bugs that aren't particularly problematic to code-gen. Not to mention that embedded systems end up using no optimization half the time anyways, because compilers go so overboard with performance that good luck trying to write safe code in them.