Matlab Coder, C-function return type

9 次查看(过去 30 天)
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
  1 个评论
Christian Steinebach
Hei again!
Nobody can help? :-( There must be some rules how the code generator decides whether to return anything as a parameter or as the function's return value. code.typeof() is only for input values as far as I understood. Example:
matlab function res=doit(a, b)
I would prefer a corresponding c-function void doit(double a, double b, double *res) eventually void doit(double a, double b, double res[])
Instead I get double doit(double a, double b)
Do I define another dummy parameter in the matlab function definition like function [res, dummy]=doit(a, b)
I get the generated c-code void doit(double a, double b, double *res, double *dummy)
That's almost what I want. But I have no use for the dummy variable.
Any suggestions?
Chris

请先登录,再进行评论。

采纳的回答

Abhishek Kumar
Abhishek Kumar 2019-6-26
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
  1 个评论
Christian Steinebach
Thank you, Abhishek Kumar ! :-)
That would have solved my problem. I sticked to the solution to check the number of output variables and react on that.
Thank you for your answer, I'll have it in mind next time.
Regards
Christian

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by