Re: snag of G_LIKELY()



Am Sam, 2002-11-23 um 20.10 schrieb Owen Taylor:

>  - The g++ problem can be fixed with __extension__; wen
>    already rely on statement expressions working for G++
>    in libgobject. (The info page for gcc does suggest
>    not using statement expressions with g++, but if they
>    break them, we'll need a new release of glib anyways)

OK.
 
> ===
> #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
> #define _G_BOOLEAN_EXPR(expr)                   \
>  __extension__ ({                               \
>    int _g_boolean_var_;                         \
>    if (expr)                                    \
>       _g_boolean_var_ = 1;                      \
>    else                                         \
>       _g_boolean_var_ = 0;                      \
>    _g_boolean_var_;                             \
> })
> #define G_LIKELY(expr) __builtin_expect (_G_BOOLEAN_EXPR(expr), 1)
> #define G_UNLIKELY(expr) __builtin_expect (_G_BOOLEAN_EXPR(expr), 0)
> #else
> #define G_LIKELY(expr) expr
> #define G_UNLIKELY(expr) expr
> #endif
> ====

Seems fine to me.

--Daniel





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]