Re: sizeof a union



pemo wrote:

<snip why is the size of a struct

Why not add another member and use that to 'explore' the other members,

Any results are highly implementation specific, of course.

e.g.,:

#include <stdio.h>

typedef union
{
    int x;

    struct
    {
            int a;
            int b;

<snip>

int main(void)
{
    SU a;

printf("x = \t%p\n", &a.x);

If using %p you should cast the pointer to void* printf("x = \t%p\n", (void*)&a.x);

printf("y.a = \t%p\n", &a.y.a);

Also, for this sort of thing using the offsetof macro from stddef.h would be more useful.


<snip>
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
.



Relevant Pages