www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/16/23:37:20

From: sparhawk AT eunet DOT at (Gerhard Gruber)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: enum problem
Date: Mon, 15 Jun 1998 18:31:52 GMT
Organization: Customer of EUnet Austria
Lines: 41
Message-ID: <358745c4.10851789@news.Austria.EU.net>
References: <bWLoegW7sFse-pn2-0JB8f0w8xHdR AT portX61 DOT lanzen DOT net>
NNTP-Posting-Host: e223.dynamic.vienna.at.eu.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Destination: sl AT psycode DOT com DOT NOSPAM (Gili)
From: Gruber Gerhard
Group: comp.os.msdos.djgpp
Date: 14 Jun 1998 18:36:22 GMT:

>	I have the following code:
>
>"enum listing
>{
>  a=0x00,
>  b=0x02
>};
>
> function(listing input)
>{
>}
>"
>
>	Now, in my main() code I use "function(a|b)" and DJGPP reports that 
>my argument should be an "int" not a type "listing".. Which makes no 
>real sense.. There is no need to expand the size to an "int" because 
>any element of type "listing" when || (ORed) with another element will
>always remain within the confines of the listing-type.. Well, that's a

That's right. But with enum the compiler keeps track of the value to the name
associated with the value. The advantage is that with enum you can show the
name in the debugger. Now when you or together two values the resulting value
has no valid name for that enum and this is what gcc is complaining about. You
can either define names for all possible values (not really recommended
usually) or, if you want to use the enum only as bits then you could use
bitfields. This way you can identify each value and you don't have to bother
to or them together (or and them apart).

--
Bye,
   Gerhard

email: sparhawk AT eunet DOT at
       g DOT gruber AT sis DOT co DOT at

Spelling corrections are appreciated.

- Raw text -


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