知识卡片

普通读书笔记卡 · 6074.h.1.a.1.a

FFI类型必须匹配真实声明

理解等级:中级

跨语言边界类型应匹配真实C声明与目标ABI,能设计新接口时可用固定宽度整数减少歧义。既有int、long或size_t接口则应使用对应C类型,不能为整齐擅改成u32。链接器通常无法证明调用签名一致,需以头文件、生成工具与目标配置核验。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 6. Beyond Standard Rust Code concerns · 查看原书依据

      Prefer sized types at FFI boundaries, where possible—which for C means making use of the types (e.g., uint32_t) defined in <stdint.h>. However, if you’re dealing with an existing codebase that already uses int/long/size_t, this may be a luxury you don’t have. The final practical concern is that the C code and the equivalent Rust declaration need to exactly m

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第6章《Code concerns》(spine10;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch06.html;u176-ch06-009)。 - 结论依据:原文在“Prefer sized types”附近的定义、例子或代码支撑本卡核心说明:跨语言边界类型应匹配真实C声明与目标ABI,能设计新接口时可用固定宽度整数减少歧义。边界按已读前提解释;示例未执行。 - 原始内容:Prefer sized types at FFI boundaries, where possible—which for C means making use of the types (e.g., uint32_t) defined in <stdint.h>. However, if you’re dealing with an existing codebase that already uses int/long/size_t, this may be a luxury you don’t have. The final practical concern is that the C code and the equivalent Rust declaration need to exactly m