enum problem

Werner Modenbach modenbach at alc.de
Thu Oct 25 07:41:01 BST 2001


On Donnerstag, 25. Oktober 2001 05:43 Phil wrote / Am Donnerstag, 25. Oktober 
2001 05:43 schrieb Phil:
> Hello all,
>
> I'm trying to use an enumerated type in an effort to avoid using a large
> switch/case block, but I don't think that it's possible.
>
> The following is a simplified example of what I'm trying to achieve.
>
> enum Mode {a,b,c};
> Mode mode;
>
> mode = (Mode) data[4];
>
> Data[4] is an unsigned char type and can have a value of 0,1 or 2 so mode
> will equal a, b or c at this point. So far so good.
>
> What I want to do now is print mode so that it is either a, b or c NOT 0,1
> or 2. Something like printf("Mode = %d\n", mode).
>
> Of course a switch statement works but Mode can have many more values that
> the 3 used in this example and so the switch block can be quite large. Is
> there a way to avoid this?

why don't you do a second array of names:

char modenames[] = {'a', 'b', 'c', 'd'};
printf("Mode = %c\n", modenames[(int)mode]);

- Werner -

-- 
--------------------------------------------------------------
                    ALC Computertechnik GmbH

        \_       \_          \_\_\_     Kaiserstr. 100
       \_\_      \_        \_           D-52134 Herzogenrath
      \_  \_     \_        \_           Germany
     \_\_\_\_    \_        \_           Fon +49 2407 95810
    \_      \_   \_        \_           Fax +49 2407 958139
   \_        \_  \_\_\_\_    \_\_\_     http://www.alc.de
   ===========================================================
   Werner Modenbach                     modenbach at alc.de
--------------------------------------------------------------

-
to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
unsubscribe »your-email-address«



More information about the KDevelop mailing list