View previous topic :: View next topic |
Author |
Message |
s.jaglowski
Joined: 14 Nov 2005 Posts: 14
|
switch statement: size limit??? |
Posted: Mon Sep 18, 2006 9:01 am |
|
|
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
|
|
Posted: Mon Sep 18, 2006 9:36 am |
|
|
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
|
|
Posted: Mon Sep 18, 2006 12:04 pm |
|
|
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
|
|
Posted: Mon Sep 18, 2006 12:54 pm |
|
|
Thanks.
Suggested solution works.
The problems I cause for myself, just for the sake of a neater, regular appearance!
Regards,
Steve Jaglowski. |
|
|
Ttelmah Guest
|
|
Posted: Mon Sep 18, 2006 2:59 pm |
|
|
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 |
|
|
|