NRK <n...@disroot.org> wrote:
> On Wed, Jan 05, 2022 at 01:56:26AM +0600, NRK wrote:
> > Just curious, why not use:
> > 
> > #if defined(__has_builtin) && __has_builtin(__builtin_expect)
> >     #define likely(expr) __builtin_expect(!!(expr), 1)
> >     #define unlikely(expr) __builtin_expect(!!(expr), 0)
> > #else
> >     #define likely(expr) (expr)
> >     #define unlikely(expr) (expr)
> > #endif
> 
> Answering my own question: because it fails if `__has_builtin` is not
> defined. I was expecting the 2nd expression wouldn't get evaluated at
> all. Should probably take some time and learn more about the
> pre-processor sometimes.

Same for me! I didn't know that the C pre-processor doesn't
short-circuit ...

Thanks for answering your own question! As you can see, it's
useful for others as well :)


Cheers,

Silvan

Reply via email to