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.

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.
 

where union can use

Take a look


I don't want to repeat myself.
Cheers.
 

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.
 

where union can use

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

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.
 

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.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top