Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
10.5 Iterating over an enum
#1
I usually define a enum in a project specific H file, to represent a set of signals:
typedef enum {
ADC_VBAT
ADC_FEEDBACK,
ADC_VOLTAGE,

ADC_NUM_SIGNALS
} adc_t ;

And then in the reusable C file, iterate over the configured set of signals. For example, to set the initial value of the averaged signal:

uint8_t i ;

for (i=0U; i < (uint8_t) ADC_NUM_SIGNALS; i++)
{
AdcClearAverage((adc_t) i) ;
}

where AdcClearAverage takes a parameter of type adc_t.

But this now generates warning 10.5 as an unsigned type is being cast to an enum.
What is the correct way to iterate over an enumeration?
<t>Dermot</t>
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 4 Guest(s)