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

Error message when case value is > 65535

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



Joined: 09 Sep 2003
Posts: 95
Location: UK

View user's profile Send private message Send e-mail Visit poster's website

Error message when case value is > 65535
PostPosted: Tue Jan 05, 2010 9:02 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Tue Jan 05, 2010 9:56 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 05, 2010 11:45 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Mon Jan 11, 2010 9:57 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Jan 11, 2010 10:09 am     Reply with quote

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







PostPosted: Mon Jan 11, 2010 10:46 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 11, 2010 4:00 pm     Reply with quote

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. Smile
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