I would like to know with there is a way to translate matlab functions to C/C++ void functions using codegen. I've tested with a
simple function trying to use -nargout 0 so as to obtain a void function. However, the translated function doesn't behave as the original
one would, since the addition is never executed.
%Matlab function
function soma_a_b = soma(a,b) %#codegen
soma_a_b = a+b;end% C code generation at the command line
codegen -c -config:lib soma.m -args {1,2} -nargout 0 %Translated C function
void soma(double a, double b){ (void)a; (void)b;}
i) Is this expected behavior given that we're passing inputs by value and not returning anything, i.e. not causing any side-effects?
ii) Why are a and b being casted into void?
iii) Is this related to the lack of a return statement in native matlab? Attributing values to the output variables is semantically equivalent to returning, but since the translation output (C code) would have no return maybe the translation mappings get messed up along the way.
iv) Is there a way to force the translated function to be void and execute every instruction properly?
Best Answer