フィルターのクリア

How to return pointer from C caller function?

14 ビュー (過去 30 日間)
Ismail Mussed
Ismail Mussed 2020 年 9 月 14 日
コメント済み: Ruben Galvez 2024 年 1 月 16 日
I'm trying to use the C caller in Simulink to call a function that returns a pointer to an array. The function definition is like this:
int *convert_to_string (int input) {
static int arr[10];
arr[0] = input;
arr[1] = input + 1;
return arr;
}
But the C caller can't find any function that has a * in front of it. This surprised me because returning a pointer to an array is something totally routine in C. I noticed there is a "size" parameter for the output argument of the C caller block, but it isn't clear if there's a way to make that anything but 1.
How do I make the C caller find my function that returns a pointer?

回答 (1 件)

majety
majety 2020 年 11 月 4 日
Hi Matthew,
You could try passing in the int * arr as an input argument to the function. When you configure your C-Caller block in Simulink, you can set the arr variable as an output. Let me know if that doesn't work.
  1 件のコメント
Ruben Galvez
Ruben Galvez 2024 年 1 月 16 日
This would be a solution if you merely wanted to modify the content of the memory region where arr is pointing to. If you want arr to point to somewhere else, you need a function that returns a pointer.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by