Errno is an int or macro in errno.h
I saw this code:
#if !defined(errno)
extern int errno;
#endif
So my question is whether errno
int or a macro, because with #if
if it is possible to check a macro defined or not and after we doextern int errno;
in errno.h is defined like this
#ifdef _ERRNO_H
/* Declare the `errno' variable, unless it defined as a macro by
bits/errno.h. This is the case in GNU, where it is a per-thread
variable. This redeclaration using the macro still works, but it
will be a function declaration without a prototype and may trigger
a -Wstrict-prototypes warning. */
#ifndef errno
extern int errno;
#endif
#endif
source to share
In C ++ (since n3376) errno is defined as a macro if you include <cerrno> otherwise if you include <errno.h> this is what is defined in C (int int I suspect given the above ( but you need to look at the C standard (according to Alok below: "It is not specified if errno is a macro or an identifier"))).
n3376:
19.4 Error numbers [errno]
The <cerrno> header is described in Table 43. Its contents are the same as the POSIX header <errno.h>, except that errno must be defined as a macro.
source to share
Check out http://www.cplusplus.com/reference/cerrno/errno/ . The standard seems to define errno as a macro for C ++.
This macro expands to a modifiable int value l, so it can be read and modified by the program.
In C ++, errno is always declared as a macro, but in C it can also be implemented as an int object with external linkage.
cppreference adds some details regarding C ++ 11.
errno is a preprocessor macro that expands to a static (pre C ++ 11) / thread-local (since C ++ 11) modifiable int l value.
source to share