They are compile time constants. You can't switch constants defined in your program.
#define etc.
Yes, you can, if the #defines are literals themselves. The compiler never sees the pre-preprocessor code so it doesn't care.
Code:
#define YES 0
#define NO 1
/* ... */
switch(answer) {
case YES: break;
case NO: break;
}
You just can't use an expression that must be evaluated at runtime, eg
Code:
int x;
switch(y) {
case x:
}
You can use a constant expression, as long as that expression can be evaluated by the compiler (I think, not sure on this one):
Code:
int array[BUFSIZ];
switch(size) {
case sizeof(array)/sizeof(*array):
}
It's like initializing a global/static variable.