I have seen this code:
#if !defined(errno)
extern int errno;
#endif
So my question is whether errno is int or macro , because with #if if can check macro defined or not and after we are doing extern int errno;
in errno.h it is defined like this
#ifdef _ERRNO_H
/* Declare the `errno' variable, unless it's 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
In C++ (as of n3376) errno is defined as a macro if you include <cerrno> otherwise if you include <errno.h> it is whatever it is defined in C (an int I suspect given the above (but you need to look at the C standard (As per Alok below: "It is unspecified whether errno is a macro or an identifier"))).
The header <cerrno> is described in Table 43. Its contents are the same as the POSIX header <errno.h>, except that errno shall be defined as a macro.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With