Re: sizeof a union
- From: Skarmander <invalid@xxxxxxxxxxxxxx>
- Date: Tue, 29 Nov 2005 21:04:36 +0100
Jordan Abel wrote:
On 2005-11-29, pemo <usenetmeister@xxxxxxxxx> wrote:"Mockey Chen" <mockey.chen@xxxxxxxxxx> wrote in message news:dmhr15$9l8$1@xxxxxxxxxxxxxxxxxMy 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.
Because that's pointless. If you want that, cast the address of the thing to an unsigned char* and use that. Overloading flexible arrays for that isn't worth it.
S. .
- References:
- Re: sizeof a union
- From: pemo
- Re: sizeof a union
- From: Jordan Abel
- Re: sizeof a union
- Prev by Date: Re: strtok() and EOL
- Next by Date: Array size depending on symbol address
- Previous by thread: Re: sizeof a union
- Next by thread: Re: sizeof a union
- Index(es):
Relevant Pages
|