News for hackers. Stuff that matters.
Re:Undefined behavior in C is a reading error by pif on Thursday May 20, 2021 @01:14PM (#27223970)
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.

Re:Undefined behavior in C is a reading error by masklinn on Thursday May 20, 2021 @03:06PM (#27225639)
> 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.

Re:Undefined behavior in C is a reading error by lmm on Thursday May 20, 2021 @09:10PM (#27229419)
Expecting 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.
Re:Undefined behavior in C is a reading error by TheCoelacanth on Thursday May 20, 2021 @09:59PM (#27229710)
The only programmers I would trust to write safe C are the ones who wouldn't trust themselves to write safe C.
Re:Undefined behavior in C is a reading error by cygx on Thursday May 20, 2021 @01:30PM (#27224221)
It'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...
Re:Undefined behavior in C is a reading error by pif on Thursday May 20, 2021 @02:29PM (#27225153)
> You first have to be aware of all the footguns,

Knowing your tools is part of being a professional. C is not for amateurs.

Re:Undefined behavior in C is a reading error by rurban on Thursday May 20, 2021 @04:14PM (#27226562)
Then 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.

Re:Undefined behavior in C is a reading error by saagarjha on Thursday May 20, 2021 @10:06PM (#27229747)
A true mark of a professional is being deathly terrified of the footguns that you must nevertheless use as tools.