Re: enums ... what am I doing wrong?

From: Hans Kesting (news.2.hansdk_at_spamgourmet.com)
Date: 11/11/04


Date: Thu, 11 Nov 2004 10:21:59 +0100

Craig wrote:
> Newbie...
>
> I'm casting enums back and forth to ints so to use them as an index
> into a complex two dimensional array. I thought it would help
> readability. Instead, my code has casts all over the place.
>
> All the casting is giving me the jitters. Where did I go wrong?
>
> Thanks!

How about using constants instead of enum values?
* same readability of enum (words instead of "magic numbers")
* they really are int's

public const int WHATEVER = 3;
myval = store[WHATEVER];

Hans Kesting



Relevant Pages

  • Re: something like switch in c
    ... I have to insert the name in the enum list as well. ... use a switch with the enum values. ... Readability, ... darrell at cs dot toronto dot edu ...
    (comp.programming)
  • Re: String or Numeric Variable?
    ... it appears that using numeric constants will solve the 'readability' ... >>issue and Enum perhaps more efficient? ... > Const Afternoon As Long = 2 ... > Dim TimeOfDay as TOD ...
    (comp.lang.basic.visual.misc)
  • Re: String or Numeric Variable?
    ... it appears that using numeric constants will solve the 'readability' ... >issue and Enum perhaps more efficient? ... Const Afternoon As Long = 2 ... Dim TimeOfDay as TOD ...
    (comp.lang.basic.visual.misc)
  • Re: Anonymous Struct Members / Struct Constants
    ... bitposition could be defined in an enum which will improve your ... readability. ... I presume you're talking about 8 bit core with a dedicated operation ...
    (comp.lang.verilog)
  • Re: enum question.
    ... Why is compiler not even warning about it? ... In C an enum ... because the values are ints and can be the results of ...
    (comp.lang.c)