Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Question about unions (C language)

Status
Not open for further replies.

impakt

Member level 4
Joined
Dec 19, 2005
Messages
71
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,286
Activity points
1,816
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?
 

btbass

Advanced Member level 5
Joined
Jul 20, 2001
Messages
1,897
Helped
438
Reputation
880
Reaction score
287
Trophy points
1,363
Location
Oberon
Activity points
12,861
In this case it is the size of one pointer which can point to two different types.
 

Mansour_M

Advanced Member level 4
Joined
Jul 30, 2006
Messages
100
Helped
11
Reputation
22
Reaction score
3
Trophy points
1,298
Location
Newcastle, UK
Activity points
1,944
Hi Dear Friend!

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

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top