casting and enums (ButtonPolicies)

2000-08-31 Thread Lars Gullik Bjønnes


Seems to me that someone has not quite understood how to avoid casting
when working with enums.

First: whenevery you have to use a cast you should think: "Something fishy is going 
on, how can I avoid this."

Remember also when working with enums: c++ can overload operators so
that:

enum Button { one, two three };
inline Button operator|(Button a, Button b) {
return Button(a | b);
}
Button all = one | two | three;

will compile without warning, anoter option in this case is to use a
more special kind of "cast":
Button all = Button(one | two | three);

I have removed all casts from ButtonPolicies + changed what Angus did
you work around wrong use of casts. (casting a enum val to a ref to
int is _bad_)

Please try it out.

Lgb




Re: casting and enums (ButtonPolicies)

2000-08-31 Thread Allan Rae

On 31 Aug 2000, Lars Gullik Bjønnes wrote:

 Seems to me that someone has not quite understood how to avoid casting
 when working with enums.
 
 First: whenever you have to use a cast you should think: "Something
 fishy is going on, how can I avoid this."

That's what I was thinking.  I was also concerned why Dekel was getting
the warnings he was so we had some private discussions.  I was more
concerned with why he was getting warnings and I couldn't with any
compiler I have no matter what flags I used.  Although I can get a warning
from 2.95.2 when using -pedantic, complaining about using SMI_TOTAL where
it wants an integer.  Maybe that should be ButtonPolicy::SMI_TOTAL
instead?

 I have removed all casts from ButtonPolicies + changed what Angus did
 you work around wrong use of casts.

Thanks.  This looks more sensible.

 (casting a enum val to a ref to int is _bad_)

Definitely agree here.

Allan. (ARRae)




casting and enums (ButtonPolicies)

2000-08-31 Thread Lars Gullik Bjønnes


Seems to me that someone has not quite understood how to avoid casting
when working with enums.

First: whenevery you have to use a cast you should think: "Something fishy is going 
on, how can I avoid this."

Remember also when working with enums: c++ can overload operators so
that:

enum Button { one, two three };
inline Button operator|(Button a, Button b) {
return Button(a | b);
}
Button all = one | two | three;

will compile without warning, anoter option in this case is to use a
more special kind of "cast":
Button all = Button(one | two | three);

I have removed all casts from ButtonPolicies + changed what Angus did
you work around wrong use of casts. (casting a enum val to a ref to
int is _bad_)

Please try it out.

Lgb




Re: casting and enums (ButtonPolicies)

2000-08-31 Thread Allan Rae

On 31 Aug 2000, Lars Gullik Bjønnes wrote:

> Seems to me that someone has not quite understood how to avoid casting
> when working with enums.
> 
> First: whenever you have to use a cast you should think: "Something
> fishy is going on, how can I avoid this."

That's what I was thinking.  I was also concerned why Dekel was getting
the warnings he was so we had some private discussions.  I was more
concerned with why he was getting warnings and I couldn't with any
compiler I have no matter what flags I used.  Although I can get a warning
from 2.95.2 when using -pedantic, complaining about using SMI_TOTAL where
it wants an integer.  Maybe that should be ButtonPolicy::SMI_TOTAL
instead?

> I have removed all casts from ButtonPolicies + changed what Angus did
> you work around wrong use of casts.

Thanks.  This looks more sensible.

> (casting a enum val to a ref to int is _bad_)

Definitely agree here.

Allan. (ARRae)