pointer_default

This is a discussion on pointer_default within the C++ Programming forums, part of the General Programming Boards category; Hello everyone, Could anyone show me the usage of pointer_default please (sample of when we need to use ref, unique ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    pointer_default

    Hello everyone,


    Could anyone show me the usage of pointer_default please (sample of when we need to use ref, unique and ptr)? After some search, I found too little materials on this topic. :-)


    thanks in advance,
    George

  2. #2
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    Any good book on C/C++ should provide enough resources to explain and provide examples of pointer usage. There are also tutorials on line (Google them) that should provide enough sources to answer any questions you may have.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    pointer_default isn't something to do with pointers. MSDN seems to indicate that it's an attribute, like __c_decl etc.

    I have no idea how to use it, though perhaps you can find some information on MSDN. http://msdn2.microsoft.com/en-us/lib...41(VS.85).aspx
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks kcpilot and dwks,


    I have found some good link by your advice, and get some further confusions,

    Confused about two sentences,

    1. "Does not cause aliasing. Storage pointed to by a reference pointer cannot be reached from any other name in the function." from,

    http://msdn2.microsoft.com/en-us/lib...53(VS.85).aspx

    2. "Does not cause aliasing. Like storage pointed to by a reference pointer, storage pointed to by a unique pointer cannot be reached from any other name in the function." from,

    http://msdn2.microsoft.com/en-us/lib...94(VS.85).aspx

    What do they mean?


    regards,
    George

    Quote Originally Posted by dwks View Post
    pointer_default isn't something to do with pointers. MSDN seems to indicate that it's an attribute, like __c_decl etc.

    I have no idea how to use it, though perhaps you can find some information on MSDN. http://msdn2.microsoft.com/en-us/lib...41(VS.85).aspx

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I think I explained the "can not alias" points in the unique post. Please ask there if you need clarification, as aliasing is the key, and default_pointer is just one of several pointer types that are defined to be nonaliased.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Mats,


    I think the concept of non-aliaing could be understood in the two rules,

    1. No other pointers could be pointed to the same memory storage;
    2. The pointer could be pointed to other storage, i.e. not const pointer.

    Right?

    About (2), I think it means other pointer has the chance to point to the same storage area if the pointer is pointed to other storage area.

    Here is a sample code,

    Code:
    char* ptr1 = NULL;
    char* ptr2 = NULL;
    char array[] = "Hello World \n";
    ptr1 = array; // allow
    ptr2 = ptr1; // not allow
    ptr2 = array; // not allow
    
    ptr1 = NULL;
    ptr2 = array; // allow;
    ptr2 = ptr1; // allow? alias to NULL allowed?
    Quote Originally Posted by matsp View Post
    I think I explained the "can not alias" points in the unique post. Please ask there if you need clarification, as aliasing is the key, and default_pointer is just one of several pointer types that are defined to be nonaliased.

    --
    Mats

    regards,
    George

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, NULL is allowed as an alias, as it can't be accessed - and aliasing is only really a problem where you have two pointers that you are accessing.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Mats,


    So you agree with my code/analysis in #6 is correct? :-)

    Quote Originally Posted by matsp View Post
    Yes, NULL is allowed as an alias, as it can't be accessed - and aliasing is only really a problem where you have two pointers that you are accessing.

    --
    Mats

    regards,
    George

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, I agree with that.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Mats,


    Cool!

    Quote Originally Posted by matsp View Post
    Yes, I agree with that.

    --
    Mats

    regards,
    George

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21