Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 带Cython的条件'ctypedef'_Python_C_Cython - Fatal编程技术网

Python 带Cython的条件'ctypedef'

Python 带Cython的条件'ctypedef',python,c,cython,Python,C,Cython,我需要从stdint.h中访问我正在编写的一些包装器代码中的uint64_ttypedef,但我不知道如何完成它。问题是,从文档中可以看出,我的ctypedef必须采用以下形式: ctypedef unsigned long uint64_t 或 取决于WORDSIZEfrombits/WORDSIZE.h是64还是32。我还没有找到如何从Cython访问这个预处理器定义的方法,如果可以的话,Cython似乎不喜欢if语句中的ctypedef语句,当我试图将if语句放入cdef块时,它似乎把它

我需要从
stdint.h
中访问我正在编写的一些包装器代码中的
uint64_t
typedef,但我不知道如何完成它。问题是,从文档中可以看出,我的
ctypedef
必须采用以下形式:

ctypedef unsigned long uint64_t

取决于
WORDSIZE
from
bits/WORDSIZE.h
是64还是32。我还没有找到如何从Cython访问这个预处理器定义的方法,如果可以的话,Cython似乎不喜欢
if
语句中的
ctypedef
语句,当我试图将
if
语句放入
cdef
块时,它似乎把它与声明混淆了。有什么想法吗?希望我只是错过了一些基本的东西

cdef extern from "stdint.h":
    ctypedef unsigned long long uint64_t
任何
ctypedef
extern
'd的文件都不会在.c文件中生成typedef。Cython将包含
stdint.h
,并且您的C编译器将从那里使用实际的typedef


提供的类型唯一重要的事情是cython何时生成在C类型和Python类型之间自动转换的代码。使用
unsigned long long
意味着Cython将使用unsigned long中的
PyLong\u和
PyLong\u作为long和overflow
。这样,您希望在转换时不会得到任何截断。

Cython在模块中已经包含了以下定义:


完美的这正是我在此期间所使用的。我不需要改变任何事情。现在回想起来,我可能已经想到检查生成的C文件了。
cdef extern from "stdint.h":
    ctypedef unsigned long long uint64_t
from libc cimport stdint

ctypedef stdint.uint64_t foo