top | item 44590639

(no title)

thasso | 7 months ago

A nice thing about C is that you can be pretty confident that you know all major footguns (assuming you spent some time reading about it). With languages that are young or complex there is a much greater chance you’re making a terrible mistake because you’re not aware of it.

discuss

order

tialaramex|7 months ago

It is nice that, unlike C++, the C language standard does list all the Undefined Behaviour (in Annex J.2), it's a pretty long list and IMO it's terrifying, not so much because of specifics like this:

"A searching or sorting utility function is called with an invalid pointer argument, even if the number of elements is zero"

But because of broad choices like:

"The execution of a program contains a data race"

"An object is referred to outside of its lifetime"

These are essentially categories of mistake we know programmers make, and in C the result is... Undefined Behaviour. No diagnostics, no exit, no errors, just throw your hands in the air and give up, anything might happen.

dwattttt|7 months ago

I'm yet to see someone be confident in this way on anything more than a trivial program, and be right. Just way too many footguns.

My personal memorable one was bit shifting 32bit values by varying amounts, and our test vectors all failing after a compiler update, because some of the shifts were by 32. Undefined behaviour.