Create your own data type

Create your own data type

The planed application should read a C source file and remove the comments. Therefore we need a file descriptor which is not part of the basic C types. The type for the file descriptor for MinGW is FILE. To make this type available on the model level, you have to declare the type.

Open the file Types.room from org.eclipse.modellib.c and take a look at the declaration of string (last line) which is not a basic C type.

PrimitiveType string:ptCharacter -> charPtr default "0"

With this declaration, you make the string keyword available on model level as a primitive type. This type will be translated to charPtr in your C sources. charPtr is defined in etDatatypes.h. This header file is platform specific ( generic). With this mechanism you can define your own type system on model level and map the model types to specific target/platform types.

To not interfere with other models, we will declare the type direct in the model. Add the following line to your model:

RoomModel RemoveComment {
import room.basic.types.* from "../../../org.eclipse.etrice.modellib.c/model/Types.room"

PrimitiveType file:ptInteger -> FILE default "0"

FILE is the native type for MinGW. Therefore you don´t need a mapping within etDatatypes.h. If your model should be portable across different platforms you should not take this shortcut.