matlab coder:Can the C++ functions generated for the entry point functions of the "arguments" validation syntax take mergeability into account?
Mostra commenti meno recenti
For example, there is such an entry-point function in matlab that needs to generate C/C++ code, and I have generated several functions that are suitable for "different" types using the following command line, can these functions be merged into one for code simplicity and readability?
function out = useDefault(a,st)%#codegen
arguments
a (1,1) double
st (1,1) struct = struct("name","cuixing",...
"score",100);
end
% Specify the class of the input as struct.
assert(isstruct(st)); % https://www.mathworks.com/help/coder/ug/define-input-properties-programmatically-in-the-matlab-file.html#bq_w7jz-1
% Specify the class and size of the fields.
% assert(isa(st.name,'string')); %https://www.mathworks.com/help/coder/ug/define-string-scalar-inputs.html
assert(isa(st.score,'double'));
out = a + st.score;
end
command line:
codegen -config:lib -c -args {1,struct('name',"zhang",'score',50)} -args {100} -args {20,struct('name',"ab",'score',20)} -report useDefault -lang:c++
Note: I have specified the input multiple times with the "-args" parameter to represent a wider range of input types.

The resulting C++ code then has multiple similar functions for each `-args`, which does not take advantage of the overloading feature in C++ or use the default argument feature inherent in C++, could this be improved?
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su MATLAB Coder in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!