On a micro-controller program I have a few instructions that I would like to execute for every case in a switch except the default. I do not, however, want to write a function call or use a macro for every case.
Because this is for a micro-controller running at 3-7Mhz, speed and code space are important. For example:
switch(letter)
{
case a:
ShowApple();
printf("You entered an english letter.");
break;
case b:
ShowBananna();
printf("You entered an english letter.");
break;
...
case z:
ShowZebra();
printf("You entered an english letter.");
break;
default:
printf("You did not enter an english letter. Silly human!");
break;
}
int was_default_picked;
was_default_picked = 0;
switch (letter)
{
// ...
default:
was_default_picked = 1;
}
if (!was_default_picked)
{
// Your logic goes here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With