Functions, Operators, Switch Cases and Truth Tables : Switch Cases : C Language : Translator

Translator

The Translator translates switch/case structures to if/then/else structures for simulation and code generation needs:

switch/case

if (expression == key_value) actions;

 

 

If the break statement occurs in the action, control is transferred out of the if/then/else statement by if (expression == key_value) actions.
If the break statement does not occur in case body, the next if/then/else statement expression contains the previous expression and the current expression.

All default actions are concatenated as a sequence of actions and run if all the if/then/else expressions are FALSE.

The following table shows the translation of a switch case.

 
switch_c (X)
{
case_c 1:
Y++;
case_c 2:
Y=Y+2;
X++;
break;
case_c 3:
FOO1(Y);
FOO2(Y);
break;
default :
DEF_ACTION(X);
};
if ( X==1 )
{
Y = (Y + 1);
}
if ((X==1)||(X==2))
{
Y = (Y + 2);
X = (X + 1);
}
else
{
if ( X==3 )
{
FOO1(Y);
FOO2(Y);
}
else
{
DEF_ACTION(X);
}
}