Floats and doubles in C have different size, regardless the size of floats in pharo who are always 64bits.
But a call to a function(float a) expects a 32bits float and not a 64bit so a cast needs to be done (automatically in FFI), now if you are calling a function(float *a) and you have a float=42.0 you have to pass an address with place to store 32bits, not 64bits��� so
(ByteArray new: 4)
floatAt: 1 put: 42.0
��� will do the job.
But if you have a function(double *a), you need to do:
(ByteArray new: 8)
doubleAt: 1 put: 42.0
Now��� old nativeboost was prepared to do that conversion for you (if this was a good idea or not, is another story and needs to be told in another moment, and thread).
So, to allow operations style:
UNIXTime localTime: (UNIXTime getTime: nil)
where:
UNIXTime>>localTime: time
^ self ffiCall: #(tm* localtime(time_t* time) )
module: LibC
and:
getTime: t
^self ffiCall: #(time_t time(time_t* t) )
module: LibC
options: #(+ optCoerceNilToNull)
(from OS-Unix package)
To work fine, I need to reproduce that behaviour��� which is what the #rollToArity: method does.
So yes, is useful��� very useful.
I must admit, I don't get it either...
When you have a signature with a pointer to a primitive type, it's usually because
a) The method replaces the value
b) The method expects a pointer to an array with items of the primitive type.
In neither case is automatic marshalling from Smalltalk type very useful.