python中如何移植c到d03

发布时间:2021-09-18 10:35:42 作者:柒染
来源:亿速云 阅读:150

这篇文章给大家介绍python中如何移植c到d03,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

// In C
extern void someCFunction(void);
// In D
extern( C ) void someCFunction();

extern(Windows),则表明stdcall调用约定.在c头上类似__stdcall前缀.在窗口上,则是类似WINAPI, APIENTRY,和PASCAL的东西.

// In C
#define WINAPI __stdcall
extern WINAPI void someWin32Function(void);

// In D
extern( Windows ) void someWin32Function();

extern(System)在绑定OpenGL等库时有用.在窗口中用stdcall,在其他系统用cdecl.

// In C
#ifdef _WIN32
#include
#define MYAPI WINAPI
#else
#define MYAPI
#endif
extern MYAPI void someFunc(void);
// In D
extern(System) void someFunc();
//跟随系统走

实践中有许多技术来添加调用约定,要仔细检查头.在d中,可以统一起来,而不是挨个加:

//属性块
extern( C )
{
void functionOne();
double functionTwo();
}

//或这样
extern( C ):
void functionOne();

void functionTwo();


d曾经有Typedefs,其创建新类型,而不是别名.d的别名,则不创建新类型,只是另外一个名字.typedef已过时,除了在构中,别名是c的typedef在d的等价物.c中有大量typedef.

typedef int foo_t;
typedef float bar_t;

d接口中最好保留原型名.d接口要尽量兼容c接口.这样,示例啊,其他代码啊都可以容易的移植过来.

第一件事是如何将整/浮转至d.对接细节文档
这样:

alias int foo_t;
alias float bar_t;

注意长/正长.

// C头
typedef long mylong_t;
typedef unsigned long myulong_t;

//D模块
import core.stdc.config;

//导入是私,但别名是公,外部可见
alias c_long mylong_t;
alias c_ulong myulong_t;

长正长见入门

翻译c的stdint.h时,两种方法:

// From SDL_stdinc.h
typedef int8_t Sint8;
typedef uint8_t Uint8;
typedef int16_t Sint16;
typedef uint16_t Uint16;
...

// In D, 不用core.stdc.stdint
alias byte Sint8;
alias ubyte Uint8;
alias short Sint16;
alias ushort Uint16;
...

//用导入
import core.stdc.stdint;

alias int8_t Sint8;
alias uint8_t Uint8;
alias int16_t Sint16;
alias uint16_t Uint16;
...

用本地类型,长度固定,很直接.用core.stdc.stdint,复制了一份c头,用别名替换typedef.

关于python中如何移植c到d03就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. 移植libffi到SylixOS
  2. lua 移植到 android 记录

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python

上一篇:HIVE中执行hive的几种方式以及把HIVE保存到本地的几种方式的示例分析

下一篇:Hive抽样的相关知识点详解

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》