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

'const' and the 'switch' statement

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



Joined: 31 May 2008
Posts: 7

View user's profile Send private message

'const' and the 'switch' statement
PostPosted: Fri Jun 06, 2008 3:26 pm     Reply with quote

Hi

At the beginning of my code I'm setting these variables:
Code:
/*COMANDOS*/
const char ENVIARPAQUETEMUESTRAS = 'N';
const char ENVIARUNAMUESTRA = 'E';
const char ENVIOCONTINUODEMUESTRAS = 'C';
const char TERMINARENVIOCONTINUO = 'T';
const char RESPONDEROK = '?';
const char EMPEZARCONEXION = 'S';
const char TERMINARCONEXION = 'X';
const char DESPERTAR = 'D';
const char DORMIR = 'Q';


and then I want to use them in this switch statement:
Code:
comando = getc();
   
    switch( comando ){
        case ENVIARUNAMUESTRA : enviarUnicaMuestra(); break;
        case ENVIOCONTINUODEMUESTRAS : enviarMuestrasContinuamente(); break;
        case ENVIARPAQUETEMUESTRAS : enviarPaqueteMuestras(); break;
        case TERMINARCONEXION : return;   
    }


But I'm getting this compilation error:

Error 27, Line..., expression must evaluate to a constant. That is with ENVIOVONTINUODEMUESTRAS .

What's wrong with this code? :S

Also... are enums chars?. If they are chars I'll define again the constants as enums.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 06, 2008 3:42 pm     Reply with quote

See this section in the CCS manual:
Quote:
#CASE
Syntax: #case
Elements: None
Purpose: Will cause the compiler to be case sensitive.
By default the compiler is case insensitive.


Fix the problem by adding #case to your program.
RaulHuertas



Joined: 31 May 2008
Posts: 7

View user's profile Send private message

Thanks
PostPosted: Fri Jun 06, 2008 9:09 pm     Reply with quote

Thanks men, It works. I didn't know that issue. Thanks!
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