When using strings in Embedded MATLAB, there is one first thing that is important to know :
'MyString' in MATLAB and "MyString" in C are not equivalent. In C, strings are null-terminated, whereas in MATLAB we treat them as character arrays (without null-termination). Therefore, it is not correct to pass
'MyString' to a C function and assume it is treated as a "MyString" in C.
Thus, the correct code for
eml.ceval('MyCExternalFunction', arg1, 'MyString');
should be:
eml.ceval('MyCExternalFunction', arg1, ['MyString' 0]);
Then, in order to pass a constant C string to a custom C function, one can use the EML.OPAQUE instruction. For example, EML.CEVAL call becomes :
eml.ceval('MyCExternalFunction', arg1, eml.opaque('const char *', '"MyString"'));
and that will just "glue-in" the "MyString" constant in the generated code :
MyCExternalFunction(arg1, "MyString");
Note : refer to related solution 1-7K299R for Null-terminated C strings.
Best Answer