Can the compiler chose the type of an enum to be signed or unsigned
int? I thought it must be int; looks like it changes based on the
assigned values. Below if I don't initialize FOO_STORE to be, say -10,
I get a warning about unsigned comparison and I'm seeing an infinite
loop.
If I do initialize FOO_STORE = -10, I don't see any warnings. No
infinite loop.
Isn't the type of FOO_xyz required to be an 'int'?
Can the compiler choose its type to be unsigned int?
--------
#include <stdio.h>
typedef enum {
FOO_STORE , /* if = -10 is added, no warnings. works fine */
FOO_HASHTABLE,
FOO_STATE,
FOO_CONFIG,
FOO_MAX
} foo_subobj_type _en;
int main(void) {
foo_subobj_type _en sub_obj;
for (sub_obj = FOO_MAX-1; sub_obj >= FOO_STORE; --sub_obj) {
printf("%d\n", sub_obj);
}
return 0;
}
gcc --version gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-52)
gcc -Wall -W -ansi -pedantic enum.c enum.c: In function `main':
enum.c:15: warning: comparison of unsigned expression >= 0 is always
true
Thanks,
Karthik