enums in C++
Ulrich Drepper
drepper@redhat.com
Tue Apr 18 02:28:00 GMT 2000
I haven't looked through the standards to see what (if anything) is
demanded to be done in this situation. I came accross thie while, you
guess it, compiling mozilla.
Take the following code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
enum ex_enum
{
NADA,
A = 1,
B = 2
};
extern "C" int
foo (ex_enum arg)
{
switch (arg)
{
case 0:
return 0;
case A:
return 1;
case B:
return 2;
#ifdef IS_THIS_LEGAL
case A | B:
return 3;
#endif
}
return 0;
}
int
bar (int a)
{
return a + foo (A | B);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compiling this with the current egcs mainline (2000-4-17T18:00-0700)
with
gcc -O -Wall -c u.cc
leads to this message (I've seen this now for some time):
u.cc: In function `int bar (int)':
u.cc:31: cannot convert `int' to `ex_enum' for argument `1' to `foo
u.cc:31: (ex_enum)'
u.cc:32: warning: control reaches end of non-void function `bar (int)'
In C this is perfectly legal. It's a nice way to make symbolic names
visible in the debugger when preprocessor macros are simply discarded.
How is the situation in C++? And especially here, when calling a C
function?
--
---------------. drepper at gnu.org ,-. 1325 Chesapeake Terrace
Ulrich Drepper \ ,-------------------' \ Sunnyvale, CA 94089 USA
Red Hat `--' drepper at redhat.com `------------------------
More information about the Gcc-bugs
mailing list