This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of CD1 status.
Section: 22.214.171.124 [headers], 18.4 [errno] Status: CD1 Submitter: Steve Clamage Opened: 2001-03-21 Last modified: 2016-02-10
Priority: Not Prioritized
View all other issues in [headers].
View all issues with CD1 status.
Exactly how should errno be declared in a conforming C++ header?
The C standard says in 7.1.4 that it is unspecified whether errno is a macro or an identifier with external linkage. In some implementations it can be either, depending on compile-time options. (E.g., on Solaris in multi-threading mode, errno is a macro that expands to a function call, but is an extern int otherwise. "Unspecified" allows such variability.)
The C++ standard:
I find no other references to errno.
We should either explicitly say that errno must be a macro, even though it need not be a macro in C, or else explicitly leave it unspecified. We also need to say something about namespace std. A user who includes <cerrno> needs to know whether to write errno, or ::errno, or std::errno, or else <cerrno> is useless.
Two acceptable fixes:
errno must be a macro. This is trivially satisfied by adding
#define errno (::std::errno)
to the headers if errno is not already a macro. You then always write errno without any scope qualification, and it always expands to a correct reference. Since it is always a macro, you know to avoid using errno as a local identifer.
errno is in the global namespace. This fix is inferior, because ::errno is not guaranteed to be well-formed.
[ This issue was first raised in 1999, but it slipped through the cracks. ]
Change the Note in section 126.96.36.199p5 from
Note: the names defined as macros in C include the following: assert, errno, offsetof, setjmp, va_arg, va_end, and va_start.
Note: the names defined as macros in C include the following: assert, offsetof, setjmp, va_arg, va_end, and va_start.
In section 19.3, change paragraph 2 from
The contents are the same as the Standard C library header <errno.h>.
The contents are the same as the Standard C library header <errno.h>, except that errno shall be defined as a macro.
C++ must not leave it up to the implementation to decide whether or not a name is a macro; it must explicitly specify exactly which names are required to be macros. The only one that really works is for it to be a macro.
[Curaçao: additional rationale added.]