Previous in Forum: Free - secure- remote access that works great.   Next in Forum: RS 422 Not Talking
Close
Close
Close
Rate Comments: Nested
Associate

Join Date: Jun 2007
Posts: 26

How structure and unions applied in real world?

02/14/2010 9:58 AM

Hi all,

I (Manas Sinha) being a lecturer in piet,rkl-770034,want to know how these concept of structure and unions in C/C++ languages applied in real or practical world..... if anybody gets some application of this concepts of software, mail me back.....

thanks in adv.

Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Guru

Join Date: Dec 2009
Posts: 581
Good Answers: 15
#1

Re: How structure and unions applied in real world?

02/16/2010 11:05 AM

The better question is, where are they not used? Relatively few numbers exist on their own: loop indexes, counters, universal constants, local constants. Except for loop indexes, all these constants should be given descriptive names - the use of "magic numbers" in source code is rightfully discouraged.

Structures provide the relationships between or organization of data items. Every data file, for example, is organized into a data structure(s). (Otherwise, how can a program make use of the data?) In fact, the whole drive/storage medium is structured.

Another easy example is time. Any given point in time has century, year, day, day of week, hours, minutes, microseconds, etc., depending on your accuracy requirement.

Unions are trickier. A union changes the interpretation of a data item. It was an int, now it's a char, in the future it'll be an int again. One very handy use of a union is to create a union of many different pointer types. Being pointers, they all occupy the same size (a memory address), and all have the same value (though bounding constraints might cause issues), but by incrementing different members of the union one can smoothly parse a serialized data stream into... a structure that makes sense of the otherwise anonymous data.

__________________
Ignorance is no sin. Willful ignorance is unforgiveable.
Register to Reply
Register to Reply

Previous in Forum: Free - secure- remote access that works great.   Next in Forum: RS 422 Not Talking

Advertisement