CPP/CLI 中的本机和托管之间是否令人困惑?

发布于 2024-10-18 21:56:47 字数 463 浏览 0 评论 0原文

如果我使用 /clr 模式编译具有如下内容的代码:

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

我现在的问题: int 类型会映射到 System::Int32 吗?那么 char ch 呢?它们被视为本机类型还是托管类型?哪里会被处决!是否通过 MSIL!

我们看到 int arr[] 是一个原生数组,这是否意味着它将在 MSIL 之外执行?

最后一个问题,,对于托管数组 ManArr1 & ManArr2 两个初始化有什么区别?

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 ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小嗷兮 2024-10-25 21:56:47

使用 /clr 编译时,整个程序都会转换为 MSIL,除非您使用 #pragma Managed(off)#pragma unmanaged

  • int 相当于 System::Int32
  • char 相当于 System::SByte (不是 System::Char!)
  • 这两种类型都是“原始的”。托管代码将它们视为托管类型,本机代码将它们视为本机类型。
  • 本机数组将使用无法验证的 MSIL(例如,与 C# 指针相同)

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)
累赘 2024-10-25 21:56:47

关于“对于托管数组ManArr1 & ManArr2这两个初始化有什么区别??”

没有功能上的区别,一个是另一个的简写。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文