matlab coder:Can the C++ functions generated for the entry point functions of the "arguments" validation syntax take mergeability into account?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
cui,xingxing
le 14 Fév 2023
Commenté : cui,xingxing
le 14 Fév 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1294865/image.png)
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 commentaires
Réponse acceptée
Bhargava Hurulagere Sridharamurthy
le 14 Fév 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Generating Code dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!