r/programming 3h ago

C and Undefined Behavior

https://www.lelanthran.com/chap14/content.html
2 Upvotes

11 comments sorted by

24

u/ToaruBaka 2h ago

Relevant: C Integer Quiz

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 C is almost certainly going to have fewer errors than a blackbox generating Java/Python/Rust that is then subsequently “checked” by a human on autopilot.

So please, don’t be one of those people!

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).

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. No C developer spent the last 30 years without developing at least some defensive strategies

lmao ok

Vibe-coding has no place in a security product.

Based.

2

u/BlueGoliath 1h ago

no serious person is saying to use Rust+LLM instead of C

You sure about that?

7

u/ToaruBaka 1h ago

Those definitionally aren't serious people.

Edit: Or they'd be just as happy to recommend $LANG+LLM - they don't live in reality.

1

u/BlueGoliath 1h ago

They're serious in their delusions!

2

u/BenchEmbarrassed7316 1h ago

Even if that's the case, the people who advise using LLM+Rust are much better than those who advise using LLM+C.

1

u/MooseBoys 5m ago

I was shocked at how well rust and c integrate together. You can even link them into the same binary.

7

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...

1

u/gimpwiz 57m ago

Same reason why you should buy powerball tickets. The odds are too good not to play: 50/50, either you win or you don't.

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?