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 statements

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



Joined: 30 Oct 2003
Posts: 24
Location: skegness

View user's profile Send private message Visit poster's website

switch statements
PostPosted: Sat Dec 20, 2003 7:48 am     Reply with quote

i have been adding to my code and i make use of switch statements quite a lot, anyhow now they have all stopped functioning correctly, when i step through the code it jumps off to some routine that reads a table and then returns back to the wrong section of the switch.
has anyone else noticed this ? am i doing something wrong.
it does the same on pch 3.180 and pch 3.181
most frustrating as i am having to recode with loads of if statements
they did work correctly last week, but i have extended the switch statements quite a lot since then.
Ttelmah
Guest







Re: switch statements
PostPosted: Sat Dec 20, 2003 10:31 am     Reply with quote

lewiseley wrote:
i have been adding to my code and i make use of switch statements quite a lot, anyhow now they have all stopped functioning correctly, when i step through the code it jumps off to some routine that reads a table and then returns back to the wrong section of the switch.
has anyone else noticed this ? am i doing something wrong.
it does the same on pch 3.180 and pch 3.181
most frustrating as i am having to recode with loads of if statements
they did work correctly last week, but i have extended the switch statements quite a lot since then.

The 'table read' code, _is_ the switch statement.
CCS, uses two different methods of coding switches. The first is similar to performing simple 'if' tests, while the second does a table 'jump' based on the value. Both do work, but the table jump version, can cause problems if table pointers are modified inside interrupt handlers. The current compilers try to protect against this, when CCS's own table handling code is used (arrays, or other switches), but will develop problems if any assembler code uses this ability, and does not save the registers. The code switches to using the 'table' version, if the number of cases is above a critical value (normally about 5), and there is no 'default' case. You can switch the behaviour between the two code types, by simply adding/removing the dafault case.
Presumably you have not got a default case, and have taken the number of statements above the 'switch' point, while something else in your code, is preventing the table based version (which is more efficient for larger switch statements), from working.

Best Wishes
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Dec 21, 2003 7:36 am     Reply with quote

Quote:


You can switch the behaviour between the two code types, by simply adding/removing the dafault case.



Hi Ttelmah,

I'm using the compiler since a while, and didn't know this "tips", it's a CCS info or the result of your own experience reading the generated .lst files?

Best wishes,


Humberto
jventerprises



Joined: 01 Apr 2004
Posts: 43
Location: Boston

View user's profile Send private message Visit poster's website

funny switch behavior
PostPosted: Fri Nov 19, 2004 2:38 pm     Reply with quote

i have had the same problem. it was becuase i left the default case out.

switch (data)
{
case 1:
...
break;

case 2:
...
break;
}

did NOT compile correctly. the code just runs off into outerspace!

switch (data)
{
case 1:
...
break;

case 2:
...
break;

default
...
break;
}

does work just fine. just add the default statement and it should be fine.

i can post the assembly of these examples if anybody wants them
_________________
Jon
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