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.
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.
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.
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.