2 ms·
errno is a macro on most (maybe every) platform supporting pthreads. Furthermore, C11 literally defines errno as a macro in 7.5p1: The macros are
by wahern 10y ago
errno is a macro on most (maybe every) platform supporting pthreads.
Furthermore, C11 literally defines errno as a macro in 7.5p1:
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; and
errno
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 name errno, the behavior is undefined.
Notably, C11 introduced an optional threading API, effectively derived from the common functionality between Window's threading API and POSIX pthreads. While I can imagine ways to have a unique errno symbol that doesn't rely on macros, the obvious solution does and there's little reason not to use it.
While C11 is most definitely not the same thing as C++11, I think, similar to atomics, the committees cooperated on the threading API. I don't have a recent C++ standard handy at the moment, but I wouldn't be surprised if C++11 at least allowed defining errno as a macro.