Re: snag of G_LIKELY()



On Sat, 2002-11-23 at 12:16, Daniel Elstner wrote:
> I'd prefer:
> 
> #define g_return_if_fail(expr) G_STMT_START{ \
>         gint value;                          \
>         if (expr)                            \
>           value = 0;                         \
>         else                                 \
>           value = 1;                         \
>         if (G_UNLIKELY (value))              \
>         {                                    \
>             g_log (G_LOG_DOMAIN,             \
>                  G_LOG_LEVEL_CRITICAL,       \
>                 "file %s: line %d (%s): assertion `%s' failed", \
>                 __FILE__,                                       \
>                 __LINE__,                                       \
>                 __PRETTY_FUNCTION__,                            \
>                 #expr);                                         \
>               return;                                           \
>         };                     }G_STMT_END
> 

And still hope for the compiler to generate equivalent code ? I have to
admit that I consider the warning on assignments to be of doubious
value. People who cannot trust themself to differentiate = and == are
probably better of to to use

#define EQUALS(a,b) ((a) == (b))

or even

#define g_return_if_not_equal(a,b) g_return_if_fail((a) == (b))

Matthias 




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