声明'errno'时发生编译时错误` 在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 ^
代码如下所示:声明'errno'时发生编译时错误` 在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 ^,c++,linux,C++,Linux,代码如下所示: #include <errno.h> //for error handling #include <cmath> #include <cstring> #include <ctime> extern int errno;//error handling #包含//用于错误处理 #包括 #包括 #包括 外部内部错误//错误处理 errno是一个全局变量,用于其他.cpp文件。如何解决此问题?errno必须是“可修改的左值”
#include <errno.h> //for error handling
#include <cmath>
#include <cstring>
#include <ctime>
extern int errno;//error handling
#包含//用于错误处理
#包括
#包括
#包括
外部内部错误//错误处理
errno
是一个全局变量,用于其他.cpp
文件。如何解决此问题?errno
必须是“可修改的左值”,而不一定是声明的对象
显然,在您的实现中,errno
扩展为一个表达式,其中包含对名为\uuuuuuerrno\ulocation
的函数的调用
在你自己的声明中:
extern int errno;
errno
扩展到该表达式,导致错误
由于
已经为您声明了errno
,因此不需要自己声明,正如您所看到的,您不能自己声明
只需省略
extern
声明。当它已经在errno.h
中声明时,为什么要声明errno
?更重要的是:errno.h
已经声明errno
,所以不要试图自己声明它。在今天的系统上,errno
不能是一个普通的标量变量来兼容多线程。