We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
"Case labels have to be literals, don't they? I don't think the comma operator is allowed there, any more than any other sort of expression." K&R says (say?), "a constant expression" - so the comma operator probably is allowed (though pointless!)
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();