We know that C store enum types internally as int
, which means that the size of the enum is 4 bytes in 32/64 bit machine.
But considering int
is signed and range from −2,147,483,648 to 2,147,483,647, we certainly don't need that many available values. We can use unsigned short (max 65,535) or even unsigned char (max 255) suffices. So my questions are:
Q1-why C don't make enum type store unsigned short/char internally?
Q2-Why we need to use typedef
to declare an enum e.g
typedef enum { N_LEAF, N_INTERNAL } nodetype_t;
but we don't need to use typedef
in struct declaration e.g
struct node_s {
char c;
int i[2];
};
Why we can't make enum declaration the same as struct as:
enum { N_LEAF, N_INTERNAL } nodetype_t;