473,804 Members | 2,747 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 2698
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 SomeMemberFunct ion(System::Int 32 *)
{ } };
....
int AnInt;
A * myA = new A();
myA -> SomeMemberFunct ion(&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
3925
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 later", but I have been reading the stroustrup (spelling?) book and he says that it is much better to learn the standard library first as a beginner, and then worry about the intrinsic types afterwards. So there is no doubt that you need to have a...
16
2624
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, but I would like to use internally my own = operator for some of my value types, so I can say "x = y;" rather than "x.Assign(y);". The op_Assign operator seems impossibly broken since it takes __value copies of the two objects. Perhaps there is...
8
1807
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 class is created, I dynamically allocate an object of the class with the legacy C++ code. However because the __value class has no destructor, I can never release that allocated memory. Why does a __value class allow no destructor ? Without it I...
0
1193
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 __value class type, everything compiles correctly but the Linker puts out error "LINK : error LNK2020: unresolved token (0A000003) AValueClassEvent" followed by "LINK : fatal error LNK1120: 1 unresolved externals". If the __value class is in the same...
15
1397
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; }; __nogc class Y { X b; int c;}; // compiler error __nogc class Y { int c;}; // OK
5
3872
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 to drop the "enum" keyword from my member variable declaration to keep the compiler happy. Shouldn't I technically be able to use the "enum" keyword without a warning?
1
1320
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 reply. Thanks in advance. Regards, Hyun-jik Bae
7
1646
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 the syntax exactly, but basically you do something like: function String.prototype.mySplit(myArgs){...do something...}
0
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9591
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10594
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10087
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7631
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6861
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.