View previous topic :: View next topic |
Author |
Message |
Richard Guest
|
switch statement |
Posted: Mon May 24, 2004 3:00 am |
|
|
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
|
|
Posted: Mon May 24, 2004 3:27 am |
|
|
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
|
|
Posted: Mon May 24, 2004 9:00 am |
|
|
Code: |
int const data[5]={1,2,3,4,5}
void main()
{
int min=5;
switch(min)
{
case data[0]:
output_d(0x00);
}
} | [/code] |
|
|
|