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

Where can unions and structures be used ?

Status
Not open for further replies.

naresh850

Full Member level 3
Joined
Jun 9, 2006
Messages
157
Helped
6
Reputation
12
Reaction score
4
Trophy points
1,298
Activity points
2,249
Hi,

Can anybody tall me where union can use and where structure can use with example.
 

vinseth

Member level 2
Joined
Jul 6, 2007
Messages
42
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,286
Activity points
1,463
where union can use

Structure is a method of packing data of different types. A structure is a convenient method of handling a group of related data items of different data types.
example:
struct lib_books
{
char title[20];
char author[15];
int pages;
float price;
};

Union:
Unions like structure contain members whose individual data types may differ from one another. However the members that compose a union all SHARE THE SAME STORAGE AREA within the computers memory where as each member within a structure is assigned its own unique storage area. They are useful for application involving multiple members. Where values need not be assigned to all the members at any one time.
 

naresh850

Full Member level 3
Joined
Jun 9, 2006
Messages
157
Helped
6
Reputation
12
Reaction score
4
Trophy points
1,298
Activity points
2,249
where union can use

con u give me the name of perticuler application for union use
 

7rots51

Advanced Member level 4
Joined
May 17, 2002
Messages
1,184
Helped
25
Reputation
50
Reaction score
12
Trophy points
1,318
Activity points
9,651
Re: where union can use

variables of same type can be defined in a structure.

Variables of different type that can share the same physical memory can be defined in union.
It is better to read some C text for more details.
 

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
where union can use

Just look in any header file from the Pic30 tools c compiler for a Pic30, Pic33, Pic24 micro.
Most ports or registers are defined as bit fields and also as ints.
You can clear a port by writing 0 to the int or set individual bits by using the bit fields.
They share memory.
Unions are also good when ram space is limited.
Beware though, they are not fully portable.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top