C
copx
C's enum type disappoints me a lot.
You cannot define which type of integer variable is used. This contradicts
C's low level spirit. "I want a number variable. I do not care about size or
execution speed." feels like typical ultra high level scripting language
design. The compiler could not optimize an enum if it wanted to, because you
cannot even specify whether memory requirements or speed are your primary
concern. Enums were meant to replace these endless lists of defines you find
all over older C source:
#define FOO 0
#define BAR 1
...
It is a technique commonly used to give index numbers meaningful names.
However, the variables which hold such numbers often do not need to be wider
than one byte and are used a lot. In one program I had many enum-type
variables as parts of my data structures and the amount of wasted RAM was
excessive when I used C enums, because the compiler (GCC) always used
(unsigned) ints, even if the entire range of valid values fitted into a
single byte. IMHO the definition of an enum should allow you to specify the
integer type. For example:
typedef int8_t enum {
FOO,
BAR
} MY_ENUM;
Not giving the programmer this type of control makes me feel like I am using
another language. What was the reasoning behind that decision? Did the guy
who designed the enum type also suggest to replace all of C's integer types
with "number"?
copx
You cannot define which type of integer variable is used. This contradicts
C's low level spirit. "I want a number variable. I do not care about size or
execution speed." feels like typical ultra high level scripting language
design. The compiler could not optimize an enum if it wanted to, because you
cannot even specify whether memory requirements or speed are your primary
concern. Enums were meant to replace these endless lists of defines you find
all over older C source:
#define FOO 0
#define BAR 1
...
It is a technique commonly used to give index numbers meaningful names.
However, the variables which hold such numbers often do not need to be wider
than one byte and are used a lot. In one program I had many enum-type
variables as parts of my data structures and the amount of wasted RAM was
excessive when I used C enums, because the compiler (GCC) always used
(unsigned) ints, even if the entire range of valid values fitted into a
single byte. IMHO the definition of an enum should allow you to specify the
integer type. For example:
typedef int8_t enum {
FOO,
BAR
} MY_ENUM;
Not giving the programmer this type of control makes me feel like I am using
another language. What was the reasoning behind that decision? Did the guy
who designed the enum type also suggest to replace all of C's integer types
with "number"?
copx