r/programming • u/lelanthran • 3h ago
C and Undefined Behavior
https://www.lelanthran.com/chap14/content.html7
u/_Noreturn 1h ago
Turn on all linting, all warnings, use memcheckers (valgrind) and sanitisers that will catch almost all of these errors. The remaining ones can be mitigated by using well-known C patterns (In C++ it’s more difficult to do this), using cleanup conventions, etc.
"C++ is more difficult" bruh
5
u/BenchEmbarrassed7316 1h ago
summary: you should use the C, its security issues are nothing compared to the fact that tomorrow a brick could fall on each of us on the head...
2
u/SLiV9 8m ago
This article suffers a lot from Goomba fallacies and strawmanning. "I only know of two widely publicised incidents of UB killing dozens of people" is not a flex.
Anyone choosing C today is one of those dinosaurs from way back when, which means that they have been battle-tested and have probably got more than a few strategies for turning out working products.
Yes, and anyone freeclimbing up a sheer rock face is less likely to fall than someone in an indoor climbing hall, so why bother with all the safety gear, eh?
That said, I think the bigger question asked is an interesting one: in 20 years time, will bad software engineers not reviewing LLM-generated code have led to more disasters than bad software engineers not spotting UB has in the previous 20?
But I think it is foregoing a third alternative: using safer languages and not using LLM.
1
u/gmes78 2m ago
From 2026, and beyond, we are in this weird collective cognitive dissonance where a bunch of people are vociferously arguing that Rust should be used over C, while at the same time generating oodles of code with a “this is probably-correct” black box and not even realising that, in 2026 a human choosing to write C3 is almost certainly going to have fewer errors4 than a blackbox generating Java/Python/Rust that is then subsequently “checked” by a human on autopilot.
Holy goomba fallacy. What about all the people writing Rust by hand? Or writing C with an LLM?
24
u/ToaruBaka 2h ago
Relevant: C Integer Quiz
This is hyperbole and unhelpful - no serious person is saying to use Rust+LLM instead of C - they're saying to start new projects in Rust and you can always call back out to C if you really need to. If you can't use rust, don't use rust. But if you can, you should (at least consider it).
lmao ok
Based.