[Mesa-dev] [PATCH] util/u_atomic: use STATIC_ASSERT() when selecting the appropriate function
Emil Velikov
emil.l.velikov at gmail.com
Wed May 13 14:50:52 PDT 2015
On 13 May 2015 at 21:01, Brian Paul <brianp at vmware.com> wrote:
> On 05/13/2015 01:18 PM, Francisco Jerez wrote:
>>
>> Emil Velikov <emil.l.velikov at gmail.com> writes:
>>
>>> As we evaluate sizeof() at compile time, having the run-time assert()
>>> does not provide any benefits. Move to the compile-time version
>>> STATIC_ASSERT() which will kindly prompt us when this go wrong.
>>>
>>
>> This doesn't look right. AFAIK STATIC_ASSERT() is implemented by
>> expanding to an array type-id of negative size, which is an error
>> regardless of whether the sizeof expression is evaluated or not: i.e.
>> "0 ? sizeof(invalid) : ..." is still an error for the same reason that
>> "0 * sizeof(invalid)" or "(void)sizeof(invalid)" is an error. That and
>> also that the whole thing is wrapped in a do-while loop you cannot use
>> as operand of the ternary operator...
>
>
> Yeah, this does not build with MSVC:
>
> C:\Users\Brian\projects\mesa\src\gallium\auxiliary\util/u_inlines.h(83) :
> error C2059: syntax error : 'do'
> C:\Users\Brian\projects\mesa\src\gallium\auxiliary\util/u_inlines.h(83) :
> error C2143: syntax error : missing ';' before ','
> C:\Users\Brian\projects\mesa\src\gallium\auxiliary\util/u_inlines.h(83) :
> error C2059: syntax error : ')'
> C:\Users\Brian\projects\mesa\src\gallium\auxiliary\util/u_inlines.h(89) :
> error C2059: syntax error : 'do'
> [...]
>
This one goes straight into the bitbin. Thanks for the explanation
Francisco and test Brian.
-Emil
More information about the mesa-dev
mailing list