To return a double* struct from an external C code in Dymola, you can follow these steps:
type MyStruct
Real x[2];
Real y[2];
end MyStruct;
malloc()
function to allocate memory for the struct on the heap.MyStruct* getMyStruct() {
MyStruct* ptr = (MyStruct*) malloc(sizeof(MyStruct));
ptr->x[0] = 1.0;
ptr->x[1] = 2.0;
ptr->y[0] = 3.0;
ptr->y[1] = 4.0;
return ptr;
}
external "C" MyStruct* getMyStruct();
MyStruct* structPtr = getMyStruct();
Real x1 = structPtr.x[0];
Real x2 = structPtr.x[1];
Real y1 = structPtr.y[0];
Real y2 = structPtr.y[1];
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-05-16 11:00:00 +0000
Seen: 11 times
Last updated: Dec 02 '21