| Contents | Index |
| On this page… |
|---|
How Stateflow Software Inlines Generated Code for State Functions |
By default, Stateflow software uses an internal heuristic to determine whether or not to inline state functions in code generated with Simulink Coder software. The heuristic takes into consideration an inlining threshold, so as your code grows and shrinks in size, the generated code for state functions can be unpredictable.
However, if you have rigorous requirements for traceability between generated code and the corresponding state functions, you can override this default behavior. Stateflow software provides a state property Function Inline Option that helps you explicitly force or prevent inlining of state functions.
If you force inlining for a state, all code generated for its state actions will be inlined into the parent function. The parent function contains code for executing the state actions, outer transitions, and flow graphs. It does not include code for empty state actions.
If you prevent inlining for a state, Simulink Coder software generates the following static functions, as in this example for state foo:
| Function | Description |
|---|---|
enter_atomic_foo | Marks foo active and performs entry actions |
enter_internal_foo | Calls default paths |
inner_default_foo | Executes flow graphs that originate when an inner transition and default transition reach the same junction inside a state. Stateflow software generates this function only when the flow graph is complex enough to exceed the inlining threshold. In generated code, Stateflow software calls this function from both the enter_internal_foo and foo functions. |
foo | Checks for valid outer transitions and if none, performs during actions |
exit_atomic_foo | Performs exit actions and marks foo inactive |
exit_internal_foo | Performs exit actions of the child substates and then exits foo |
Suppose that you explicitly prevent inlining for the following state A in model M:

Stateflow software generates the following functions:
static void M_inner_default_A(void); static void M_exit_atomic_A(void); static void M_A(void); static void M_enter_atomic_A(void); static void M_enter_internal_A(void);
To set the function inlining property for a state:
Right-click inside the state and select Properties from the context menu.
The State properties dialog box opens.
In the Function Inline Option field, select one of these options:
| Option | Behavior |
|---|---|
| Inline | Forces inlining of state functions into the parent function, as long as the function is not part of a recursion. See What Happens When You Force Inlining. |
| Function | Prevents inlining of state functions. Generates up to six static functions for the state. See What Happens When You Prevent Inlining. |
| Auto | Uses internal heuristics to determine whether or not to inline the state functions. |
Click Apply.
| To... | Set the Function Inline Option property to... |
|---|---|
| Generate a separate function for each action of a state and a separate function for each action of its substates | Function for the state and each substate |
| Generate a separate function for each action of a state, but include code for the associated action of its substates | Function for the state and Inline for each substate |
![]() | Traceability of Stateflow Objects in Generated Code | Debugging and Testing Stateflow Charts | ![]() |

Learn how engineers use Stateflow to model state machines in their Simulink models.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |