我正在使用一些C++代码扩展Python.
我使用的其中一个功能有以下签名:
int PyArg_ParseTupleAndKeywords(PyObject *arg, PyObject *kwdict,
char *format, char **kwlist, ...);
Run Code Online (Sandbox Code Playgroud)
(链接:http://docs.python.org/release/1.5.2p2/ext/parseTupleAndKeywords.html)
感兴趣的参数是kwlist.在上面的链接中,给出了如何使用此功能的示例.在示例中,kwlist看起来像:
static char *kwlist[] = {"voltage", "state", "action", "type", NULL};
Run Code Online (Sandbox Code Playgroud)
当我使用g ++编译它时,我收到警告:
warning: deprecated conversion from string constant to ‘char*’
Run Code Online (Sandbox Code Playgroud)
所以,我可以将静态char*更改为静态const char*.不幸的是,我无法更改Python代码.因此,通过此更改,我得到了不同的编译错误(无法将char**转换为const char**).根据我在这里阅读的内容,我可以打开编译器标志来忽略警告,或者我可以将kwlist定义中的每个常量字符串转换为char*.目前,我正在做后者.有什么其他解决方案?
对不起,如果之前已经问过这个问题.我是新来的.