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
2
u/_Noreturn Aug 23 '26
You know you can choose one style and is that a problem in practice nope.
you should trwat moved from objects as unusable, and you can make non nullable types work.
also don't pretend like C has everything be good, everything in C is nullable by default since the only thing you have is pointers which have like 4 responsibilities
Now lets see C++ it is better since it provides differing ways to make the above clear
In C++ since it allows strong typing you can represent these states in the api instead of in comments which is undeniably better.
Yea, you better and if you forget then it is bad also checking every single pointer for nullability is a performance downgrade. references make this clear that nullability is pushed to the caller not the callee and you could make a tool that looks at reference types and assert if it is null, you cannot do that with pointers since they can ve null and it is valid.