Re: [Widelands-public] Problems with union Owner_Info
Status: Beta
Brought to you by:
sirver
From: Erik <fr...@ho...> - 2006-09-21 15:43:39
|
Christoph Mallon wrote: > Erik wrote: > >> Christoph Mallon wrote: >> >>> Erik wrote: >>> >>> >>>> Christoph Mallon wrote: >>>> >>>> >>>>> add a compile time assert to verify that the size of the struct is 1. >>>>> >>>>> >>>>> >>>> What do you expect a compile time assert in C++ to look like? Would >>>> something like this hack please you?: >>>> #define UMP_META_ASSERT(const_expr) typedef bool >>>> Meta_Assertion[(const_expr) ? 1 : -1] >>>> >>>> >>> This looks ok to me. >>> Though i would use extern int instead of a typedef, because in C a >>> typedef must be declared at most once. (Yes, i know, there is no C in >>> Widelands, but this change costs nothing) >>> >> I tried do "extern int COMPILE_ASSERT" and it fails as it should when >> the argument is false. But it also fails when the argument is true: >> error: storage class specified for 'COMPILE_ASSERT' >> So I have to use typedef bool COMPILE_ASSERT. It works as intended. >> > Please show exactly what you're doing and don't try to describe it. > #define compile_assert(x) extern int COMPILE_ASSERT[(x) ? 1 : -1] struct F { compile_assert(true); }; g++ says: fel: storage class specified for "COMPILE_ASSERT" #define compile_assert(x) typedef bool COMPILE_ASSERT[(x) ? 1 : -1] struct F { compile_assert(true); }; g++ says nothing Your suggestion does not allow compile_assert inside struct declarations, which is what I want. |