Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top