Question about unions (C language)

Status
Not open for further replies.

impakt

Member level 4
Joined
Dec 19, 2005
Messages
68
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,286
Activity points
1,799
Hello all,
I have a question about unions. Suppose we have the following piece of code:

Code:
typedef struct {
                      ...
                     }type_struct1;

typedef struct {
                      ...
                     }type_struct2;

typedef union{
                    type_struct1* var1;
                    type_struct2* var2;
                    }type_union;
Hoe much memory is allocated for the union in this case?
 

In this case it is the size of one pointer which can point to two different types.
 

Hi Dear Friend!

Unions always occupies the space needed for the largest variable the have.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…