Afficher un message
Vieux 17/10/2007, 21h58   #6
Ben Bacarisse
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.
  Réponse avec citation
 
Page generated in 0,05718 seconds with 9 queries