纯 C++/CLI 的 MSIL
/clr:pure
开关生成纯 MSIL,但不可验证。本机数组和指针可以在此模式下使用。这是否意味着 MSIL 中有一个结构来保存本机数组和指针?如果是的话,我想问一下如何编写MSIL本机数组和指针?
/clr:pure
switch generates pure MSIL but it is not verifible. Native array and pointer can be used in this mode. Does that mean that there is a structure in MSIL to hold native arrays and pointers? If yes, I would like to ask how can I code MSIL native array and pointer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,CIL中有一种类型来表示非托管指针。它们类似于托管指针(C# 中的
ref
和out
,CIL 中的&
),只不过 GC 会忽略它们,您可以执行一些操作对它们进行算术运算(对指针有意义的算术运算)。有趣的是,指针类型确实包含有关目标类型的信息(例如
int32*
),但所有算术运算都是基于字节的。例如,以下 C++/CLI 方法:
当它位于
ref class
内部时,会生成以下 CIL(如 Reflector 所报告):Yes, there is a type in CIL to represent unmanaged pointers. They are similar to managed pointers (
ref
andout
in C#,&
in CIL), except that GC ignores them and you can do some arithmetic operations on them (those that make sense with pointers).Interestingly, the pointer type does contain information about the target type (so it's e.g.
int32*
), but all arithmetic operations are byte based.As an example, the following C++/CLI method:
produces the following CIL when it's inside a
ref class
(as reported by Reflector):