P
Peter Tipton
/* Let's say I have an enum: */
enum Leds {
FIRST_LED = 0,
LED_RED = FIRST_LED,
LED_YLW,
LED_GRN,
NUM_LEDS
};
/* And a driver function (elsewhere) */
void turnOnLeds(enum Leds led);
/* And a function that wants to turn all the LED's on: */
void cycleLeds(void)
{
enum Leds led;
for (led = FIRST_LED; led < NUM_LEDS; ++led) /* <-- Line in question
*/
{
turnOnLed(led);
}
}
Now, on the line in question, should ++led be legal? I can see how it
might
not be but I'm sure I've done this before without compiler errors being
generated. So should I be able to increment an enum variable or not?
Thanks.
enum Leds {
FIRST_LED = 0,
LED_RED = FIRST_LED,
LED_YLW,
LED_GRN,
NUM_LEDS
};
/* And a driver function (elsewhere) */
void turnOnLeds(enum Leds led);
/* And a function that wants to turn all the LED's on: */
void cycleLeds(void)
{
enum Leds led;
for (led = FIRST_LED; led < NUM_LEDS; ++led) /* <-- Line in question
*/
{
turnOnLed(led);
}
}
Now, on the line in question, should ++led be legal? I can see how it
might
not be but I'm sure I've done this before without compiler errors being
generated. So should I be able to increment an enum variable or not?
Thanks.