How to use Deep C/C++ Integration

Using Deep C/C++ Integration is pretty straightforward:

  1. You have to use a „C/C++ domain” statechart or change the domain of an existing statechart.
  2. The Eclipse project your statechart is in must be a CDT project.

The subsequent sections will explain how to use Deep C/C++ Integration in practice, using a sample project. In this example, we will define some geometry types like Point or Triangle in C/C++ header files and demonstrate how to make them available and use them in a statechart model. While this example covers C constructs only, there is no extra effort involved in using C++ features – with one exception: Your project must be a C/C++ or a pure C++ project.

Creating a new C project

  1. In the Eclipse main menu, select File → New → Project…. The New Project wizard opens.
  2. Select C/C++ → C Project.
    Creating a new C project
  3. Click Next >. The C Project dialog appears.
  4. Enter the name of your project into the Project name field. For the sake of this example, we call the project Geometry.
  5. Specify the location of the project folder by either using the default location or by explicitly specifying a directory in the Location field.
  6. Select the Project type. In order to keep things plain and simple, for this example we create an Empty Project.
  7. Select the toolchain you want to work with. It contains the necessary tools for C development. By default only the toolchains supporting your local platform are displayed. Since this example has been created on a Linux machine, the toolchain Linux GCC is shown.
    Specifying the C project's properties
  8. Click Next >.
  9. Specify platforms, configurations, and project settings. This is more specific to C than to YAKINDU Statechart Tools, so we won’t go into any details here.
    Specifying platforms, configurations, and project settings
  10. Click Finish.
  11. Eclipse asks whether it should associate this kind of project with the C/C++ perspective. Usually this is what you want, so set a checkmark at Remember my decision and click Yes.
  12. Eclipse creates the C project, here Geometry.

Creating a C header file

Now we can create a C header file specifying our own C type definitions which we can use in a state machine later. In order to create the file, let’s proceed as follows:

  1. In the project explorer view, right-click on the project. The context menu opens.
  2. In the context menu, select New → Header File.
    Creating a C header file
  3. The dialog New Header File is shown. Specify the name of the header file. Here we choose point.h.
    Selecting a header filename
  4. Click Finish.
  5. The header file point.h is created.

Defining a C struct

In the created header file we define a struct type named Point, which we will later use in a statechart. A (two-dimensional) point consists of an x and a y coordinate. We choose int16_t to represent a coordinate, i.e., a 16-bit signed integer. The complete header file containing the struct definition looks like this:

/*
 * point.h
 *
 */

#ifndef POINT_H_
#define POINT_H_

#include <stdint.h>

typedef struct {
    int16_t x;
    int16_t y;
} Point;

#endif /* POINT_H_ */

Please note: In C it is possible to define structs, unions and enums without a typedef. They can be referenced by using the corresponding qualifying keyword ( struct, union, or enum, respectively). As the statechart language does not support these qualifiers, the usage of struct, union and enumeration types is currently restricted to those defined by a typedef.