C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 21st, 2003, 05:45 AM
bsuribabu bsuribabu is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Hyderabad
Posts: 17 bsuribabu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to bsuribabu
References Vs Anonymous Unions

Hi,

Here is a some analysis i have made on References and Anonymous Unions.

Pls tell me that my assumption is correct or not?

1. Reference is a alias for another variable means i can create a reference to a variable where i can use the reference in the same way where i can use the variable . Means some what we are creating the two variables sharing the same memory.

2. If anonymous union contains two variables of same datatype
like

union {
int a,b;
};
this declaration gives us that a,b sharing the same memory.
means if we feel "a" as a actual variable and b as a reference for it , it acts in the same way as reference does.


Suri

Last edited by bsuribabu : January 21st, 2003 at 05:48 AM.

Reply With Quote
  #2  
Old January 23rd, 2003, 05:38 AM
alibek alibek is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Budapest
Posts: 5 alibek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
not correct 100%

I think, your assumption is not correct 100%:

1. here, there is 80% truth. yes, Reference is a kind of alias for another variable. Yes, youi can create a reference to a variable and use that reference in the same way. But, you have to remember, that you cannot create reference without creating and initializing variable first, otherwise you will get problem. More strcitly, reference is "syntactic sugar", it is a pointer which is always dereferenced for you.
and you cannot create 2 two variables sharing the same memory
with reference. you just create another names for that variable. but that names are pointers and their value is the address of original variable.

2. and it is union, which allows creating 2 variables "really" sharing the same memory. But only one can exist at the time.

Even if anonymous union contains two variables of same datatype
like, does not make sense, because when you will have 1 int space in memory.
The main reason to have union is to safe memory.

in this and it will not act in the same way as reference does. for example:

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > References Vs Anonymous Unions

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap