A
At_sea_with_C
Consider the following code:
#include <stdio.h>
#define SOMEVAL 1234
enum tree_types { PINE = 10, BIRCH, LARCH, OAK = 100, MAPLE, ELM, WILLOW };
void print_val(enum tree_types tree)
{
printf("tree is: %d\n", tree);
}
int main()
{
enum tree_types trees;
trees = PINE;
print_val(trees);
trees = OAK;
print_val(trees);
trees = ELM;
print_val(trees);
trees = SOMEVAL;
print_val(trees);
return 0;
}
Why is the assignmnt with SOMEVAL allowed? I thought an enum type was only
allowed to have values specified in the enumeration list. Why is compiler
not even warning about it? Am I wrong?
Thanks.
#include <stdio.h>
#define SOMEVAL 1234
enum tree_types { PINE = 10, BIRCH, LARCH, OAK = 100, MAPLE, ELM, WILLOW };
void print_val(enum tree_types tree)
{
printf("tree is: %d\n", tree);
}
int main()
{
enum tree_types trees;
trees = PINE;
print_val(trees);
trees = OAK;
print_val(trees);
trees = ELM;
print_val(trees);
trees = SOMEVAL;
print_val(trees);
return 0;
}
Why is the assignmnt with SOMEVAL allowed? I thought an enum type was only
allowed to have values specified in the enumeration list. Why is compiler
not even warning about it? Am I wrong?
Thanks.