知识卡片
外语接口协调调用约定
FFI 让 Rust 和其他语言互相调用。声明 C 函数要有匹配的签名和 extern “C” 调用约定,ABI 规定机器层级怎样传参并接收结果。Rust 调用外部实现时还需核对其安全条件。从 Rust 向外导出时,除 ABI 外还要保证链接方能引用预期的符号名,书中用 no_mangle 演示。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 高级特性 Using extern Functions to Call External Code · 查看原书依据
Within the extern "C" block, we list the names and signatures of external functions from another language we want to call. The "C" part defines which application binary interface (ABI) the external function uses: the ABI defines how to call the function at the assembly level. The "C" ABI is the most common and follows the C programming language’s ABI.
参考来源
- 位置:《The Rust Programming Language(第2版)》第19章 高级特性(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c19.xhtml`,块 0086)
- 结论依据:原文说明 extern 块放置声明以及 C ABI 规定的底层调用方式,随后展示反向导出所需的符号名。
- 原始内容:Within the extern "C" block, we list the names and signatures of external functions from another language we want to call. The "C" part defines which application binary interface (ABI) the external function uses: the ABI defines how to call the function at the assembly level. The "C" ABI is the most common and follows the C programming language’s ABI.