有没有办法包装一个像关键字一样命名的结构(例如 print )?
我有一些 C 源代码,想将其包装在 Cython 中。现在的问题是,有一个名为 print
的结构,并且 externing 它会引发语法错误。
cdef extern from "foo.h":
struct print:
# ...
当像关键字一样调用属性或函数等时,也会出现同样的问题。
cdef extern from "foo.h":
struct foo:
bint print
print(char*, int)
有没有办法解决这个问题,无需修改源代码?也许有某种技术可以用源文件中的真实姓名替换代理名称?
I have some C
source code and want to wrap it in Cython. Now, the problem is, that there is a structure called print
, and externing it throws a syntax error.
cdef extern from "foo.h":
struct print:
# ...
Same problem would appear when an attribute or a function or alike is called like a keyword.
cdef extern from "foo.h":
struct foo:
bint print
print(char*, int)
Is there a way to work around this, without modifieng the source? Maybe some technique that replaces a proxy-name with the real-name in the source-file ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在寻找的解决方案类似于:
print.var 将被定义为:
这样您就可以从头文件中重命名结构、函数、联合和枚举。当 Cython 将代码编译为 C 代码时,名称会被转换。
Cython 文档的相关部分可以找到 此处。
I think the solution you are looking for is something along the lines of:
print.var will then be defined by:
This way you can rename structs, functions, unions and enums from the header file. The names are converted when Cython compiles your code into C code.
The relevant part of Cython documentation can be found here.