Created on 2001-03-21.00:00:00 last changed 171 months ago
[ Curaçao: additional rationale added. ]
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.
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.
[ This issue was first raised in 1999, but it slipped through the cracks. ]
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.
History | |||
---|---|---|---|
Date | User | Action | Args |
2010-10-21 18:28:33 | admin | set | messages: + msg2199 |
2010-10-21 18:28:33 | admin | set | messages: + msg2198 |
2010-10-21 18:28:33 | admin | set | messages: + msg2197 |
2010-10-21 18:28:33 | admin | set | messages: + msg2196 |
2001-03-21 00:00:00 | admin | create |