Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No one has written a C program of any complexity with zero undefined behavior. Noting its existence as if it's some kind of revelation is trite and annoying.


Yeah there's a whole genre of talks, blog posts, online rants of the form:

"So you think you know C, huh? What does this horrible piece of code do that no one would ever write and if you see it should be nuked from orbit? <ridiculous contrived example>"

I just clicked I don't know on all of em, cause I realised what the metagame was from a mile away.

Some of these things are at least a little insightful, but overall, kind of a waste of time past a certain point, unless you work on a compiler or something like that. Much more constructive would be making resources on best practices for things like memory management, string handling, knowing where the footguns are in the stdlib and other common libs, managing complexity etc. Most bad C code isn't because of some standards gotcha, it's because of those things.


Except there is some very crazy code out there, and if you come across it and took at least one such quiz, you know you'll have to be careful.


Oh yeah, I've seen some shit, having done a fair bit of professional C work, mostly in the embed space.

But if I'm in an existing codebase, and I see a certain volume of this kind of "potential UB everywhere" code, my first instinct isn't let's spend however long trying to understand what exactly this code may or may not be doing/relying on according to dusty corners of the standard and the datasheet(sometimes you may have to, but I find it's rare). I prefer to approach it as "what is this code supposed to do, and how can it be done more sanely? Usually I find I can replace the crazy code with sane code in a fraction of the time it would take to fully understand the crazy code.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: