VerTiGo_Etrex
VerTiGo_Etrex

Reputation: 149

explicit cast in a switch case statement

I have a character pointer named label, and also an enumerator that contains an element named "label". How can I differentiate between them in a case statement?

switch((I_ARG_TYPES) progrm[i].arg[j].type){
case (I_ARG_TYPES) value:
    break;
case (I_ARG_TYPES) label:
    break;
default:
    break;
}

Global scope:

typedef enum I_ARG_TYPES {
    value, label
} I_ARG_TYPES;

In the same function as the switch:

char label[MAXLINELENGTH]

"Case label does not reduce to an int" on the case for label.

Upvotes: 1

Views: 1122

Answers (1)

melpomene
melpomene

Reputation: 85767

You can't. (Similarly, if you do float printf, you can't call the printf() function in that scope.)

Solution: Don't give your local variables the same name as things from the global scope.

Upvotes: 2

Related Questions