Re: [hackers] [libgrapheme] Mark likely branches || Laslo Hunhold

From: Silvan Jegen <s.jegen_AT_gmail.com>
Date: Tue, 04 Jan 2022 22:38:33 +0100

NRK <nrk_AT_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
Received on Tue Jan 04 2022 - 22:38:33 CET

This archive was generated by hypermail 2.3.0 : Wed Jan 05 2022 - 04:12:36 CET