【问题标题】:StructLayout limitation in F# Interactive?F# Interactive 中的 StructLayout 限制?
【发布时间】:2014-07-05 15:01:24
【问题描述】:

我注意到如果我用 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 的错误或限制吗?有解决办法吗?

【问题讨论】:

标签: f# f#-interactive


【解决方案1】:

解决方法(错误有提示):

[<Struct;StructLayout(LayoutKind.Explicit)>]
type SomeType =
    [<FieldOffset(0)>]
    val mutable Field1: uint32
    [<FieldOffset(4)>]
    val mutable Field2: uint32

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多