1

I have a MATLAB (R2020b) function that I am trying to convert to (Linux-compatible) C program using MATLAB Coder. The function accepts 3 string arguments like so:

function func1(a, b, c)

I would like the generated C function to accept 3 char* arguments:

extern void func1(const char *a, const char *b, const char *c);

To get this done I'm running MATLAB Coder through this script:

cfg = coder.config('dll','ecoder',false);
cfg.GenerateReport = true;
cfg.ReportPotentialDifferences = false;
cfg.GenerateComments = false;
cfg.RuntimeChecks = true;
cfg.GenCodeOnly = true;
cfg.HardwareImplementation.TargetHWDeviceType='Generic->64-bit Embedded Processor (LP64)';
cfg.DataTypeReplacement = 'CBuiltIn';

%% Define argument types for entry-point 'func1'.
ARGS = cell(1,1);
ARGS{1} = cell(3,1);
ARGS{1}{1} = coder.typeof('X',[Inf Inf],[1 1]);
ARGS{1}{2} = coder.typeof('X',[Inf Inf],[1 1]);
ARGS{1}{3} = coder.typeof('X',[Inf Inf],[1 1]);

%% Invoke MATLAB Coder.
codegen  -config cfg func1 -args ARGS{1} -c

After running the script, the resulting function signature is:

extern void func1(const emxArray_char_T *a, const emxArray_char_T *b, const emxArray_char_T *c);

It seems that despite my having explicitly set cfg.DataTypeReplacement = 'CBuiltIn', MATLAB Coder has generated MathWorks typedefs instead of built-in C data types.

My question is - Why? And how can I fix this to generate built-in data types?

1 Answer 1

3

Generating code that takes char* for variable-sized strings is unfortunately not supported as of MATLAB Coder R2021a. For now, MATLAB Coder always generates code that takes emxArray_char_T* (for C code generation) or coder::array (default for C++ code generation) when variable-sized strings are used.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.