This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: enum declaration/definition bug


Harald Iwe <hiw@funcom.com> writes:

> The following program does not compile: 
> 
> enum Answer_e;
> 
> enum Answer_e
> {
>   ONE, TWO, TREE
> };
> 
> int
> main()
> {
>   return 0;
> }
> 
> Output:
> [hiw@hartmann tmp]$ g++ -g -Wall junk.cpp 
> junk.cpp:2: use of enum `Answer_e' without previous declaration
> junk.cpp:6: multiple definition of `enum Answer_e'
> 
> 
> Operating System : Linux 2.1.115
> Compiler : gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
> 

After some more research on the C++ language standard I belive the
egcs 1.1 compiler is right. You cannot forward declare an enum. At
least that was the conclusion when I asked on
comp.lang.c++.moderated. My motivation for doing it was to reduce
dependencies between files. 

Interesting fact: The MIPSpro C++ compiler Version 7.2.1 (Silicon
Graphics), DIGITAL C++ V6.0-021 (Digital) and VC++ 5.0 (Microsoft) all
compiles the code with no warnings or errors. They are apparently all
wrong.

-- 
Harald Iwe, hiw@funcom.com
Funcom Oslo A/S, Karenlyst alle' 5, N-0277 Oslo, Norway
Tel. +47 22-925963, Fax. +47 22-420302


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]