www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/17/08:31:00

From: D DOT J DOT Eleveld AT anest DOT azg DOT nl
Newsgroups: comp.os.msdos.djgpp
Subject: Re: enum problem
Date: Wed, 17 Jun 1998 09:43:09 GMT
Organization: Deja News - The Leader in Internet Discussion
Lines: 54
Message-ID: <6m833d$lvq$1@nnrp1.dejanews.com>
References: <19980615072556700 DOT AAA231 AT portC17 DOT Generation DOT NET> <Pine DOT SUN DOT 3 DOT 91 DOT 980615174251 DOT 11003B-100000 AT is>
NNTP-Posting-Host: 192.87.23.66
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <Pine DOT SUN DOT 3 DOT 91 DOT 980615174251 DOT 11003B-100000 AT is>,
  Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> wrote:
>
>
> On Mon, 15 Jun 1998, sl wrote:
>
> > #include <stdio.h>
> >
> > enum lineType
> > {
> >   sLine=0x00,

Are you sure you mean sLine = 0x00?

> >   dLine=0x01,
> >   overwrite=0x02,
> > };
> > {
> >   saychoice(sLine|overwrite);
> > }

Are you trying to use the enum here like a bit field? Do you realize that
sLine==0 which means that it has no bits set, so ORing with anything doesn't
make a whole lot of sense.

I would suggest (in C++):

enum lineType
  {
  sLine = 1,
  dLine = 1<<1,
  overwrite = 1<<2
  };

lineType operator|(const lineType one, const lineType two)
  {
  return lineType((int)one | (int)two);
  }

Then you can do stuff like this:

saychoice(sLine|overwrite)

without any complaints from the compiler, and all your wierd casts are in one
easy to find and maintan place, where you user doesn't have to do the casts
them selevs, and possibly get it wrong and confuse the hell out of
everything...

Doug Eleveld



-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading

- Raw text -


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