This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Switch and Case structure

I am trying to do a simple function to return values based on the input...shown below.

char func (unsigned char add)
{
signed char i;
switch (add)
{
case 0: i = 0; break;
case 1: i = 1; break;
case 2, 3, 4, 9: i = 9; break;
case 10: i = 10;break;
default: i = 99;break;
}
return i;
}

When i try to call func(2), it automatically jumps to the default....
Does the Keil C compiler support the multiple list case structure?

MG

Parents
  • Thanks.

    The follwing code does work.

    switch (inputvar)
    {
    case a:
    case b:
    case c:
    etc etc
    callfunction();
    break;

    case d:
    callotherfunction();
    break;
    }
    The original code does not generate any errors btw. I guess could implement this with an if condition as follows

    if ((var == a)|(var == b)|.....
    callfunction();

Reply
  • Thanks.

    The follwing code does work.

    switch (inputvar)
    {
    case a:
    case b:
    case c:
    etc etc
    callfunction();
    break;

    case d:
    callotherfunction();
    break;
    }
    The original code does not generate any errors btw. I guess could implement this with an if condition as follows

    if ((var == a)|(var == b)|.....
    callfunction();

Children
No data