View previous topic :: View next topic |
Author |
Message |
pfournier
Joined: 30 Sep 2003 Posts: 89
|
switch size |
Posted: Tue Feb 07, 2006 2:51 pm |
|
|
I am using v3.227. Can I use the switch statement with a 32 bit value? I seem to have found that it may be limited to 16 bits. I'm not about to go nuts looking for an error if it can't do it.
-Pete _________________ -Pete |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Feb 07, 2006 4:13 pm |
|
|
It looks like you have found another undocumented 'feature' of the compiler...
In another thread on this forum Darren Rook wrote: Quote: | The compiler only switches up to int16 anyways. | This was June 2004, about the time v3.202 was released. I don't think this behaviour has changed since then.
I tried compiling the following code in v3.241 and it failed with 'Duplicate case value'. Looks like it's still not implemented....
Code: | void main()
{
int32 Test;
switch (Test)
{
case 1:
Test+=1;
break;
case 0x10001: <== Duplicate value. Handled as an int16 i.s.o. int32
Test+=2;
break;
default:
Test+=10;
break;
}
} |
Report it to CCS as a Request For Enhancement. With enough people asking for this feature they will implement it eventually. |
|
|
pfournier
Joined: 30 Sep 2003 Posts: 89
|
|
Posted: Tue Feb 07, 2006 4:20 pm |
|
|
Thanks for the info. I guess I'll find another way to do what I want. _________________ -Pete |
|
|
Ttelmah Guest
|
|
Posted: Wed Feb 08, 2006 3:51 am |
|
|
If you look at the listing, you can see that switch only accesses the bottom two bytes of an int32.
If you look at K&R (The C programming language), they say that "The controlling expression of a switch and the case constants, are required to have an int type". In fact given that an 'int' in CCS, is only an int8, the compiler is doing more than might be expected...
This was a restriction that disappeared in ANSI-C.
Best Wishes |
|
|
|