CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

switch size

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pfournier



Joined: 30 Sep 2003
Posts: 89

View user's profile Send private message

switch size
PostPosted: Tue Feb 07, 2006 2:51 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 07, 2006 4:13 pm     Reply with quote

It looks like you have found another undocumented 'feature' of the compiler... Crying or Very sad

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

View user's profile Send private message

PostPosted: Tue Feb 07, 2006 4:20 pm     Reply with quote

Thanks for the info. I guess I'll find another way to do what I want.
_________________
-Pete
Ttelmah
Guest







PostPosted: Wed Feb 08, 2006 3:51 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group