constants - 如何在 cython 中声明双 const* const* 变量?
问题描述
我在“example.h”中有一个 c++ 函数:
bool myFunc(double const* const* p);
我想用 cython 代码(在 .pyx 文件中)包装它。但是,当我编写以下代码时:
cdef extern from r"example.h":
bool myFunc(double const*const* p)
我收到以下错误:
编译 Cython 文件时出错:应为 ')',找到 '*'
并且 pycharm 在 double const* const* p 上显示此错误:
未解决的参考“常量”
我怎样才能声明那种变量?
解决方案
在 C/C++ 中,在哪里放置const
-qualifier 一直存在争议:要么
void foo(const int *a);
或者
void foo(int const *a);
两者意思相同。
Cython 中没有这样的战斗,因为它只接受第一个版本。
上述规则适用于double**
导致:
cdef extern from r"example.h":
bool myFunc(const double * const* p)
或者作为一种解决方法,可以完全放弃 const 限定符:
cdef extern from r"example.h":
bool myFunc(const double **p)
我不建议在大型项目中使用 const-qualifiers 在弄清楚会发生什么时有很大帮助。
推荐阅读
- javascript - 滚动停止时Anime.js停止动画
- java - 我在调试java多线程时犯了什么错误?
- php - imagick setimageformat 零大小图像字符串传递错误 - 许多错误之一 - svg 到 pdf
- amazon-web-services - 是否可以通过 NAT GW(到特定的外部 IP)从 aws 中的公共子网选择性地路由流量?
- python - 我在使用 pandas 和 list 进行深度学习正确输入时遇到问题
- ios - Swift/Xcode:如何检测按键?
- python - Google Colab 本地运行时连接错误
- javascript - Ember.js - 扩展 Bootstrap 插件的功能
- reactjs - 在 ReactJS 中,我可以“复制” Draggable 项目,以便拖动克隆并且原始项目保持在同一个地方吗?
- python - 如何获取 Kafka-python 消费者端最后 'n' 分钟内的数据(消息)