Re: snag of G_LIKELY()



Am Sam, 2002-11-23 um 02.15 schrieb Matthias Clasen:
> On Sat, 2002-11-23 at 01:56, Daniel Elstner wrote:
> > 
> > As for g_return_if_fail() and friends, I find Owen's idea to be quite
> > interesting.  Since G_LIKELY() requires gcc >= 3.0 anyway this shouldn't
> > be much of a problem, should it?
> 
> Ah, I didn't get Owen's idea at first reading (maybe because of the typo
> _g_tmp_conditional vs. _g_conditional). So the idea is to have

[...]

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

So that it works with g++ -- G_STMT_{START,END} are always #defined to
the do {} while(0) loop in C++.  However, I haven't verified that this
change doesn't have any impact on the generated code.

--Daniel





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