🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #562

Re: scope of enumerators

#562
From: Tony L. Hansen
Date: Thu, 16 Nov 1989 15:28
27 lines
1655 bytes
<> Consider the following:
<>     struct color {
<> 	enum { red, green, blue }   type;
<>     };
<>     main() {
<> 	struct color favourite;
<> 	favourite.type = red;
<>     }
<> If this piece of code is compiled with g++ (1.35.0) or AT&T cfront (1.20)
<> both compilers complain about `red' in line 10 being undefined or
<> undeclared, resp.  gcc (1.35.0) and Sun cc compile without problems.

< I have used 'enum' this way (i.e. assuming it scopes) and I find it very
< useful for making code more readable (and more typesafe, because C++ (2.0)
< actually typechecks enums as separate types). I would think gcc and Sun cc
< are busted.

This is one of the few places where C++ is not a superset of C. In C++, the
scope of the enum is restricted to the class; in C, the enum has the same
scope as the structure.

Gcc and Sun cc aren't broken; they're doing exactly what they're supposed to
do.

					Tony Hansen
				att!pegasus!hansen, attmail!tony
				    hansen@pegasus.att.com
Technical Details
Message-ID: <4258@pegasus.ATT.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!uunet!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!samsung!rex!wuarchive!udel!princeton!att!dptg!pegasus!hansen
References: <2113@isaak.isa.de> <1404@odin.SGI.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!uunet!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!samsung!rex!wuarchive!udel!princeton!att!dptg!pegasus!hansen
From: hansen@pegasus.ATT.COM (Tony L. Hansen)
Newsgroups: gnu.g++.bug,comp.lang.c++
Subject: Re: scope of enumerators
Summary: no bug in C, one of the few differences between C and C++
Keywords: C, ANSI C, C++
Message-ID: <4258@pegasus.ATT.COM>
Date: 16 Nov 89 15:28:22 GMT
References: <2113@isaak.isa.de> <1404@odin.SGI.COM>
Reply-To: hansen@pegasus.ATT.COM (Tony L. Hansen)
Followup-To: gnu.g++.bug
Distribution: gnu, world
Organization: AT&T Bell Labs Middletown/Lincroft NJ USA
Lines: 27