[英]StructLayout limitation in F# Interactive?
我注意到如果我用StructLayout.Sequential定义一个结构,就像这样:
open System.Runtime.InteropServices
[<StructLayout(LayoutKind.Sequential, Pack=1)>]
type SomeType =
val mutable Field1: uint32
val mutable Field2: uint32
这在实际程序中编译并正常工作,但FSI给出错误error FS0193: internal error: Could not load type 'SomeType' from assembly 'FSI-ASSEMBLY, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because field 'Field1' was not given an explicit offset.
这是FSI的错误或限制吗? 有解决方法吗?
解决方法(错误有提示):
[<Struct;StructLayout(LayoutKind.Explicit)>]
type SomeType =
[<FieldOffset(0)>]
val mutable Field1: uint32
[<FieldOffset(4)>]
val mutable Field2: uint32
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.