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 CCS Technical Support

switch statement: size limit???

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



Joined: 14 Nov 2005
Posts: 14

View user's profile Send private message

switch statement: size limit???
PostPosted: Mon Sep 18, 2006 9:01 am     Reply with quote

Hi.

I'm implementing a command line interface with approx. 20 commands that need to be received and executed.

I'm using a switch() statement to direct me to the correct command service routine - but the compiler won't let me have any more than 8 cases before it refuses to compile and gives the error message
"A numeric expression must appear here."

Code:

void command_control(void)
{
   BYTE c;

   while(buff_getc(command_stream) != 'W')
      ;

   sel_gets(command_stream);

   parse();            

   switch(atoi(command_token))
   {
      case   00:   printf("Case 00");
               break;
      case   01:   printf("Case 01");
               break;
      case   02:   printf("Case 02");
               break;
      case   03:   printf("Case 03");
               break;
      case   04:   printf("Case 04");
               break;
      case   05:   printf("Case 05");
               break;
      case   06:   printf("Case 06");
               break;
      case   07:   printf("Case 07");
               break;
      caSe   09:   printf("9");
               break;
      case   08:   printf("Case 08");
               break;
      default    :   printf("Unrecognised Command");
   }
   printf("\n\r");
/*      case   09:   printf("Case 09");
               break;
      case   10:   printf("Case 10");
               break;
      case   11:   printf("Case 11");
               break;
      case   12:   printf("Case 12");
               break;
      case   13:   printf("Case 13");
               break;
      case   14:   printf("Case 14");
               break;
      case   15:   printf("Case 15");
               break;
      case   16:   printf("Case 16");
               break;
      case   20:   printf("Case 20");
               break;
      case   21:   printf("Case 21");
               break;
      default    :   printf("Unrecognised Command");
   }
   printf("\n\r");

*/
   comms_active = FALSE;
}


It works fine up to case 7. The capital S in the listing (caSe 9) indicates where the cursor resides after the failed compilation.

The target PIC is an 18F8720. Plenty of code space. Is this some kind of stack limit?

Regards,

Steve Jaglowski
      Ttelmah
      Guest







      PostPosted: Mon Sep 18, 2006 9:36 am     Reply with quote

      Get rid of your leading zeros.
      You are causing an overflow in part of the compilers 'parser' because it is not designed to handle values with leading zeros.

      Best Wishes
      ckielstra



      Joined: 18 Mar 2004
      Posts: 3680
      Location: The Netherlands

      View user's profile Send private message

      PostPosted: Mon Sep 18, 2006 12:04 pm     Reply with quote

      Ttelmah wrote:
      You are causing an overflow in part of the compilers 'parser' because it is not designed to handle values with leading zeros.
      Values starting with a '0' are valid constants, but... they are considered to be in the octal number system. Constants 08 and 09 are invalid in the octal system. See page 81 of the PICC March 2006 manual for different notations of constant expressions.
      s.jaglowski



      Joined: 14 Nov 2005
      Posts: 14

      View user's profile Send private message

      PostPosted: Mon Sep 18, 2006 12:54 pm     Reply with quote

      Thanks.

      Suggested solution works.

      The problems I cause for myself, just for the sake of a neater, regular appearance!

      Regards,

      Steve Jaglowski.
      Ttelmah
      Guest







      PostPosted: Mon Sep 18, 2006 2:59 pm     Reply with quote

      I do think though, that the parser syntax checking really ought to simply highlight the '09', and give a message like 'invalid number format', rather than just saying that a number is required.
      Many posters in the past have opted to put the code through a third party syntax checker, and this will pick up '09', and the one I use says 'invalid octal number', which really does explain the problem.
      Depending on the compiler version, the parser can get completely screwed by '09', and generate a huge output fle before failing.

      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