Someone said it is dangerous to use enum constants as array indices. Why?
Is it dangerous because some compilers do not support the arithmetics of enum constants, like in the case of A[MON+TUE] given enum DAYS{MON, TUE, ...}?
And is there anything wrong in the following?
Code:
enum DAYS {MON, TUE, WED, totaldays};
char *days[] = {"Monday", "Tuesday", "Wednesday"};
for (i=0; i<totaldays; i++)
if (strcmp(string, days[i])==1) ...
Any possible improvement?
And from the information-hiding perspective, let's say I do not want the client of the above code know about MON, TUE, etc, i.e. the enum declaration. They need know only about "Monday", "Tuesday", etc. So, I put only the days[] declaration in a header file (i.e. an interface). Is it a good idea? It seems the enum declaration and the days[] declaration are so tightly coupled that they should be together. ???
Thank you.