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
Printable View
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
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.
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
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
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
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?
regards,
George
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
Yes, I agree with that.
--
Mats