I tried searching the standards but couldn't find anything specific regarding errno
.
What I mean is some implementations define errno
as a global variable while some define it as a macro
#define errno (*_err_no())
The standard doesn't include it in the list of reserved keywords for identifiers.
This means that I should be able to use errno as a local variable. While it should be fine for the first implementation (that defines it as a global), the second one wouldn't be fine.
Is use of errno
implementation defined or am I missing something?
From the latest C11 draft (N1570), 7.5 Errors <errno.h>
(emphasis mine):
The header
<errno.h>
defines several macros, all relating to the reporting of error conditions.The macros are
EDOM EILSEQ ERANGE
which expand to integer constant expressions with type
int
, distinct positive values, and which are suitable for use in#if
preprocessing directives; anderrno
which expands to a modifiable lvalue that has type
int
and thread local storage duration, the value of which is set to a positive error number by several library functions. If a macro definition is suppressed in order to access an actual object, or a program defines an identifier with the nameerrno
, the behavior is undefined.
This pretty clearly defines errno
as a macro, and reserves its name in all scopes.