[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FW: [avr-gcc-list] Dumb C question
From: |
J.C. Wren |
Subject: |
FW: [avr-gcc-list] Dumb C question |
Date: |
Fri, 16 Aug 2002 15:39:03 -0400 |
I don't know of a way equivalent to sizeof(), but I usually do it like this
typedef enum
{
menuItem_zero = 0,
menuItem_next,
menuItem_another
menuItem_MAX
}
menuItem_e
I denote structs with _s, types with _t and enums with _e on the ends. I
use typedefs for just about everything, since this allows type checking, and
even cooler, switch statements that tell you if you don't check every case
with no default.
I also prefix each enum with the typedef name, since enums are globally
scoped (unlike structs, where the structure element is locally scoped to the
struct definition). At a glance, this allows me to tell what enum it's a
member of.
And because old ways sometimes die hard, I always initialize the first
element of the enum. I was taught this by someone who had been bit by a
compiler that started enums at 1 instead of 0 (Dog knows why...), and it
imposes no addition cost.
--John
-----Original Message-----
From: address@hidden [mailto:address@hidden
Behalf Of Larry Barello
Sent: Friday, August 16, 2002 12:18
To: AVR GCC List
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
- FW: [avr-gcc-list] Dumb C question,
J.C. Wren <=
- [avr-gcc-list] Dumb C question, Larry Barello, 2002/08/31
- Re: [avr-gcc-list] Dumb C question, Jesper Hansen, 2002/08/31
- Re: [avr-gcc-list] Dumb C question, Jeff Dairiki, 2002/08/31
- Re: [avr-gcc-list] Dumb C question, Theodore A. Roth, 2002/08/31
- Re: [avr-gcc-list] Dumb C question, Mike Tsao, 2002/08/31
- Re: [avr-gcc-list] Dumb C question, Harald Kipp, 2002/08/31