Re: Getting sizeof an anonymous struct declared inside a union
Harald van Dijk <truedfx@gmail.com> writes:
> On Wed, 17 Oct 2007 16:44:36 +0100, Ben Bacarisse wrote:
>> You can use a compound literal (new in C99) which won't actually 'make'
>> anything either:
>>
>> sizeof (union msg){{0,0}}.s2;
>>
>> but this requires you to know how to initialise a 'union msg' (so the
>> code changes if the structure changes)
>
> All object and incomplete types can be initialised to {0}, whether
> they're arrays, structures, unions, or scalars.
>
> sizeof (int) {0} ==
> sizeof (int)
> sizeof (int [2]) {0} ==
> sizeof (int [2])
> sizeof (union { struct { union { int m; } u; } s; }) {0} ==
> sizeof (union { struct { union { int m; } u; } s; })
Duh! I tried that, and concluded that the rules must be different for
compound literals, but it was just the compiler giving me a ful
warning.
--
Ben.
|