Help me understand

Q

QbProg

Hello,

I did some experiments with VC++ 2005, and some ILDasm. Please tell me
if I have understood the concepts of C++ programming under .NET, since
I'm a bit confused!
--
There are 4 types of classes in VC++/CLI:

Unmanaged classes (i.e. normal classes compiled in a unmanaged source
or dll , the code is unmanaged and CPU native). Accessible from C++/CLI
classes but only with a reference (pointer), require a
managed/unmanaged transition for each function call.

Native classes
Standard C++ classes that are compiled with /CLR enabled. These are
marked as native, use the same syntax as standard c++, but compile to
IL (and use the IL CRT). These are not accessible from C#/VB, etc...
but only from C++. Allow for a CLR:pure compilation, and the code
generated is effectively IL. (you can use framework classes). When an
unmanaged function is called a IJW stub is used.
I don't know if the term "native" is appropriate because on previous
versions it was used as synonym of "unmanaged". Anyway, using ILDasm I
see the "native" tag and IL code.

Value classes
Are .NET classes that can be defined only from C++/CLI, but can be
*used* from other languages too. Are effectively .NET classes value
classes, but could not be instantiated from C# VB. These suffer of many
limitations, so the port of existing C++ classes is not really
confortable.

Ref classes, are "ufficial" .NET classes , used in C++/VB, are accessed
with handles and garbage collected, bla bla bla
In C++ you can use Ref classes by value (and in C# it generates a
different syntax), anyway you need an explicit contructor and
copy/constructor.
--
It is correct? I'm a little confused about native classes. The lack of
value class support in C#/VB is not really good, because it makes
harder to port existing C++ code....
From what I've understood, Native classes are the key feature to avoid
managed/unmanaged transitions and to port easily your existing code at
least into CLI.... (and that is REALLY good)

Tell me if I'm wrong...
Thanks and sorry for my English!!
QbProg
 
G

Guest

Regarding ref vs value classes and comparison to C# and VB:
ref class -> equivalent to C# or VB 'class'
value class -> equivalent to C# or VB 'struct'

Note that the C++ 'ref struct' and 'value struct' are not required to
represent C# or VB entities. 'struct' in C++ is identical to a C++ class
except for the default access level.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
 
A

adebaene

Hello,

I did some experiments with VC++ 2005, and some ILDasm. Please tell me
if I have understood the concepts of C++ programming under .NET, since
I'm a bit confused!
--
Value classes
Are .NET classes that can be defined only from C++/CLI, but can be
*used* from other languages too. Are effectively .NET classes value
classes, but could not be instantiated from C# VB. These suffer of many
limitations, so the port of existing C++ classes is not really
confortable.

Ref classes, are "ufficial" .NET classes , used in C++/VB, are accessed
with handles and garbage collected, bla bla bla
In C++ you can use Ref classes by value (and in C# it generates a
different syntax), anyway you need an explicit contructor and
copy/constructor.

Value classes are full fledged .NET citizens, and can be created in
other .NET languages. They are called "struct" in C# and "Structure" in
VB.NET. They indeed have some limitations compared to classes, but also
some advantages (eg, they are allocated on the stack, not on the manaed
heap). Anyway, the difference between those 2 types is defined by the
..NET Runtime, and it is not C++ specific in any way.
It is correct? I'm a little confused about native classes.
Why? You can simply see them as usual, normal C++ classes that are
compiled to a different assembly language... Anyway, your wording for
"unmanaged" versus "native" is not official, but if it helps you....
The lack of
value class support in C#/VB is not really good, because it makes
harder to port existing C++ code....
Value classes *ARE* supported in C# or VB !!!

To help you understand those things, you could use .NET Reflector
(Google for it) instead of IldAsm. This tool can dissasemble IL code
and show it as either C# or VB.NET source code. This may help you
understand better what the C++ compiler generates when calling it with
/clr.

Arnaud
MVP - VC
 
A

adebaene

Hello,

I did some experiments with VC++ 2005, and some ILDasm. Please tell me
if I have understood the concepts of C++ programming under .NET, since
I'm a bit confused!
--
Value classes
Are .NET classes that can be defined only from C++/CLI, but can be
*used* from other languages too. Are effectively .NET classes value
classes, but could not be instantiated from C# VB. These suffer of many
limitations, so the port of existing C++ classes is not really
confortable.

Ref classes, are "ufficial" .NET classes , used in C++/VB, are accessed
with handles and garbage collected, bla bla bla
In C++ you can use Ref classes by value (and in C# it generates a
different syntax), anyway you need an explicit contructor and
copy/constructor.

Value classes are full fledged .NET citizens, and can be created in
other .NET languages. They are called "struct" in C# and "Structure" in
VB.NET. They indeed have some limitations compared to classes, but also
some advantages (eg, they are allocated on the stack, not on the manaed
heap). Anyway, the difference between those 2 types is defined by the
..NET Runtime, and it is not C++ specific in any way.
It is correct? I'm a little confused about native classes.
Why? You can simply see them as usual, normal C++ classes that are
compiled to a different assembly language... Anyway, your wording for
"unmanaged" versus "native" is not official, but if it helps you....
The lack of
value class support in C#/VB is not really good, because it makes
harder to port existing C++ code....
Value classes *ARE* supported in C# or VB !!!

To help you understand those things, you could use .NET Reflector
(Google for it) instead of IldAsm. This tool can dissasemble IL code
and show it as either C# or VB.NET source code. This may help you
understand better what the C++ compiler generates when calling it with
/clr.

Arnaud
MVP - VC
 
Q

QbProg

Thanks for the pointings!!
One last thing:
Why? You can simply see them as usual, normal C++ classes that are
compiled to a different assembly language... Anyway, your wording for
"unmanaged" versus "native" is not official, but if it helps you....

This is where I do not understand. From what I view from ILDast(I'll
try google net reflector soon :)
unmanaged classes are compiled to platform specific assembler code, but
NATIVE classes are still compiled to IL (i.e are not unmanaged but
accessible only from C++/CLI).
Native classes exists even with CLR:pure (not unmanaged) and use a
modified version of the C Runtime.
I'm wrong?

QbProg
 
B

Ben Voigt

QbProg said:
Thanks for the pointings!!
One last thing:


This is where I do not understand. From what I view from ILDast(I'll
try google net reflector soon :)
unmanaged classes are compiled to platform specific assembler code, but
NATIVE classes are still compiled to IL (i.e are not unmanaged but
accessible only from C++/CLI).
Native classes exists even with CLR:pure (not unmanaged) and use a
modified version of the C Runtime.
I'm wrong?

You're not wrong about that.

You are wrong in thinking that only C++/CLI can generate value class types.
The equivalent in C# is the struct keyword.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top