Is Union Still Relevant in Programming Today?

  • Thread starter Thread starter Pattielli
  • Start date Start date
  • Tags Tags
    Union
AI Thread Summary
The discussion centers on the relevance and usage of unions in programming today, particularly in the context of C and C++. While some participants acknowledge that unions are not frequently used in modern programming, they highlight their memory-saving advantages, as unions allocate memory only for the largest member, unlike structs. The conversation reflects on the potential benefits of unions, suggesting that they can be useful in specific scenarios despite their limitations, such as only allowing one member to be used at a time. Participants express a desire to understand how to effectively leverage unions and explore additional insights beyond what has been presented in existing literature, particularly referencing Andrei's work. Overall, there is a shared interest in learning more about unions and their practical applications in programming.
Pattielli
Messages
296
Reaction score
0
Would you please tell me how "popular" it is today ? I mean if you are still using it in programming or not, since I have heard from many friends of mine that they don't use it at all, even once...So, how about you ? Your ideas are all appreciated, and thank you very much for your help..:sm:
 
Computer science news on Phys.org
I've never had a case where I truly needed to use a union, although I could have if i wanted to. The place you'd want to use a union is when you want to save on memory. The union only allocates enough memory for the largest member. Structs on the other hand allocate memory for the total size ocuppied by every member. The only bad thing about the union is that you can only use one member at a time.
 
Thank you, I guess there are a lot of people here coming from C background :sm:
I made this question to ask them if they are still using it as one of the tools included to their making some applications...My background is not originally from informatics, I started learning computer programming also from C and now moving towards C++, i know only a little about both because I actually have no much time to handle them all...I used to be told some things about union too, that it is not oftenly used anymore but since it is also has its own special features which you already mentioned above, it could be exploited to get fitted in some cases... So the problem is how can we take advantage of its bad effects and turn them all into good ones...That is my main idea when creating this thread...

I have tried my best to understand what Andrei said in Andrei's paper about union, but actually and honestly have not yet figured out much all of Andrei's wonderful and great ideas...And I would also like to know if there are still any other things about union beside what is already mentioned by Andrei that we can learn and make use of.
If you have any ideas in mind about this, please tell me...I really would like to learn something from you...

Any ideas are all appreciated!
Thank you very much.
 
In my discussions elsewhere, I've noticed a lot of disagreement regarding AI. A question that comes up is, "Is AI hype?" Unfortunately, when this question is asked, the one asking, as far as I can tell, may mean one of three things which can lead to lots of confusion. I'll list them out now for clarity. 1. Can AI do everything a human can do and how close are we to that? 2. Are corporations and governments using the promise of AI to gain more power for themselves? 3. Are AI and transhumans...
Sorry if 'Profile Badge' is not the correct term. I have an MS 365 subscription and I've noticed on my Word documents the small circle with my initials in it is sometimes different in colour document to document (it's the circle at the top right of the doc, that, when you hover over it it tells you you're signed in; if you click on it you get a bit more info). Last night I had four docs with a red circle, one with blue. When I closed the blue and opened it again it was red. Today I have 3...

Similar threads

Back
Top