avr-gcc-list
[Top][All Lists]
Advanced

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

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


From: Jesper Hansen
Subject: Re: [avr-gcc-list] Dumb C question
Date: Fri, 16 Aug 2002 19:57:00 +0200

You probably already know this, but anyway.....

One easy way is :

enum eMenuItem
{
     D_this,
     D_that,
     D_TheOtherThing,
     D_Last_Enum
}

The size is then simply D_Last_Enum

But as enum's can have init values like :

enum eMenuItem
{
     D_this = 50,
     D_that,
     D_TheOtherThing = 60,
     D_Last_Enum
}

D_Last_Enum would be wrong, so it's not foolproof.

As far as I know, there's no way to do it with sizeof ( ) .


/Jesper


----- Original Message -----
From: "Larry Barello" <address@hidden>
To: "AVR GCC List" <address@hidden>
Sent: Friday, August 16, 2002 6:17 PM
Subject: [avr-gcc-list] Dumb C question


> 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.e.
>
> enum eMenuItem
> {
>     D_this,
>     D_that,
>     D_TheOtherThing
> }
>
> If I say "sizeof(enum eMenuItem)" I just get 2, which of course is the
size
> of the enum.
>
> Cheers!
>
> avr-gcc-list at http://avr1.org
>


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



reply via email to

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