Stateflow | ![]() ![]() |
Pointer and Address Operators
The Stateflow action language includes address and pointer operators. The address operator is available for use with both custom code variables and Stateflow variables. The pointer operator is available for use with custom code variables only.
Syntax Examples
These examples show syntax that is valid for use with custom code variables only.
varStruct.field = <expression>; (*varPtr) = <expression>; varPtr->field = <expression>; myVar = varPtr->field; varPtrArray[index]->field = <expression>; varPtrArray[expression]->field = <expression>; myVar = varPtrArray[expression]->field;
These examples show syntax that is valid for use with both custom code variables and Stateflow variables.
varPtr = &var; ptr = &varArray[<expression>]; *(&var) = <expression>; function(&varA, &varB, &varC); function(&sf.varArray[<expr>]);
Syntax Error Detection
The action language parser uses a relaxed set of restrictions. As a result, many syntax errors will not be trapped until compilation.
Hexadecimal Notation
The action language supports C style hexadecimal notation (for example, 0xFF
). You can use hexadecimal values wherever you can use decimal values.
Typecast Operators
A typecast operator converts a value to a specified data type. Stateflow typecast operators have the same notation as MATLAB typecast operators:
op(v)
where op is the typecast operator (e.g, int8
, int16
, int32
, single
, double
) and v
is the value to be converted.
Normally you do not need to use typecast operators in actions. This is because Stateflow checks whether the types involved in a variable assignment differ and, if so, inserts a typecast operator in the generated code. (Stateflow uses the typecast operator of the language in which the target is generated, typically C.) However, if external code defines either or both types, Stateflow cannot determine which typecast, if any, is required. If a type conversion is necessary, you must use a Stateflow action language typecast operator to tell Stateflow which target language typecast operator to generate.
For example, suppose varA
is a data dictionary value of type double
and y is an external variable of type 32-bit integer. The following notation
y = int32(varA)
tells Stateflow to generate a typecast operator that converts the value of varA
to a 32-bit integer before the value is assigned to y
.
Event Broadcasting
You can specify an event to be broadcast in the action language. Events have hierarchy (a parent) and scope. The parent and scope together define a range of access to events. It is primarily the event's parent that determines who can trigger on the event (has receive rights). See Name for more information.
Broadcasting an event in the action language is most useful as a means of synchronization amongst AND (parallel) states. Recursive event broadcasts can lead to definition of cyclic behavior. Cyclic behavior can be detected only during simulation.
Example: Event Broadcast State Action
This is an example of the event broadcast state action notation.
See Example: Event Broadcast State Action for information on the semantics of this notation.
Example: Event Broadcast Transition Action
This is an example of the event broadcast transition action notation.
See Example: Event Broadcast Transition Action (Nested Event Broadcast) for information on the semantics of this notation.
![]() | Arrays | Directed Event Broadcasting | ![]() |