How do I control the generation of default cases for switch statements in code built from Stateflow charts?

9 views (last 30 days)
The configuration option Code Generation > Code Style > Suppress generation of default cases for Stateflow switch statements if unreachable seems to have no effect on some of my charts. How do I control the generation of these cases when generating code?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 22 Sep 2015
The Suppress generation of default cases… configuration option was introduced in R2011b. Prior to that release, a default case was generated for all charts with multiple child states, and that default could theoretically be unreachable. When the option was first introduced, users could instead have Stateflow generate code with only case statements, and no defaults.
However, the behavior of this option was changed starting in R2012a. Now this configuration option will have an effect on the generated code only from charts which contain local events. In their absence, the default case is always the last child state (in alphabetical order), is always reachable, and is always generated. In the presence of local events, you can use the configuration option to suppress the generation of the default case, if desired.
It is important to note that the statement “if unreachable” in the option name refers to the possibility of reaching the default case itself, not any sort of unreachable states in the Stateflow chart. Stateflow is designed to always optimize unreachable states out of the generated code entirely. 

More Answers (0)


No tags entered yet.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!