Re: g_return_if_fail() breakage



> From: Daniel Elstner <daniel elstner gmx net>
>
> Am Die, 2002-11-26 um 17.32 schrieb Tim Janik:
> > On 26 Nov 2002, Matthias Clasen wrote:
> > 
> > > On Tue, 2002-11-26 at 02:40, Daniel Elstner wrote:
> > >
> > > > To fix this either g_return_if_fail() or G_LIKELY() should add parens.
> > > > The latter is probably the safest option, even though we'd definitely
> > > > lose the warning feature with -O0 or other compilers than GCC.
> > >
> > > Already fixed in CVS, thanks to our alert build sheriff Dan Mills.
> > 
> > adding parens is not a good idea, because of loosing compiler checks
> > for x=5 instead of x==5 that way.
> > a better fix is if (G_LIKELY (expr)) ; else g_log (...
> > and not having G_LIKELY/G_UNLIKELY add extra parens.
>
> Right, it'd work fine for g_return_if_fail().  But G_[UN]LIKELY() are
> public API and I'm sure most people won't expect breakage if they write
>
>     if(!G_LIKELY(foo || bar)) ...
>
> If the parens are going to be removed this should be documented.  With a
> big red warning sign.

Perhaps _G_LIKELY_PRIVATE() without parens, and use it to implement both
g_return_if_fail() and G_LIKELY()?

Ron



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