ABI边界的可移植性
来源:互联网 发布:区域生长分割算法 编辑:程序博客网 时间:2024/06/15 18:09
在二进制接口边界应该使用足够可移植的类型和惯用法。可移植类型指C的内置类型或只含有C内置类型的结构体(struct)。Class类型只有在调用方和被调用方在内存布局和调用约定一致的情况下才可以使用,这通常只有在双方使用同样的编译器和编译选项的情况下才成为可能。
如何使一个class转化为可移植的C等价物
当调用方可能被另一种编译器或语言编译的时候,使用一定的调用惯例将class"flatten"到“extern C”接口。
示例:// class widget {// widget();// ~widget();// double method(int, gadget&);// };extern "C" { // functions using explicit "this" struct widget; // + opaque type (fwd decl only) widget* STDCALL widget_create(); // ctor → create new "this" void STDCALL widget_destroy(widget*); // dtor → consume "this" double STDCALL widget_method(widget*, int, gadget*); // method → use "this"}
这个转化实际上相当于将class定义的数据和接口分离为C struct和对应的一组接口,显示使用class的this指针原文:http://technet.microsoft.com/en-us/magazine/hh438475.aspx
Portability At ABI Boundaries (Modern C++)
Use sufficiently portable types and conventions at binary interface boundaries. A “portable type” is a C built-in type or a struct that contains only C built-in types. Class types can only be used when caller and callee agree on layout, calling convention, etc. This is only possible when both are compiled with the same compiler and compiler settings.
How to flatten a class for C portability
When callers may be compiled with another compiler/language, then “flatten” to an “extern C” API with a specific calling convention:
Visual C++// class widget {// widget();// ~widget();// double method(int, gadget&);// };extern "C" { // functions using explicit "this" struct widget; // + opaque type (fwd decl only) widget* STDCALL widget_create(); // ctor → create new "this" void STDCALL widget_destroy(widget*); // dtor → consume "this" double STDCALL widget_method(widget*, int, gadget*); // method → use "this"}
- ABI边界的可移植性
- Java 的可移植性
- linux的可移植性
- Linux 可移植性(软件可移植)
- 关于JAVA的可移植性
- 关于可移植性的一点唠叨
- 可移植性最好的SNMP引擎
- 关于JAVA的可移植性
- 关于程序可移植性的问题
- 关于驱动程序的可移植性
- linux内核的可移植性
- 软件程序的可移植性
- 论Oracle数据库的可移植性
- Djyos的可移植性(转载)
- Djyos的可移植性(转载)
- 如何提高程序的可移植性
- 如何提高程序的可移植性
- C 程序的可移植性
- 《黑马程序员》java笔记->售票例子
- Javascript基础(一)——基本语法
- Heritrix的安装与配置
- SICP 习题(1.5)解题总结:应用序和正则序
- 《黑马程序员》java笔记->售票例子实现Runnable接口创建线程
- ABI边界的可移植性
- java 日期处理
- oracle之闪回
- 《黑马程序员》java笔记->多线程安全问题
- perl advent
- 内存管理之虚拟页式分配
- 一步步构建大型网站架构 .
- stm32程序中的assert_param()的说明
- 对于公司的企业文化和组织架构的一些意见