logoalt Hacker News

Everything in C is undefined behavior

382 pointsby lycopodiopsidatoday at 6:07 AM529 commentsview on HN

Comments

crackitoday at 7:10 AM

We know. This is not news.

show 1 reply
Webhixtoday at 1:04 PM

maybe rewrite this in go?)

NooneAtAll3today at 11:26 AM

feels like https://xkcd.com/1499/

the only people complaining about being able to do awful things are people that do awful things

show 1 reply
logicchainstoday at 7:10 AM

The concept of undefined behaviour is also a very useful lens for understanding LLM-based coding. Anything you don't explicitly specify is undefined behavior, so if you don't want the LLM to potentially pick a ridiculous implementation for some aspect of an application, make sure to explicitly specify how it should be implemented.

VimEscapeArtisttoday at 7:44 AM

Wait until he discovers PowerShell ;D

SanjayMehtatoday at 8:47 AM

I used to teach C programming and one time I got anonymous feedback: "when this instructor doesn't know the answer he says "it's compiler dependent.""

Shrug.

jraphtoday at 6:51 AM

Yet another push to use LLMs after casting fear. Now it should be illegal not to use LLMs. A good start of the day.

(I hope casting fear is not UB)

show 2 replies
EGregtoday at 3:03 PM

a good case can be made that use of C++ is a SOX violation

So Linus was right? But for a second reason too:

C++ is a horrible language. It’s made more horrible by the fact that a lot of substandard programmers use it, to the point where it’s much, much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do _nothing_ but keep the C++ programmers out, that in itself would be a huge reason to use C.

That is, accepting C++ code from programmers who use C++ could be a SOX violation ;-)

jdw64today at 6:56 AM

[dead]

ivandotcodestoday at 8:35 AM

[dead]

tenegotoday at 10:57 AM

[flagged]

rahadbhuiyatoday at 7:39 AM

[dead]

black_13today at 7:39 AM

[dead]

nurettintoday at 7:13 AM

[dead]

llggbbtttoday at 6:50 AM

[flagged]

nokeyatoday at 6:42 AM

Ok, and?

show 2 replies
stackghosttoday at 6:44 AM

Anyone who uses the construction "C/C++" doesn't write modern C++, and probably isn't very familiar with the recent revisions despite TFA's claims of writing it every day for decades.

Far from being just "C with classes", modern C++ is very different than C. The language is huge and complex, for sure, but nobody is forced to use all of it.

No HN comment can possibly cover all the use cases of C++ but in general, unless you have a very good reason not to:

- eschewing boomer loops in favor of ranges

- using RAII with smart pointers

- move semantics

- using STL containers instead of raw arrays

- borrowing using spans and string views

These things go a long way towards, shall we say, "safe-ish" code without UB. It is not memory-safe enforced at the language level, like Rust, but the upshot is you never need to deal with the Rust community :^)

show 7 replies
reinhashtoday at 8:42 AM

Rust.

grougnaxtoday at 7:44 AM

Use Rust!

liamd1988today at 7:10 AM

When use C ,keep using char* not mess with int*

momo26today at 7:03 AM

Debugging in C is soooo hard. When I was writing Malloc Lab in system course, there were uncountable undefined and out of range :(

show 1 reply
bullentoday at 11:03 AM

Everything in Java is defined behaviour, you need a VM with GC to remain sane.

Everything else is a waste of time!

ricardobeattoday at 10:23 AM

I’ve been heavily invested in https://c3-lang.org/ the past couple months. How does it look from this perspective to someone with C experience?