声明“errno”时出现编译时错误
Compile-time error on declaration of `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
^
代码如下所示:
#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
声明。
相关文章:
- 在缺少函数重载时抛出异常,并带有 std::variant 而不是编译时错误
- 如何在常量计算表达式中获取编译时错误?
- C++根据调用的构造函数强制编译时错误
- 使用 std::iterator_traits<> 时编译时错误不明确
- is_same和variadic模板编译时错误无效转换
- 私有运营商删除会触发 GCC 和 Clang 的编译时错误,但不会在 MSVC 上触发编译时错误
- 运行时与编译时多态性:更好的可读性与编译时错误检查,更重要的是
- 引发编译时错误
- 为什么调用不明确的 ctor 时没有编译时错误?
- 在 sizeof 运算符上强制编译时错误
- 未经授权的私有类成员访问会产生编译时错误而不是运行时错误?
- 从Mac上的终端编译时C 错误
- 使用MINGW-W64使用-M32选项(32位代码)编译时错误
- C++线程错误 - 带有类参数的编译时错误
- 如果编译时间构量参数是错误的,则生成编译时错误
- 尝试调用指向成员函数的函数指针时出现编译时错误
- 编译时错误:删除了联合默认构造函数
- 初始化启动对象时出现编译时错误
- 如果在C++中将成员添加到类中,则会导致编译时错误的技术
- 声明“errno”时出现编译时错误