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 statement

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







switch statement
PostPosted: Mon May 24, 2004 3:00 am     Reply with quote

PCM V3.186
I am new to the CCS compiler, I need some advice:

Does anyone know why the following code will not be accepted:

int min=5;

int data[] = {1,2,3,4,5};

switch(min)
{

case data[0]: output_d(0x00); //

}

IN THE ABOVE EXAMPLE THE COMPILER WILL NOT ALLOW ME TO ENTER
A SEGMENT OF OF THE DATA ARRAY IN THE SWITCH STATEMENT

***Any ideas, alternatives??***

Thanx
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Mon May 24, 2004 3:27 am     Reply with quote

Only a constant can appear in front of a 'case' statement. An alternative is:

Code:
int min=5;

#define CASE1 1
#define CASE2 2
#define CASE3 3
#define CASE4 4
#define CASE5 5

switch(min)
{

case CASE1: output_d(0x00); //

}
AK



Joined: 20 Apr 2004
Posts: 33

View user's profile Send private message

PostPosted: Mon May 24, 2004 9:00 am     Reply with quote

Code:

int const data[5]={1,2,3,4,5}
void main()
{
     int min=5;
     switch(min)
     {
          case data[0]:
               output_d(0x00);
     }
}
[/code]
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