[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Dumb C question

From: Jeff Dairiki
Subject: Re: [avr-gcc-list] Dumb C question
Date: Fri, 16 Aug 2002 11:37:40 -0700

On Fri, 16 Aug 2002 09:17:34 -0700
"Larry Barello" <address@hidden> wrote:

> I am slogging into the future and learning how to use "enums".  Is there
> an elegant way to find out how many items there are in a particular
> enum?

I don't think there's a "built in" way to do this.  It clashes
a bit with the zen of enums, I think...  (Why do you need to know
the number of values in the enum?)

One way (I think the "normal one") is something like:

  enum my_state_e {

This relies on the fact that the enum values are assigned 
values starting from 0 (by default).  So the (int) value of
STATE_INIT is 0, and the value of NUM_STATES is 4.

avr-gcc-list at http://avr1.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]