[lkml]   [2008]   [Sep]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH 5/5] debug: BUILD_BUG_ON: error on non-const expressions
>>> Boaz Harrosh <> 01.09.08 16:21 >>>
>> I have to admit that I'm surprise this compiles: You replace an expression
>> with a statement, and hence you reduce the places where BUILD_BUG_ON()
>> can validly be used.
>it is only an expression because of the (void)() cast, which is what
>I'm trying to avoid.

No, sizeof() alone is an expression, too. Also, by using a statement you'll
have more problems with fixing BUILD_BUG_ON_ZERO(), which must be
an expression.

>> Of course you could wrap the whole thing in ({}),
>"do{}while(0)" is effectively an "{}" plus the added bonus
>of demanding an ";" ;-)

An expression likewise demands a terminating ; (or a continuation of the
expression, i.e. by using an operator)

>> Also, are you sure the compiler will eliminate the dead variable in all
>> cases?
>> Finally, using as common a variable as 'x' here seems dangerous, too:
>> What if somewhere x is #define-d to something more complex than a
>> simple identifier?
>No it is scoped in a dead do{}while(0). What gets optimized out most
>is the do nothing do{}while(0). The inside is just ignored.

I don't think compilers in general and gcc in particular work this way
(i.e. automatically throwing away everything included in a dead block).


 \ /
  Last update: 2008-09-01 16:37    [W:0.056 / U:5.092 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site