Re: sizeof a union
- From: Jordan Abel <jmabel@xxxxxxxxxx>
- Date: Tue, 29 Nov 2005 19:34:46 +0000 (UTC)
On 2005-11-29, pemo <usenetmeister@xxxxxxxxx> wrote:
>
> "Mockey Chen" <mockey.chen@xxxxxxxxxx> wrote in message
> news:dmhr15$9l8$1@xxxxxxxxxxxxxxxxx
>> My friend ask me a question as following:
>>
>> give a union SU define as:
>> typedef union _SU
>> {
>> short x;
>> struct y{
>> char a;
>> short b;
>> char c;
>> };
>> }SU;
>>
>> what is the sizeof (SU)?
>>
>> My compiler tell me the answer is 6.
>> I want to know why the answer is 6.
>
>
> Why not add another member and use that to 'explore' the other members,
> e.g.,:
[snipped]
Out of curiosity, why is it impossible to add a 'flexible array' to a
union? The best solution to this IMO would be an "unsigned char data[];"
member.
.
- Follow-Ups:
- Re: sizeof a union
- From: Skarmander
- Re: sizeof a union
- References:
- Re: sizeof a union
- From: pemo
- Re: sizeof a union
- Prev by Date: Re: Read dynamic string
- Next by Date: Re: Read dynamic string
- Previous by thread: Re: sizeof a union
- Next by thread: Re: sizeof a union
- Index(es):
Relevant Pages
|