c - 使用 .h 文件中声明的 C 类型

标签 c cython typedef python-2.x

我想在我的 .pyx C 类型中使用在我的 .h 文件中声明的 typedef:

//decls.h
typedef double Doub
typedef long int LInt
//etc...

我的简单解决方法是在我的 *.pxd 中重新声明它们(即将我的 .h block 复制粘贴到我的 .pxd 中,替换 typedef-->ctypedef)。 现在我正在使用另一个带有大量 typedef 语句的 .h ,所以我想要一种更“cythonic”的声明方式。 我一直在读this ,但没有帮助我。 也许类似?:

# .pxd cython file
cdef extern from "decls.h":
    Doub # no idea what to put before `Doub`

最佳答案

如果唯一的区别是 typedef 中的 c,那么您可以使用 C 预处理器将 .h 文件预处理为以下文件:可以由 cython 处理。例如:

// a .c file:
#define CTYPEDEF typedef
#include "mytypes.h"

// the "mytypes.h" for cython preprocessing
#ifndef CTYPEDEF
# define CTYPEDEF ctypedef
#endif
CTYPEDEF ... myType;

在 makefile 或 IDE 中,制定规则来预处理 .h 文件,然后将输出包含到 cython 中。

如果还有更多差异,您可以按照相同的方式继续操作,并以此为例。

关于c - 使用 .h 文件中声明的 C 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40069058/

相关文章:

python - 一些 python/numpy 优化可能吗?

c - 使用数组创建单链表时的警告

c - 使用带有数组的 typedef struct 创建一个函数

python - Cython - 动态二维 C++ 数组的内存 View

python - 从 Cython 访问 Fortran 公共(public)变量

c - 使用 typedef 的 C 枚举类型的值

C中字符串中某些字符大写

在 C 中创建应用程序接口(interface)

c - uint32_t 和 u_int32_t 的区别

c - 如何在用 C 编写的 CGI 应用程序中使用系统命令执行批处理脚本,通过 Web 浏览器(Apache 服务器)执行