A function declared in a C header file becomes available in a statechart. The state machine can call it as an operation.
Let’s say our rectangle.h header file not only defines the data type, but also declares one or more C functions to operate on them. The following line declares a function named area, taking a Rectangle parameter by value and returning an int32_t result.
extern int32_t area(Rectangle r);
For the sake of the example, let’s assume the function calculates the area of the given rectangle. Of course we could also do this with means built into the statechart language. However, in the general case you neither can nor want to do that.
itemis CREATE parses function declarations in header files and makes the functions available in the statechart language. It doesn’t care where those functions are defined – or whether they are defined at all – nor what they do. Questions like these will become relevant later when the state machine is generated as C source code, compiled and linked to the functions' implementations.
For now, once the statechart knows about the
area function’s declaration in the C header file, the function can be used immediately in statechart language operations. A corresponding
operation declaration in the statechart’s definition section is not needed. Example:
Using content assist to enter a C function call
Here’s the complete example with the area calculations done by the area function:
Example calling the “area” function
Please note: State machines calling C functions as operations are debarred from simulation and debugging. The simulator is not yet capable to call C functions.