This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC 3.0.2: errno conflict.
On Fri, Dec 14, 2001 at 03:51:09PM -0800, Joe Buck wrote:
> Maxim Dementiev writes:
> > This code compile with error by g++ 3.0.2 on Linux 2.2.19 (i386).
> > If rename "errno" to "errno1" - all works fine.
> > Is it a bug?
>
> [ testcase uses errno as an identifier, and there is a collision with
> the errno macro in glibc, but the only #include was for <iostream> ]
>
> I think that the conclusion is that, since you did not include <errno.h>
> or <cerrno> explicitly, there is a bug. errno is allowed to be a macro,
> but only if you ask for one of these headers, which you did not.
In C++, errno is required to be a macro. Further, it is a reserved name
if _any_ standard C++ header is included.
Any code that includes a standard header and tries to use errno in any
way incompatible with its role in the C library is wrong.
In general, any C library name that may need to be implemented as a
macro (errno, va_*, offsetof) is required to be a macro in C++; all
the others are required not to be macros (although that is violated
in current libstdc++). Further, including any C++ header causes all
C library names (excluding new C99 names) to be reserved: the non-macro
names in global scope, and the macro names in all scopes.
Nathan Myers
ncm at cantrip dot org