enums in C++
Phil Edwards
pedwards@jaj.com
Tue Apr 18 09:00:00 GMT 2000
Ulrich Drepper <drepper@redhat.com>:
> Nathan Sidwell <nathan@codesourcery.com> writes:
>
> > Remember, stuff inside `extern "C" { ... }' must still be valid
> > C++. Also remember, the set of overloaded functions named `foo' must
> > have distinct parameters, only one of the set can have C linkage.
>
> Yes, it must be valid C++ but the rules must be relaxed. It must be
> possible to call the functions the way you can do this in C.
The code /inside/ an extern-C block should have certain rules relaxed,
definitely. But I respectfully disagree that the /calling/ code should
have its language semantics silently changed by the linking convention of
the code being called. That way lies silent disaster.
> It simply does not help insisting that they write C++. You have to
> use C libraryies at some point and then you have to use their
> interface. If the interface is defined using enum of bit values then
> people can reasonably expect it to work just as in C.
Given your example, I would expect
foo (static_cast<ex_enum>(A | B))
to work exactly as it works in C. Perhaps I'm missing something -- what
do you find objectionable about that code?
> This is apparently how other C++ work. Otherwise this code wouldn't
> be in such wide use. At least relax the rules when using
> -fpermissive.
Aye, other C++ implementations get this wrong... I could see relaxing
the rules when using -fpermissive, though.
Phil
More information about the Gcc-bugs
mailing list