matlab coder:Can the C++ functions generated for the entry point functions of the "arguments" validation syntax take mergeability into account?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
cui,xingxing
am 14 Feb. 2023
Kommentiert: cui,xingxing
am 14 Feb. 2023
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?
0 Kommentare
Akzeptierte Antwort
Bhargava Hurulagere Sridharamurthy
am 14 Feb. 2023
Hi Cui,
Thanks for the inputs.
"Overloading feature" is unfortunately not supported in MATLAB Coder as of MATLAB 2022b. We've made an internal note of your request so we can look at lifting that limitation in the future.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!