all groups > dotnet clr > december 2006 >
You're in the

dotnet clr

group:

What's with the new C++/CLI pointers (handles ^)? Managed C++.NET



What's with the new C++/CLI pointers (handles ^)? Managed C++.NET raylopez99
12/18/2006 7:03:48 AM
dotnet clr: Please comment on the following code fragment. Note the "WHY"?
Particularly, (1) why does referencing and dereferencing a pointer give
the same thing (at least in WriteLine(), which might be some sort of
cast going on behind the scenes), (2) why doesn't the pointer "stick
to" a reference, such as when y = intRef; below, then intRef is changed
but the y handle does not change, and (3) why doesn't y = &intVT
compile?

Thanks

RL

///////////////////////////////////////////////////////////////
// in managed C++/CLI console mode

int intVT = 10;
int %intRef = intVT;
int ^y = gcnew int(200);
Console::WriteLine("Should be 200 {0} EITHER WAY !: {1} ", y, *y);

*y = 210; //also works y = 210; //WHY?

Console::WriteLine("Should be 210 {0}...is it? (yes)",*y);

y = intRef;
Console::WriteLine("Should be intRef or 10: {0}...is it (Yes)?",y);

intRef = 21;
Console::WriteLine("Should be intRef or 21: {0} , {1}...is it
(NO)?",y, intRef); //WHY NOT?

y = intRef; //but now it should work: add-- y = intRef; // also works:
*y = intRef; // same answer of 21 //WHY?

Console::WriteLine("Should be intRef or 21: {0} , {1}...is it
(Yes)?",y, intRef);

//y = &intVT; //unsafe operation by definition? (no, illegal!)
//won't compile! WHY?
Re: What's with the new C++/CLI pointers (handles ^)? Managed C++.NET kwikius
12/18/2006 7:45:04 AM

[quoted text, click to view]

Technically this isnt standard C++, but OTOH I personally find the
garbage collected types in C++/CLI interesting. I would guess that you
cant get the address because being a handle this gives the
implementation the fredom to change the actual address whenever it
wants, in order to move gc stuff in memory or whatever. You could do
the same type of stuff in standard C++ I guess with some handle<T>
type...

Anyway you are probably better off to refer your questions to a more
appropriate newsgroup, where they can give more details.

regards
Andy Little
Re: What's with the new C++/CLI pointers (handles ^)? Managed C++.NET kwikius
12/18/2006 7:48:43 AM

[quoted text, click to view]

Ooops. sorry didnt realise it was crossposted.

regards
Andy Little
Re: What's with the new C++/CLI pointers (handles ^)? Managed C++.NET William DePalo [MVP VC++]
12/18/2006 10:22:06 PM
[quoted text, click to view]

FWIW, you are far more likely to find help on C++/CLI in the group

microsoft.public.dotnet.languages.vc

than here.

Regards,
Will





Re: What's with the new C++/CLI pointers (handles ^)? Managed C++.NET raylopez99
12/19/2006 3:02:08 AM
Thank you, I'll post to microsoft.public.dotnet.languages.vc

I think the answer is indeed garbage collection.

RL

[quoted text, click to view]
AddThis Social Bookmark Button