First output of calllib is always double.

4 ビュー (過去 30 日間)
Zachary Smoot
Zachary Smoot 2024 年 4 月 24 日
回答済み: Paras Gupta 2024 年 4 月 30 日
If I have a function in a C library declared in a C header like so:
long long some_function();
And call the function like so:
loadlibrary('the_library', 'the_header.h');
out = calllib('the_library', 'some_function');
The output "out" is of type double, instead of int64.
When generating a prototype file for the library, the value of "LHS" is detected as "int64", but this does not seem to effect what the actuall output type is when calling the function.

採用された回答

Paras Gupta
Paras Gupta 2024 年 4 月 30 日
Hey Zachary,
In my understanding, you want the output type of the 'calllib()' function to be 'int64' instead of 'double' for a C function with return type "long long".
The type for all scalar values returned by MATLAB is 'double' by default. Please refer to the note given in the following documentation:
To convert the output to 'int64', you can try the following two workarounds:
  1. Using the 'int64()' function on the output - https://www.mathworks.com/help/matlab/ref/int64.html
  2. Modifying the function definition to return an array pointer with type "long long" instead of a scalar output. The 'out' variable in MATLAB will then be a 'libpointer' object - https://www.mathworks.com/help/matlab/ref/libpointer.html
Hope this helps.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall C from MATLAB についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by