#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    Hyderabad
    Posts
    17
    Rep Power
    0

    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.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Budapest
    Posts
    5
    Rep 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:

IMN logo majestic logo threadwatch logo seochat tools logo