Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile-time error on declaration of `errno`

Tags:

c++

linux

During the process of compilation of my C++ program on Linux, it gives the following warning:

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
         ^

The code is shown below:

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

extern int errno;//error handling

errno is a global variables, it is used in other .cpp files. How can I solve this?

like image 546
kenan Avatar asked Oct 17 '13 03:10

kenan


1 Answers

errno is required to be a "modifiable lvalue", not necessarily a declared object.

Apparently on your implementation, errno expands to an expression that includes a call to a function called __errno_location.

In your own declaration:

extern int errno;

errno expands to that expression, resulting in an error.

Since <errno.h> already declared errno for you, there's no need to declare it yourself, and as you've seen, you can't declare it yourself.

Just omit that extern declaration.

like image 108
Keith Thompson Avatar answered Oct 31 '22 21:10

Keith Thompson