3 ms·
Those who complain about UB should first master asm programming with microcontroller and some modern architecture. Maybe then they'd understand the cost better
by vardump 11y ago
Those who complain about UB should first master asm programming with microcontroller and some modern architecture.
Maybe then they'd understand the cost better.
Compilers should generate warnings on all compile time UB and maybe even do data flow analysis for possible runtime UB.
Although, IMHO, code with a reference to block scope uninitialized variable shouldn't even compile.
- Someone 11y agoIt can be hard or even impossible to prove that a variable gets read before it gets written to. People who want to get every last bit of performance out of their systems do want to write code like: int x; ... if(condition1) x = expression1; ... while(expression2) { x = DoSomethingWith(x); } where the intelligent reader knows things are fine, but a compiler has a hard time proving it. For example, a contract implicit in an API may enforce the invariant, but that cannot be deduced from the code.
- cyphar 11y ago> Although, IMHO, code with a reference to block scope uninitialized variable shouldn't even compile. Funny story, that is actually what caused Debian's weak keys fiasco. The code was using uninitialised memory to seed the PRNG and someone removed it because of valgrind warnings. So sometimes UB is exactly what you want. :P