2 ms·
So fix it to the extent possible. Eg, this: https://t.co/Z1Ib2fIyu6 https://t.co/Z1Ib2fIyu6 Is easily fixable. A. static Function Do; -- This is a syntax erro
by dale_glass 3y ago
So fix it to the extent possible. Eg, this: https://t.co/Z1Ib2fIyu6 https://t.co/Z1Ib2fIyu6
Is easily fixable.
A. static Function Do; -- This is a syntax error, initialization is mandatory.
B. It's initialized to nullptr, and compiled to jmp 0x0
- layer8 3y agoYes, you can fix it in some cases, but the real errors usually happen in complex code where it is much harder or impossible to detect at compile time. The examples in TFA are very simplified for exposition purposes, they are not representative of ease-of-detection.
- dale_glass 3y agoI don't see how this particular case could ever be hard to deal with. Using uninitialized memory is UB, so initialize every byte of memory allocated to NULL. Dereference NULL pointers as-is. Done. I'd be quite happy with a best effort approach. If you can't be perfect in every case, at least handle the low handling fruit.
- layer8 3y agoThis approach would also impact UB-free code that initializes the memory later. C compilers don’t want to pessimize such code. The difficulty lies in identifying only code with actual UB.
- dale_glass 3y agoThat's perfectly fine with me. If the compiler can prove the code is initialized twice, then it's free to deduplicate it. Otherwise I'll happily eat the cost and preserve more of my sanity when debugging.
- layer8 3y agoYou’ll happily eat the cost, but the target audience of C compilers traditionally doesn’t. That’s the point made by TFA. C prioritizes performance over safety.