943,962 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 435
  • C RSS
Oct 6th, 2009
0

Structures And Unions

Expand Post »
Please someone help me regarding the differencec b/w Structures and Unions.I know the differnce in the memory management but what is itz advantage .Also why are unions specifically used in mouse programming and similar stuff..
Similar Threads
Reputation Points: 8
Solved Threads: 2
Junior Poster in Training
alvalany is offline Offline
61 posts
since Jul 2009
Oct 6th, 2009
-7
Re: Structures And Unions
unions are used whenever the same data can be represented in two or more ways, or by two or more data types. Normally I think unions are place inside structures, something like a VARIANT structure. This structure has two members, an integer that tells which of the union members are used, and then the union of 20 or so data types.

>>.Also why are unions specifically used in mouse programming
AFAIK unions are not used for that purpose because the program needs to know both the x and y coordinates of the mouse. A union would not provide that information.
Last edited by Ancient Dragon; Oct 6th, 2009 at 2:16 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Oct 6th, 2009
2
Re: Structures And Unions
Quote originally posted by Ancient Dragon ...
Normally I think unions are place inside structures
They can also be very helpful outside structures, for example in this snippet I made some time ago. [link]
I used it in the main scope as a structure inside of a union instead of the other way round. It helps when you want to assign values quickly. In fact, in the Pixel struct, i use a struct inside a union inside a struct
Last edited by William Hemsworth; Oct 6th, 2009 at 6:58 am.
Reputation Points: 1429
Solved Threads: 129
Posting Virtuoso
William Hemsworth is offline Offline
1,542 posts
since Mar 2008
Oct 27th, 2009
0
Re: Structures And Unions
Structures are used when you want to use every member of the structure at the same time
while in union only one of the member can be used

Union is very helpful in many cases where there are switch cases and we have to use only one of the members in our list
Reputation Points: 34
Solved Threads: 2
Light Poster
ankur_ is offline Offline
38 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Reverse Polish Notation
Next Thread in C Forum Timeline: How to make the output screen in C to stand for a long time.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC