3 ms·
If the alternative is the coder having to write a separate "frob_notnull()" function, to be used specifically in certain fastpaths, then yes - that is exactly w
by caf 8y ago
If the alternative is the coder having to write a separate "frob_notnull()" function, to be used specifically in certain fastpaths, then yes - that is exactly what many people want from compiler optimisation.
- caf 8y agoI'd also point out that this is a strange optimisation to choose to pick on, because the only time it's potentially problematic is when a NULL pointer dereference doesn't necessarily trap, which certainly not the usual case on the platforms where common compilers enable it by default (and for the unusual cases, like kernels, the compiler option to disable it is there).
- jstimpfle 8y agoThat's true - see my other comment below the original one. I'd remembered that one from faint memory as one of the canonical examples of optimizations gone wrong. And think it might have been a case where that access comes AFTER a test. I don't really remember, though - and I've never had serious problems with optimizations myself.