c++ - 声明 `errno` 时出现编译时错误

标签 c++ linux

在Linux上编译我的C++程序的过程中,出现如下警告:

warning #584: omission of exception specification is incompatible with previous function "__errno_location" (declared at line 43 of "/usr/include/bits/errno.h")
extern int errno;//error handling
         ^

代码如下:

#include <errno.h>    //for error handling
#include <cmath>
#include <cstring>
#include <ctime>

extern int errno;//error handling

errno是一个全局变量,在其他.cpp文件中使用。我该如何解决这个问题?

最佳答案

errno必须是“可修改的左值”,不一定是声明的对象。

显然在您的实现中,errno扩展为一个表达式,其中包含对名为 __errno_location 的函数的调用.

在你自己的声明中:

extern int errno;

errno扩展为该表达式,导致错误。

<errno.h> 已经声明errno对您来说,没有必要自己声明,正如您所见,您不能自己声明。

只需省略 extern声明。

关于c++ - 声明 `errno` 时出现编译时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19417623/

相关文章:

c++ - 仅黑色窗口绘制三角形,在 MacOS 上使用 openGL 和 GLUT 与 Xcode

linux - 重新启动 Linux 工作站时与日志文件相关的 pbs_mom 问题

c++ - Clang VS VC++ :"error: declaration of ' T'阴影模板参数”

c - pthread - 条件信号和等待

python - 关于执行 cron 作业的菜鸟问题

linux - 为什么我不能 sudo 回显/etc/中的一行?

linux - 使用 telnet 的 HTTP 请求没有得到任何响应

c++ - sd_journal_send 发送二进制数据。如何使用 journalctl 检索数据?

c++ - 我可以将 std::map 的内容 move 分配到另一个 std::map 吗?

c++ - 可以递归解析 va_list 中的参数吗?