Skip to content


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.

  • Implementing the functionality in the statechart language might not be possible, because the latter does not provide the necessary means, e.g., to pull some data from an external source.
  • Even if it would be possible to implement the functionality in the statechart language, it might still not be desirable, if the functionality has been developed and fully tested in C already. You will neither want to re-invent the wheel nor would you want to introduce any new errors into an alternative implementation.

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

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

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.