I have the following C code:
unsigned long val = <my_size>;
switch(val)
{
case (1L<<10): // 1KB
// Do something
break;
case 1L<<20: // 1MB
// Do somnething
break;
case (1L<<30): // 1GB
// Do something
break;
case (1L<<40): // 1TB
// Do something
break;
// Other cases
default:
// Do something
break;
}
Now lint is giving me a warning saying
"Warning:44 Illegal Argument to Switch: Size Exceeds UB4"
So is it valid to use switch on a unsigned long
?
I don't get any compilation errors but want to make sure my code works properly and there are no funny rollover type stuff going on.
There won't be too many case labels in the switch.
I was reading on this and came across - Why can't your switch statement data type be long, Java?
It looks like switch statement type shouldn't be long in case of Java. Is it true for C as well?
If needed: 1. I am using linux lint 2. gcc for compiler 3. platform is linux 64 bit