473,511 Members | 15,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ intrinsic types and __value class equivalents

In the doc regarding __value classes, under Primitive Types, I read:

"Generally, the C++ types and their __value class equivalents are
interchangeable in Managed Extensions."

What exactly does this mean ?

Does it mean that one can pass or return a C++ primitive to a function for
the equivalent __value class and vice-versa ?
Does this mean that one can assign the value of a C++ primitive type to the
equivalent __value class object and vice versa ?

Or what exactly is being specified here ? The rest of the topic does not
explain the quoted line above.
Nov 16 '05 #1
3 2681
Edward Diener wrote:
In the doc regarding __value classes, under Primitive Types, I read:

"Generally, the C++ types and their __value class equivalents are
interchangeable in Managed Extensions."

What exactly does this mean ?


It means that you can do the following:

int x = 42;
System::Int32 y = x;
int z = y;

Basically, int and System::Int32 are exactly the same type. In fact, when
you type System::Int32 in a program, the compiler diagnostics will say "int"
instead.

The "generally" comes in when GC'ness of a type matters. This appears in two
contexts: (1) default meaning for a pointer, and (2) default meaning for an
array. The C++ type is assumed to have no GC'ness, whereas the __value class
equivalent does have GC'ness.

If a type T has GC'ness, then the declaration "T*" defaults to a __gc
pointer. If a type does not have GC'ness, then the declaration "T*" defaults
to a native pointer. To convert from a __gc pointer to a native pointer
requires pinning.

If a type T has GC'ness, then the declaration "T arr[]" defaults to a
System::Array of T. If a type T does not have GC'ness, then the declaration
"T arr[]" is a native C-style array.

Based on that summary, it should be easy to make sense of this when you read
other parts of the Managed Extenstions spec.

Hope that helps!

--
Brandon Bray http://blogs.gotdotnet.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.
Nov 16 '05 #2
Brandon Bray [MSFT] wrote:
Edward Diener wrote:
In the doc regarding __value classes, under Primitive Types, I read:

"Generally, the C++ types and their __value class equivalents are
interchangeable in Managed Extensions."

What exactly does this mean ?
It means that you can do the following:

int x = 42;
System::Int32 y = x;
int z = y;


Yes, I understand this.

Basically, int and System::Int32 are exactly the same type. In fact,
when you type System::Int32 in a program, the compiler diagnostics
will say "int" instead.

The "generally" comes in when GC'ness of a type matters. This appears
in two contexts: (1) default meaning for a pointer, and (2) default
meaning for an array. The C++ type is assumed to have no GC'ness,
whereas the __value class equivalent does have GC'ness.

If a type T has GC'ness, then the declaration "T*" defaults to a __gc
pointer. If a type does not have GC'ness, then the declaration "T*"
defaults to a native pointer. To convert from a __gc pointer to a
native pointer requires pinning.
If I go the opposite way, and need to pass a __gc pointer, can I pass a
native pointer instead ?

public __gc class A { public: void SomeMemberFunction(System::Int32 *)
{ } };
....
int AnInt;
A * myA = new A();
myA -> SomeMemberFunction(&AnInt);

If a type T has GC'ness, then the declaration "T arr[]" defaults to a
System::Array of T. If a type T does not have GC'ness, then the
declaration "T arr[]" is a native C-style array.
OK, good. I assune there is no automatic conversion between a GC array and a
C++ array.

Based on that summary, it should be easy to make sense of this when
you read other parts of the Managed Extenstions spec.

Hope that helps!


Thanks, it does.
Nov 16 '05 #3
Edward Diener wrote:
If I go the opposite way, and need to pass a __gc pointer, can I pass a
native pointer instead ?
Yes. Adding GC'ness to a pointer is fine. Only removing GC'ness requires
pinning.
OK, good. I assune there is no automatic conversion between a GC array
and a C++ array.


Correct.

Cheerio!

--
Brandon Bray http://blogs.gotdotnet.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3910
by: Jeremy Cowles | last post by:
I have been reading a book that focuses on understanding the intrinsic types of C++ in depth. The author's mentality is this: "Understand the intrinsic types, then learn the std types as needed...
16
2566
by: Edward Diener | last post by:
Is there a way to override the default processing of the assignment operator for one's own __value types ? I realize I can program my own Assign method, and provide that for end-users of my class,...
8
1792
by: Edward Diener | last post by:
I have a __value class which uses some legacy C++ code. So I wrapped the legacy C++ code in another __nogc class and have a pointer to that class as a member of my __value class. When the __value...
0
1182
by: Edward Diener | last post by:
If a __value class with an event is put into an assembly, and a __gc class in another assembly attempts to attach its own event handler to the __value class's event of an embedded object of the...
15
1370
by: Edward Diener | last post by:
Why is it impossible to have a __value class instance variable in a __nogc class when it is possible to have a built-in type instance variable in a __nogc class ? __value class X { int a; };...
5
3856
by: Alan Cobb | last post by:
Hi, In the managed C++ class below I get compile warning C4677 from VS2003. "signature of non-private function contains assembly private type", even though the managed enum is public. I have...
1
1306
by: Bae,Hyun-jik | last post by:
Where are __value objects allocated? I guess __value object is same to basic __value objects such as int,char,float, but C# compiler demands using new keyword even to __value classes. Please...
7
1628
by: A Traveler | last post by:
Hello all, i was just curious if anyone whos been playing with VS2005 could tell me... In javascript (and java??) you can alter the prototypes for an object in your project. I dont remember...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7508
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3212
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.