r/programming • • 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

61 comments sorted by

View all comments

Show parent comment

-2

u/Immediate-Food8050 Aug 22 '26

They are compiler extensions for C. I believe they are also compiler extensions in C++, not standard. but don't know for sure.

7

u/_Noreturn Aug 22 '26

they are standard in C++20, C doesn't have them as standard


if(cond) [[likely]] {

}