delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/19/13:47:49

Message-ID: <35B1DF3B.B1A11B6@ipass.net>
From: Terry <iceman AT ipass DOT net>
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Bug? Or am I misusing something?
References: <35b19846 DOT 0 AT news DOT mountain DOT net>
Lines: 46
Date: Sun, 19 Jul 1998 12:03:33 GMT
NNTP-Posting-Host: ts8-155-ppp.ipass.net
NNTP-Posting-Date: Sun, 19 Jul 1998 08:03:33 EDT
Organization: iPass.Net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Tom Leete wrote:
> 
>     Hi, if I'm being boneheaded about something please hurry to tell me.
> Aren't enums supposed to be distinct types, with their element names
> overloaded?
> 
> // file- tenum.cpp - combines tenum.cpp with tenum.h
> enum definiteAnswer{ no, yes};
> enum anyAnswer{ no, yes, maybe};
> int main(int,char**)
> {
>     definiteAnswer A;
>     anyAnswer B;
>     return 0;
> }
> 
 ******** Some stuff clipped out ******

> In file included from tenum.cpp:4:
> ../include/tenum.h:12: conflicting types for `0'
> ../include/tenum.h:6: previous declaration as `enum definiteAnswer const no'
> ../include/tenum.h:13: conflicting types for `1'
> ../include/tenum.h:7: previous declaration as `enum definiteAnswer const
> yes'
> tenum.cpp: In function `int main(int, char **)':
> tenum.cpp:9: warning: unused variable `enum anyAnswer B'
> tenum.cpp:8: warning: unused variable `enum definiteAnswer A'
> bash$
> *********
> 
> Why does gcc think I'm trying to redeclare global `0' and `1'?
> I think that this is pretty wrong, but I dont see how it could have been
> missed.

I think "no" and "yes" are being redefined as different types --
definiteAnswer and anyAnswer.

As for the type issue, you can use:
   typedef enum {noDefinite, yesDefinite} definiteAnswer;
   typedef enum {noAny,yesAny,maybeAny} anyAnswer;

if you want to be sure the enums become types.

Hope this helps.

Terry

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019