The ThingML code is valid - and makes sense - but the resulting C-code from the Posix compiler will not compile, since the struct MyThing_Instance MyThingInst_var is declared in the MyConf_cfg.c file, while it is assigned in the void initialize_configuration_MyConf() function. As depicted in the following snippet of the resulting MyConf_cfg.c file:
The above code works for basic types, but not arrays and structs.
The current workaround is a mess of declaring some temporary global variables in a @c_header annotation in the configuration, and initializing them in a @c_global annotation in the configuration.
A solution
A better way of initializing properties of things in C, would be to initialize the Thing-struct in the declaration, like this:
The problem
Consider the following ThingML code
where
bdaddr_t
is defined inbluetooth/bluetooth.h
asThe ThingML code is valid - and makes sense - but the resulting C-code from the Posix compiler will not compile, since the
struct MyThing_Instance MyThingInst_var
is declared in theMyConf_cfg.c
file, while it is assigned in thevoid initialize_configuration_MyConf()
function. As depicted in the following snippet of the resultingMyConf_cfg.c
file:The above code works for basic types, but not arrays and structs.
The current workaround is a mess of declaring some temporary global variables in a @c_header annotation in the configuration, and initializing them in a @c_global annotation in the configuration.
A solution
A better way of initializing properties of things in C, would be to initialize the Thing-struct in the declaration, like this:
Which would be valid C-code.
This should also be implemented to work when the values of properties are set in the ThingML configuration, like this: