r/programming • u/chaobang • Aug 22 '26
The unlikely Linux macro
https://rushed-reflections.bearblog.dev/an-unlikely-experiment/Wrote a bit about the `unlikely` and `likely` macros in the Linux codebase. Great little exploration into tiny optimizations that everyone should know more about 😄
188
Upvotes
View all comments
Show parent comment
6
u/max123246 Aug 23 '26
On a large project like the Linux kernel, it helps a lot when the language does that work for you. Otherwise maintainers have to constantly be vigilant to tell people to stick to the 1 convention within that codebase.
I agree, I don't reach for C these days at all unless there's a codebase I need to work in that's already in C.
This isn't what the C++ standard says. They specifically say the moved-from object is a valid object, which means it should be safe to call any API on it. Yes, in practice, most code simply ignores what the C++ standard says and does the sensible thing, treat the moved-from object as not existing anymore. But you're now back in the world where your moved-from object just does arbitrary out of spec behavior and you kinda have to hack around it.
C has its faults but I appreciate that it doesn't claim to protect me against bugs when in fact, C++ just makes those bugs when they happen far more confusing to understand.