Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

errno is int or macro in errno.h

Tags:

c++

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 
like image 848
EmptyData Avatar asked Nov 29 '25 02:11

EmptyData


1 Answers

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"))).

n3376:

19.4 Error numbers [errno]

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.

like image 190
Martin York Avatar answered Nov 30 '25 15:11

Martin York



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!