Why is a doublePtr output argument actually a double?
4 views (last 30 days)
Show older comments
In this page below titled "Working with Pointer Arguments", the sample function (multDoubleRef) is said to return the second output argument (xval) as a value of type double. As a matter of fact, xval indeed functions as a double variable. However, the function prototype indicates that it should be of type doublePtr. Why is there an inconsistency? Thanks.
Example:
x = 15;
xp = libpointer('doublePtr',x);
[xobj,xval] = calllib('shrlibsample','multDoubleRef',xp)
xobj =
lib.pointer
xval =
75
Function Prototype
[lib.pointer, doublePtr] multDoubleRef(doublePtr)
0 Comments
Answers (1)
Philip Borghesani
on 15 Feb 2013
This is a convenience for the user. When MATLAB knows the size and type of a simple output pointer it automatically copies the output values to MATLAB arrays. The original(possibly modified) values and pointer from the inputs are still intact and can be used when a copy is not desired.
The same conversions are done on input. This is a reasonable call:
[~,newvalue]=calllib('shrlibsample','multDoubleRef',5);
Note that in this case the first output pointer return value should not be used because it points to a temporary value that has already been deleted.
0 Comments
See Also
Categories
Find more on Call C from MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!