Quote Originally Posted by ridgerunnersjw View Post
I have a type enum and would like to use the sizeof command to get a value....Can I do this? For instance my enum is:

Code:
typedef enum {EMPTY, RST, PWM_DIV, PWM_DUTYCYCLE, DAC_REF, ADC_SAMP_TIME = 8, ADC_NUM_SAMPLES, ADC_CONV} commands
I would like to do sizeof(commands) and get back 8....if I run as is I get back 2 which presumably is the size of a type enum

Thanks
From what I see I think you're misunderstanding what sizeof does, for starters sizeof(commands) will, in general, be equal to sizeof(int), that is the sizeof of what will contain the values of your enums, not the count of them. Secondly to get the count you could do something as simple as this:

Code:
typedef enum
{
	EMPTY = 0,
	RST,
	PWM_DIV,
	PWM_DUTYCYCLE,
	DAC_REF,
	ADC_SAMP_TIME = 8,
	ADC_NUM_SAMPLES,
	ADC_CONV,
	LAST_CMD_MARKER,
	CMD_COUNT = DAC_REF + (LAST_CMD_MARKER - SAMP_TIME)
} commands;
Might be 1 off with the count, I didn't bother with a math check since it was off the top of my head, can just add - 1 to the end if it is, anyways CMD_COUNT would then hold what you were looking for.