Buses as inputs/outputs in C MEX S-Functions and vectors as structure members

1 view (last 30 days)
Hi everybody,
I need help, I've already learned how to define buses as outputs/inputs of a c-mex functions with the legacy code tool but what I need now is that my structures which are actually the buses have vectors as members. Something like :
typedef struct sTestData {
std::vector<Type_A> member1;
std::vector<Type_B> member2;
} TestData_t;
when I try to generate the code for the c-mex function and compile it I receive several errors :
error C2039: '..': is not a member of 'std::vector<_Ty>' with [ _Ty=Type_A ]
I hope someone can help me.

Answers (1)

Kaustubha Govind
Kaustubha Govind on 24 Aug 2012
First, std::vector is a C++ data structure, so you can't use them inside C S-functions, you'll need to use C++ S-functions. Second, Simulink does not support dynamic allocation, so data structures like std::vectors are not allowed. You might need to convert your std::vectors to built-in arrays (which is fairly easy using an intermediate type and extracting the built-in array under the std::vector using &member1[0]) of fixed-size (or of a fixed maximum size at any rate if you plan to create a bus containing variable-size signals).
  2 Comments
N P
N P on 24 Aug 2012
My mistake, I've wanted to say c++. And how do you suggest to do it? Like :
typedef struct sTestData { Type_A member1[10]; Type_B member2[10]; } TestData_t;
Because in that case the compiler has again problems with the generated c++ code from the LCT. It says :
error C2228: left of '.write' must have class/struct/union. Type is Type_A [10]
Kaustubha Govind
Kaustubha Govind on 27 Aug 2012
What are Type_A and Type_B typedef'd to? Is the type declaration in the same header?

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!