【发布时间】:2018-09-16 11:34:17
【问题描述】:
最新版本的 python 2.7 (2.7.13) 包含一个使用 register 关键字的标题 unicodeobject.h。我的理解是 C++ 17 有 removed 这个关键字。当使用 C++ 17 对该头文件进行编译时,会触发一系列警告,包括:
/opt/anaconda/include/python2.7/unicodeobject.h:534:24: warning: ISO C++1z does not allow ‘register’ storage class specifier [-Wregister]
register PyObject *obj, /* Object */
^~~
/opt/anaconda/include/python2.7/unicodeobject.h:553:24: warning: ISO C++1z does not allow ‘register’ storage class specifier [-Wregister]
register PyObject *obj /* Object */
^~~
/opt/anaconda/include/python2.7/unicodeobject.h:575:29: warning: ISO C++1z does not allow ‘register’ storage class specifier [-Wregister]
register const wchar_t *w, /* wchar_t buffer */
^
/opt/anaconda/include/python2.7/unicodeobject.h:593:23: warning: ISO C++1z does not allow ‘register’ storage class specifier [-Wregister]
register wchar_t *w, /* wchar_t buffer */
也就是说,尽管有这些警告,我仍然能够编译和运行 python 扩展。继续这样做是否安全?有没有办法(除了明确忽略警告)来解决这些消息,例如升级到 2.7 的不同版本(尽管如前所述,最新版本似乎仍然使用 register 关键字)?
【问题讨论】:
-
register是一个优化提示。编译器可能会忽略它。您可以随时更改构建脚本以添加-Dregister=(删除它)或添加-Wno-register -
作为一个小提示,Python 2.7(和一般的 Python 2)将达到他们的end of life by the end of 2019,所以如果 Python 3 没有发生这种情况,您可能需要考虑切换到它。跨度>
标签: python c++ python-2.7 c++17