MATLAB: Do I receive a “C2552” compiler error when I build the model using Real-Time Workshop or Simulink Accelerator, when using a version of the Microsoft Visual C++ Compiler lower than 7.1

accelaccelleratorc2552compilationcompileconstfailsimulink coderstructure

When I build my model, I receive the following error:
error C2552: 'MyVar' : non-aggregates cannot be
initialized with initializer list
I am using Real-Time Workshop or Simulink Accelerator with Version 6.0 or 7.0 of the Microsoft Visual C++ Compiler.

Best Answer

This error results from a restriction present in some versions of the Microsoft Visual C/C++ compiler. The restriction prevents code of the following format from compiling, if the code resides in a .cpp file:
struct foo {
int code;
const bool flag;
};
where the variable foo is initialized as:
static foo FTwo = {2, false };
Since Real-Time Workshop generates code of this format under some circumstances, this restriction can affect compilation of generated code.
To work around this issue, either upgrade to Version 7.1 of the Microsoft Visual C/C++ compiler, or choose the target language as C on the RTW pane of the Configuration Parameters dialog box or from the command line:
set_param(modelname,'TargetLang','C')