View previous topic :: View next topic |
Author |
Message |
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
Error message when case value is > 65535 |
Posted: Tue Jan 05, 2010 9:02 am |
|
|
With version 4.099, the following code brings up the error:-
Error[103] main.c 902 : Constant out of the valid range 65536 is not less than 65536
Am I doing something wrong here ? Surely this is valid ? Can someone confirm this is a bug ?
Mark
Code: | main()
{
int32 a;
a = 0x10000;
switch(a)
{
case 0x10000: break;
}
} |
|
|
|
mkuang
Joined: 14 Dec 2007 Posts: 257
|
|
Posted: Tue Jan 05, 2010 9:56 am |
|
|
I have compiler version 4.064 and have the same problem as you do. But if you declare "a" to be int16 instead of int32 and use the constant of comparison as 0x1000 instead of 0x10000 then the compiler doesn't complain. The switch statement constants of comparison has to be integers or characters according to CCS, I didn't know they have to be 16 bits or less also. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Tue Jan 05, 2010 11:45 am |
|
|
I just tried 3.249 and it fails as well. I guess the switch() is not able to evaluate a number greater than 65535, a 16bit number.
Ronald |
|
|
mkuang
Joined: 14 Dec 2007 Posts: 257
|
|
Posted: Mon Jan 11, 2010 9:57 am |
|
|
I posed the question to CCS Tech Support and they gave this simple answer:
32 bit switch/case arguments are not supported. |
|
|
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
|
Posted: Mon Jan 11, 2010 10:09 am |
|
|
mkuang wrote: | I posed the question to CCS Tech Support and they gave this simple answer:
32 bit switch/case arguments are not supported. |
Ah well ... I did raise this as a bug, but I guess it's not a show-stopper. I'll just have to use lots of if() else if() ... statements !!
Thanks |
|
|
Ttelmah Guest
|
|
Posted: Mon Jan 11, 2010 10:46 am |
|
|
It is perhaps worth saying that K&R, says switch 'accepts an integer value', so stopping at 65535, would be correct for most C's.
Best Wishes |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jan 11, 2010 4:00 pm |
|
|
When you have a lot of items in your switch-case it could be more efficient to implement a lookup table, and you can make these for 32-bits if you want to. |
|
|
|