codegen: Problems using a structure as an input parmeter

조회 수: 12 (최근 30일)
AJ
AJ 2012년 2월 2일
편집: dpb 2013년 10월 1일
I am developing a codegen project with multiple functions. One function BAR1 returns a structure of type FOO. Another function BAR2 accepts a structure of type FOO. However, the code generator creates two structures, indentical except they have different structure names. The code, as generated, produces a syntax error in my app:
FOO_TYPE foo;
double c;
foo = bar1();
c = bar2(foo);
error C2664: 'bar2' : cannot convert parameter 1 from 'FOO_TYPE' to 'const struct_T'
How can I make bar2() accept a struct of type 'FOO_TYPE' instead of internally generated type 'struct_T'?
A workaround is to use:
c = bar2(*(struct_T*)&foo);
but this is not robust if the structure name is redefined by codegen.
Thanks, AJ
Here is the Matlab code. In the codegen project, for bar2, I specified the input type "by example" using "FOO_TYPE". ====================
function foo = bar1
%bar1 - Code generator test case - Structure as an output
%#codegen
foo = FOO_TYPE;
foo.a = 1.0;
foo.b = 2.0;
====================
function c = bar2(foo)
%bar2 - Code generator test case - Structure as an input
%#codegen
c = double(0);
c = sqrt(foo.a^2 + foo.b^2);
====================
function s = FOO_TYPE
%FOO_TYPE - Defines a structure
%#codegen
s = struct(...
'a', double(0), ...
'b', double(0));
coder.cstructname(s, 'FOO_TYPE');

채택된 답변

Fred Smith
Fred Smith 2012년 2월 16일
Hi AJ,
Have you looked at coder.cstructname? That command can be used to specify the C name to use for a structure type.
-Fred

추가 답변 (1개)

Fred Smith
Fred Smith 2012년 2월 3일
Have you tried compiling both of these files with a single call to the codegen command? You can pass multiple entry points, and MATLAB Coder should ensure that the types are resolved correctly.
  댓글 수: 1
AJ
AJ 2012년 2월 6일
Thanks for the reply.
I did build this project with a single codegen call with multiple entry points.
For defining input types, there seems to be no concept of "named structures". Structures are defined by only their fields. I was hoping there would be some codegen directive and/or method to assign names to input structures. I am not intimately familiar with coder, and have been replying on the user interfaces for project building.
AJ

댓글을 달려면 로그인하십시오.

카테고리

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