Aan
Aan

Reputation: 12890

Confusing between Native and Managed in CPP/CLI?

If i use /clr mode to compile a code that has somthing like the following:

int x = 3;
char ch='A';
int arr[]="Hi";
array<int>^ ManArr1={44};
array<int>^ ManArr2= gcnew array<int> {44};

my questions now: Would the type int be mapped to System::Int32 ?? and what about char ch ? Are they considerd as native or managed type? Where will be executed! through MSIL or not!!

We see that int arr[] is a native array, does that mean it will be executed out of MSIL?

The last question ,, For both the managed array ManArr1 & ManArr2 what is the difference between the two initialization ??

Upvotes: 0

Views: 406

Answers (2)

Ben Voigt
Ben Voigt

Reputation: 283624

When compiling with /clr, your entire program is converted to MSIL unless you use #pragma managed(off) or #pragma unmanaged

  • int is equivalent to System::Int32
  • char is equivalent to System::SByte (not System::Char!)
  • Both of these types are "primitive". Managed code sees them as managed types and native code sees native types.
  • Native arrays will use unverifiable MSIL (same as C# pointers, for example)

Upvotes: 2

Matt Smith
Matt Smith

Reputation: 17434

Regarding "For both the managed array ManArr1 & ManArr2 what is the difference between the two initialization ??"

There is no functional difference, one is a shorthand for the other.

Upvotes: 1

Related Questions