C_guy said:
I noticed that
typedef enum _myEnum
It's inadvisable to use identifiers starting with underscores. Some
of them are reserved for the implementation; others are reserved but
only in certain contexts.
If you insist on using a typedef, you can use the same identifier for
the typedef and the enum tag -- or you can drop the enum tag
altogether:
typedef enum { ... } myEnum_t;
(And I think the _t suffix is reserved by POSIX.)
{
enum1 = 0,
enum2,
enum3,
....
} myEnum_t;
is making myEnum_t a 4-byte type.
How can I get the same "enumerate" feature, but make myEnum_t a 2-byte
type (preferable unsigned short)?
Why do you want to do this?
I don't mean to imply that you don't have a perfectly good reason, but
knowing what that reason is would help us to help you find a solution
to your underlying problem.
Keep in mind that the enumeration constants enum1 et al are not of
type enum; they're of type int. Since the language doesn't tie the
enumerated type to the constants, you don't have to either. Assuming
that unsigned short is 2 bytes (this is *not* guaranteed), you can do:
typedef unsigned short myEnum_t;
enum { enum1 = 0, enum2, enum3 };