CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    Reference and address of operator

    Why did C++ creators used the same symbol for references and address of operator. When I was a begineer I found it very difficult to differentiate between the two though the right type could be obtained from the context. Is there any advantage in doing so?
    If there is no love sun won't shine

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Reference and address of operator

    [ Redirected thread ]
    Although later you'll consider that it's not so hard to differentiate from context, this guy is the only one who can give you the best answer:
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    Re: Reference and address of operator

    Is this Stroustroup himself?

    Nice picture
    If there is no love sun won't shine

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Reference and address of operator

    Yea, it's taken from Bjarne Stroustrup's homepage.
    You can take a look in it and maybe you can find the answer.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  5. #5
    Join Date
    Sep 2004
    Location
    New Delhi, India
    Posts
    640

    Re: Reference and address of operator

    I have put that as my new wallpaper.

    I love you Bjarne :-*!
    "I rather not play football than wear Nerrazzuri shirt" - Paolo Maldini
    FORZA MILAN!!!

  6. #6
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128

    Re: Reference and address of operator

    I never know there are some people actually worshipping him.
    quoted from C++ Coding Standards:

    KISS (Keep It Simple Software):
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.

    Avoid magic number:
    Programming isn't magic, so don't incant it.

  7. #7
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588

    Re: Reference and address of operator

    It may be confusing, but I don't remember having trouble distinguishing between the two different uses. It's true that something like "void f(int &i)" looks weird when you come from C without references, but then again, the contextual differences are pretty clear though.
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  8. #8
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Re: Reference and address of operator

    Quote Originally Posted by Kheun
    I never know there are some people actually worshipping him.
    He is not worshipping him.. You will find many worshippers though...

    He actually is in LOVE with him ... el o vee ee... love..

  9. #9
    Join Date
    Sep 2004
    Location
    New Delhi, India
    Posts
    640

    Re: Reference and address of operator

    I love this man too...
    "I rather not play football than wear Nerrazzuri shirt" - Paolo Maldini
    FORZA MILAN!!!

  10. #10
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: Reference and address of operator

    When I first saw that syntax, I thought it was intuitive, but of course I understand that overuse of the same keywords in different contexts, with different meaning, may be confusing.
    For example the "static" keyword has at least three meanings (and a new one in C99).
    "inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
    Club of lovers of the C++ typecasts cute syntax: Only recorded member.

    Out of memory happens! Handle it properly!
    Say no to g_new()!

  11. #11
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    Re: Reference and address of operator

    I know two meanings of the static keyword.

    1. Life time that of the program.
    2. Creation of one instance.

    Is Internal Linkage the third one?
    Last edited by miteshpandey; March 3rd, 2006 at 08:36 AM.
    If there is no love sun won't shine

  12. #12
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

  13. #13
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: Reference and address of operator

    static means "instance-independent" when used with members of a class.

    It means "internal storage" when used with data/functions at namespace-scope level... what is funny, because with class data members it has external linkage.
    It means "static storage duration" for function's static variables.
    Since internal storage data implies static storage duration, you can deem that these two last form of "static" have the same semantics (i.e. "internal storage).
    But for a beginner, it is not very intuitive that:
    Code:
    static int hello()
    {
    static int k=42;
    return ++k;
    }
    In that code, the two static words have the same "meaning".
    However if the auto keyword was not implicit when declaring variables inside a function, that may seem more intuitive to beginners.

    That is why I said that there were three meanings.
    "inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
    Club of lovers of the C++ typecasts cute syntax: Only recorded member.

    Out of memory happens! Handle it properly!
    Say no to g_new()!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured