4 ms·
Unspecified result means the compiler must think about what could happen in case I made an error. UB means the compiler will trust me and concentrate on genera
by pif 5y ago
Unspecified result means the compiler must think about what could happen in case I made an error.
UB means the compiler will trust me and concentrate on generate the fastest code ever.
C is for clever programmers; if you don't want to be clever, you are free to use Go or something like that.
- cygx 5y agoIt's not so much about cleverness, but knowledge and vigilance. You first have to be aware of all the footguns, and then be careful not to let any of them slip through...
- pif 5y ago> You first have to be aware of all the footguns, Knowing your tools is part of being a professional. C is not for amateurs.
- rurban 5y agoThen use such a tool, but don't call it C, rather -std=gnuc-opt11, which always knows better than the author, without any warning. Call it randomC, unsuitable for professional programmers, but extremly suitable for benchmark games and managers. Who prefer to ignore pesty overflows, underflows, memset, memcpy, dereferencing NULL pointers and other rare cases.
- saagarjha 5y agoA true mark of a professional is being deathly terrified of the footguns that you must nevertheless use as tools.
- masklinn 5y ago> UB means the compiler will trust me and concentrate on generate the fastest code ever. In reality, UB means the compiler will assume it doesn't happen and work from there. Of course a more expressive language could just make it so the compiler doesn't have to assume this e.g. a C compiler will consider a dereference as meaning the pointer is non-null, both backwards and forwards. But if the language had non-null pointers, it would not need to bother with that, it would have a non-null pointer in the first place. It could still optimise nullable pointers (aka lower nullable pointers to non-nullable if they're provably non-nullable, usually after a few rounds of inlining), but that would be a much lower priority.
- lmm 5y agoExpecting programmers to evaluate their own cleverness does not work. Every nontrivial C program has undefined behaviour, making it a security flaw waiting to happen - I've been in these kind of debates where a C advocate will claim that program X is correct, and literally every time it turns out that program X has undefined behaviour somewhere.
- TheCoelacanth 5y agoThe only programmers I would trust to write safe C are the ones who wouldn't trust themselves to write safe C.