Why is a doublePtr output argument actually a double?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Philip Borghesani
el 15 de Feb. de 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 comentarios
Ver también
Categorías
Más información sobre Call C from MATLAB en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!