Chad said:
D = 500,
M = 1000
};
int main(void)
{
int D = 44;
enum values romandigits = D;
printf("The value is: %d\n", romandigits);
return 0;
}
I get....
[cdalten@localhost oakland]$ gcc -g -Wall -Wextra roman.c -o roman
[cdalten@localhost oakland]$ ./roman
The value is: 44
How come the compiler doesn't complain about 'D' being both an int and
an enum?
You might choose to add -Wshaddow to your set of useful gcc options.
Lint is also handy:
C:\tmp>"C:\Lint\Lint-nt" +v -i"C:\Lint" std.lnt -os(_LINT.TMP) l.c
PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software 1985-2006
--- Module: l.c (C)
C:\tmp>type _LINT.TMP | more
--- Module: l.c (C)
_
int D = 44;
l.c(15) : Warning 578: Declaration of symbol 'D' hides symbol
'values:
' (line
9)
l.c(9) : Info 830: Location cited in prior message
_
enum values romandigits = D;
l.c(16) : Error 64: Type mismatch (initialization) (int/enum)
_
}
l.c(19) : Note 953: Variable 'D' (line 15) could be declared as const
--- Eff.
C++ 3rd Ed. item 3
l.c(15) : Info 830: Location cited in prior message
_
}
l.c(19) : Note 953: Variable 'romandigits' (line 16) could be declared
as const
--- Eff. C++ 3rd Ed. item 3
l.c(16) : Info 830: Location cited in prior message
--- Wrap-up for Module: l.c
Info 749: local enumeration constant 'values::I' (line 4, file l.c) not
referenced
l.c(4) : Info 830: Location cited in prior message
Info 749: local enumeration constant 'values::V' (line 5, file l.c) not
referenced
l.c(5) : Info 830: Location cited in prior message
Info 749: local enumeration constant 'values::X' (line 6, file l.c) not
referenced
l.c(6) : Info 830: Location cited in prior message
Info 749: local enumeration constant 'values::L' (line 7, file l.c) not
referenced
l.c(7) : Info 830: Location cited in prior message
Info 749: local enumeration constant 'values::C' (line 8, file l.c) not
referenced
l.c(8) : Info 830: Location cited in prior message
Info 749: local enumeration constant 'values:
' (line 9, file l.c) not
referenced
l.c(9) : Info 830: Location cited in prior message
Info 749: local enumeration constant 'values::M' (line 10, file l.c) not
referenced
l.c(10) : Info 830: Location cited in prior message