MATLAB: Does the Embedded MATLAB Function block fail to compile to C++ when it contains a switch statement in Simulink 6.2 (R14SP2)

buildccasecharEmbedded Coderemlfailfailssimulinkstrstring

I have a model set to compile to C++ with an Embedded MATLAB Function block. In this block, I have a switch statement with a variable that represents a character. When I try to run this model, I receieve the following error:
### Compiling "c2_eml_fail.cpp"
cl.exe -c -Zp8 -G5 -GR -W3 -DMATLAB_MEX_FILE -nologo /MD /I "t:\1-1joeg9\sfprj\build\eml_fail\sfun\src" /I "t:\1-1joeg9" /I "d:\program files\matlab704\extern\include" /I "d:\program files\matlab704\simulink\include" /I "d:\program files\matlab704\stateflow\c\mex\include" /I "d:\program files\matlab704\stateflow\c\debugger\include" /I "d:\program files\matlab704\toolbox\eml\lib\dsp" "c2_eml_fail.cpp"
c2_eml_fail.cpp
c2_eml_fail.cpp(216) : error C2664: 'cv_eml_init_switch' : cannot convert parameter 10 from 'unsigned int *' to 'int *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
NMAKE : fatal error U1077: 'cl.exe' : return code '0x2'
Stop.
The full build log and the model are attached.

Best Answer

This bug has been fixed in Release 2006a (R2006a). For previous product releases, read below for any possible workarounds:
There is a bug in Simulink 6.2 (R14SP2) when a switch statement is used with a variable that represents a character. Here are two workarounds:
  • Use If/Then/Else statements instead of Switch/Case statements.
  • Build to C instead of C++. This setting can be changed in Simulation -> Configuration Parameters -> Real-Time Workshop.