MATLAB: Matlab Coder, C-function return type

c functioncode generationmatlab coderreturn parameter

What determines the return of a parameter when generating C-code from a function? In which case is the parameter returned by value (as the c-function's value) and in which case is it returned in the parameter list? How can I ensure that the generated c-function is alwasy of type void()? Thanks for helping

Best Answer

Hi Christian
Functions in programming languages like 'c' and 'c++' are of a certain type, whether it be int, double, string etc. And when called using the main program, these functions return a value of that type. That is not the case in MATLAB, here we don't define return type also the function can return many values.
The coder is designed in such a way that when the matlab function returns more than one value the value to be returned is passed as parameters in the function.
If you have only one return and want is passed as parameter in the function, you could do this:
..............................................
function res = doit(a, b, res)
res= a+b;
end
................................................
>>codegen doit -args {0, 0, 0} -config:lib -report