Victor Yodaiken
yodaiken.com · Personal blog · on HN since 2016
Victor Yodaiken is a computer scientist who writes about C undefined behavior, aliasing rules, and the C standard.
What HN saysCommenters cite his argument that compiler writers misread undefined behavior as license to do anything, and note that Linus Torvalds and others share the view.
34HN people shared it
17linked it in comments
45stories submitted
1.1Kstory points
9 months agolast shared
2016people per year2026
Most-shared posts
- 1Linus Torvalds on aliasing7 people · 150 points · first shared 2018 · 269 comments on HN
- 2Undefined behavior in C is a reading error5 people · 239 points · first shared 2021 · 491 comments on HN
- 3C Standard Undefined Behavior vs. Wittgenstein [pdf]4 people · 17 points · first shared 2018 · 2 comments on HN
- 4Dennis Ritchie on alias analysis in C (1988)3 people · 63 points · first shared 2021 · 11 comments on HN
- 5Synchronous Processors (2016)3 people · 33 points · first shared 2018 · 19 comments on HN
- 6The C standard versus C and the mother of all hacks3 people · 10 points · first shared 2017 · discussion on HN
- 7Depressing and faintly terrifying days for the C standard [pdf]2 people · 209 points · first shared 2018 · 270 comments on HN
- 8Von Neumann’s critique of automata theory and logic in computer science (1947)2 people · 141 points · first shared 2019 · 31 comments on HN
- 9Undefined Behavior and the Purpose of C2 people · 5 points · first shared 2019 · discussion on HN
- 10Undefined behavior and purpose of C language2 people · 4 points · first shared 2017 · discussion on HN
- 11Computer Sciences as a Scholarly Discipline and Functional Programming2 people · 3 points · first shared 2016 · discussion on HN
- 12Three proposals for the C standard WG141 people · 72 points · first shared 2018 · 118 comments on HN
- 13PLOS2021: ISO-C became unusable for operating systems1 people · 57 points · first shared 2021 · 95 comments on HN
- 14On C-optimizing compilers removing code that has undefined behavior1 people · 40 points · first shared 2017 · 62 comments on HN
- 15Possibly Fun C Code1 people · 29 points · first shared 2022 · 6 comments on HN
What HN people wrote when they linked it
platinumrad · 2018-06-05
The standard massively conflicts with the practices used in existing C programs by existing C programmers. Yes, it's perfectly possible to write code that doesn't violate any of the (largely implicit, it's worth noting) strict-aliasing rules. But was it a good idea for the standard to allow optimizing compilers to silently break massive amounts of existing code that has worked for years? Even if that were acceptable, was it a good idea for the standard to disallow one of the more ergonomic and explicit ways (using a union) of reinterpreting an object as an object of a different type?
Some good reads on this topic:
https://blog.regehr.org/archives/1307
http://www.yodaiken.com/2018/05/20/depressing-and-faintly-terrifying-d…
https://blog.regehr.org/archives/903 (See the end of Xavier Leroy's comment)
vlovich123 · 2021-07-09
All I can do is point out that very big names in CS (including Linus) disagree with you: http://www.yodaiken.com/wp-content/uploads/2018/05/ub-1.pdf
This is probably because they’ve seen the effects of the foot gun first hand. They also recall what C/C++ looked like before the standards bodies made exploiting UB in compilers open season. There’s also a reason why Rust doesn’t have any UB in its safe dialect even though it sits on infrastructure capable of most/all the same possible optimizations via LLVM.
There was in fact a direct kernel security issue UB exploitation caused in the Linux kernel whereas without that optimization there is no security issue. if I recall correctly the code looked something like:
Some_value = ptr->value
If (!ptr) { return; }
This worked correctly in all cases before the compiler added the optimization. It worked less well after because the !ptr check was UB since it followed a dereference. It also wasn’t immediately obvious this code was broken because there was no diagnostic nor any indication that upgrading a compiler would suddenly elide the check. The value-add of such optimizations at scale vs the correctness issues exploiting it causes is questionable.
The problem wasn’t that it’s not fixable. It’s that it takes time to find and you may not even find it until after it’s being exploited.
Animats · 2016-10-02
Some of those are classics. The Lipton-Perlis-DeMillo argument against program verification is a good one.[1] They demonstrated that manual programming verification via hand theorem proving is buggy. Automated theorem proving was new back then.
This was an issue back in the 80s for a philosophical reason in mathematics. Mathematics classically approves of short, clever, elegant proofs. The paper-and-pencil crowd was trying to do that for code. In practice, program verification is about mechanized grinding through massive numbers of dumb assertions to catch off-by-one errors.
This used to bother mathematicians. When the four-color theorem was originally proved, it was done partly by hand and partly with computer case analysis. The computer part bothered many mathematicians. The culture has changed. Recently, someone redid the proof with the old hand parts re-done by computer. Since that eliminated some possible human errors, that was a step forward in solidifying the proof.
We also know now how to check a theorem prover. Some theorem provers emit a proof trace, huge files of "Step 2437: apply rule 42 to change 2*X to X+X". Proof traces can be fed into a dumb proof checker which does the indicated rewrite and checks that the expected output is obtained.
So progress has resolved that issue.
[1] http://www.yodaiken.com/papers/p271-de_millo.pdf
zephen · 2026-02-17
Here's a cogent argument that any decision by compiler writers that they can do whatever they wish whenever they encounter an "undefined behavior" construct is rubbish:
https://www.yodaiken.com/2021/05/19/undefined-behavior-in-c-is-a-readi…
And here's a cautionary tale of how a compiler writer doing whatever they wish once they encounter undefined behavior makes debugging intractable:
https://www.quora.com/What-is-the-most-subtle-bug-you-have-had-to-fix-…
matheusmoreira · 2025-04-25
Reminds me of strict aliasing. Same attitude...
https://www.yodaiken.com/2018/06/07/torvalds-on-aliasing/
davidgerard · 2021-10-06
10000truths · 2021-08-01
Type punning/aliasing with unions is well defined in gcc. Linus even has a humorous rant about it on the topic:
https://www.yodaiken.com/2018/06/07/torvalds-on-aliasing/
Sure, it's compiler-specific, but I'm already using `__attribute__((packed))` anyways.
fierro · 2021-04-07
truly ahead of his time
https://www.yodaiken.com/2019/02/20/von-neumanns-critique-of-automata-…
dundarious · 2021-03-20
I was grateful for this context in the introduction, even if I was already familiar with Torvalds and Regehr's comments. The introduction is extremely light, but I don't think it amounts to "blogspam", and if the implication is that your direct link should be substituted, I disagree.
> For further reading try Linus Torvalds[1] (pre-nice) note, John Regehr’s paper[2] on alias and this proposal[3] for the C 2x standard.
[1] https://www.yodaiken.com/2018/06/07/torvalds-on-aliasing/
[2] https://blog.regehr.org/archives/1307
[3] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2577.pdf
__s · 2020-04-18
-fno-strict-aliasing: https://stackoverflow.com/questions/98650/what-is-the-strict-aliasing-…
Torvalds rant: https://www.yodaiken.com/2018/06/07/torvalds-on-aliasing
edit: I misread the parent as wondering about a compiler flag
ahelwer · 2019-09-01
This is authentically a very interesting simulation and I would be interesting to see a writeup if you have one. I will say that you only have multiple proposers if the proposers cannot talk to one another, as otherwise they would be silenced by any simple leader election protocol (heartbeats + node rank, etc.) It's true that the leader election protocol is not part of paxos per se but all implementations will have one, and the protocol livelocks in the unusual case where there's an enduring network partition and the multiple proposers are sending messages with specific timing.
Edit: I took a look at your post[0] and it is interesting. I'll take a look at CM.
[0] https://www.yodaiken.com/papers-and-talks/distributed-consensus-paxos-…
Sarki · 2018-06-13
Relevant comment by Linus Torvalds on standards:
"I've said this before, and I'll say it again: a standards paper is
just so much toilet paper when it conflicts with reality. It has
absolutely _zero_ relevance. In fact, I'll take real toilet paper over
standards any day, because at least that way I won't have splinters
and ink up my arse."
http://www.yodaiken.com/2018/06/07/torvalds-on-aliasing/
justboxing · 2018-05-30
Direct link to PDF: http://www.yodaiken.com/wp-content/uploads/2018/05/ub-1.pdf
kazinator · 2017-08-18
Running Linux under something lower level is old hat, see RTLinux:
http://www.yodaiken.com/papers/BarabanovThesis.pdf [1997]
Well, that's not exactly a microkernel, but took lots of inspiration from microkernels.
I take it that you may be alluding to the debate between Torvalds and Tannenbaum regarding microkernels.
https://en.wikipedia.org/wiki/Tanenbaum%E2%80%93Torvalds_debate
trealira · 2023-12-19
Yeah, I think a degree of complexity is required to achieve being the fastest compiled language.
To achieve that, you need stuff like monomorphized templates, actual arrays and slices being distinguished from pointers, well-defined rules on pointers (like Rust's rules about references and mutable references, or strict aliasing in C++), and the freedom to let the compiler reorder structure fields for better alignment and space usage. Runtime polymorphism, like virtual functions in C++, are better as a core language feature rather than something implemented as a struct of function pointers, because that way the compiler can devirtualize some calls.
All of these things, I think most C programmers would be against adding to C. And pointer rules are historically controversial; for example, Dennis Ritchie was against adding noalias to C in 1988[1].
[1]: https://www.yodaiken.com/2021/03/19/dennis-ritchie-on-alias-analysis-i…
quietbritishjim · 2021-03-22
[Edit: this isn't true] That is definitely how it is used, and it works on the major compilers. But, surprisingly, this is indeed undefined behaviour according to the standard. There was an infamous rant by Linus [1] (more infamous for the language than the subject) about how the kernel can and should continue to use unions for type punning. He noted that even though the C standard doesn't specify a behaviour for that usage, gcc does (so long as you don't use a particular compiler switch mentioned in that discussion), and went on to say "The standard simply is not important, when it is in direct conflict with reality and reliable code generation."
EDIT: Having looked into this more I think I was getting confused with C++ (where the only supported way to type pun is to use memcpy or similar, which despite the name might not have to actually copy the bytes at runtime). Here [2] is a StackOverflow answer (/discussion) on the matter.
[1] https://www.yodaiken.com/2018/06/07/torvalds-on-aliasing/
[2] https://stackoverflow.com/questions/25664848/unions-and-type-punning