Function return types in Matlab Coder
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I am investigating the Matlab Coder functionality. I have 2 quick questions let's say I have the following function in Matlab:
function int_point = my_cross(line1,line2)
int_point = cross(line1,line2);
end
The corresponding C++ function generated by the coder is the following:
void my_cross(const double line1[3], const double line2[3], double int_point[3])
{
int_point[0] = line1[1] * line2[2] - line2[1] * line1[2];
int_point[1] = line2[0] * line1[2] - line1[0] * line2[2];
int_point[2] = line1[0] * line2[1] - line2[0] * line1[1];
}
Question 1) Is there a way to have the c++ function having return type double instead of returning as parameter?
Question 2) In the generated c++ function where my_cross is called the parameters are passed by pointer but I want to pass by value. Can I change this behaviour?
Thanks.
0 comentarios
Respuestas (1)
Mukund Sankaran
el 14 de Jun. de 2023
Hello,
This doc page provides some insight into what you are observing: https://www.mathworks.com/help/coder/gs/differences-in-the-appearance-of-generated-code-and-matlab-code.html
Another similar question was posed a while ago, and the answer there contains some more specifics as well: https://www.mathworks.com/matlabcentral/answers/781348-matlab-coder-generated-a-c-function-which-has-void-output-even-though-the-matlab-function-has-doubl
Hope this helps!
Ver también
Categorías
Más información sobre MATLAB Coder en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!