【问题标题】:How one defines a union type in Squeak FFI如何在 Squeak FFI 中定义联合类型
【发布时间】:2018-04-11 19:32:41
【问题描述】:

我想与对某些结构字段使用某种联合类型的库进行交互,例如:

typedef struct {
    H5L_type_t          type;           /* Type of link                   */
    hbool_t             corder_valid;   /* Indicate if creation order is valid */
    int64_t             corder;         /* Creation order                 */
    H5T_cset_t          cset;           /* Character set of link name     */
    union {
        haddr_t         address;        /* Address hard link points to    */
        size_t          val_size;       /* Size of a soft link or UD link value */
    } u;
} H5L_info_t;

我在 Squeak FFI 中没有看到任何形式的支持。

我应该自己确定最长的会员规模并坚持下去吗?

【问题讨论】:

    标签: smalltalk ffi squeak


    【解决方案1】:

    所以在仔细查看源代码后,我可以看出 Squeak FFI 中不支持联合。

    不必一直这样,所以我发布了 Squeak FFI 的更新以支持工会。
    见http://source.squeak.org/FFI/FFI-Kernel-nice.50.diff

    ExternalUnion 与ExternalStructure(作为子类)基本共享相同的代码,只是它使用常量byteOffset 和max: 运算符来累积总字节大小,而不是使用递增的byteOffset遍历字段时的 + 运算符。

    【讨论】:

    • 非常适合ExternalObject 的层次结构。我同意将ExternalUnion 视为ExternalStructure 的特例很有用。 C标准如何谈论联合?这些解释与结构有关吗?
    • Subclassing ExternalStructure 是避免 FFI 插件更改的必要技巧。但如果我们愿意,我们也可以改变它。
    猜你喜欢
    • 2011-03-31
    • 1970-01-01
    • 1970-01-01
    • 2022-07-08
    • 1970-01-01
    • 1970-01-01
    • 2021-04-01
    • 2018-05-16
    相关资源
    最近更新 更多