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: 16.4.2.3 [headers], 19.4 [errno] Status: CD1 Submitter: Steve Clamage Opened: 2001-03-21 Last modified: 2016-01-28
Priority: Not Prioritized
View all other issues in [headers].
View all issues with CD1 status.
Discussion:
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. ]
Proposed resolution:
Change the Note in section 17.4.1.2p5 from
Note: the names defined as macros in C include the following: assert, errno, offsetof, setjmp, va_arg, va_end, and va_start.
to
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>.
to
The contents are the same as the Standard C library header <errno.h>, except that errno shall be defined as a macro.
Rationale:
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.]