urig
urig

Reputation: 16851

Why does MATLAB Coder not generate C built-in types even though I've set DataTypeReplacement = 'CBuiltIn'?

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?

Upvotes: 1

Views: 319

Answers (1)

ami91
ami91

Reputation: 1354

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.

Upvotes: 3

Related Questions