uFFI ffiCall return value

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

uFFI ffiCall return value

eftomi
Dear all,

Should the method that calls Object>>#ffiCall: and variants always return the result of this call? For instance, in uFFI book, there is a method abs: defined as

FFITutorial class >> abs: n [
    ^ self ffiCall: #( int abs (int n) )
]

on page 16, however

FFITutorial >> abs: n [
    self ffiCall: #( int abs (int n) )
]

on page 52 doesn't have an explicit return ^. The book, however, in most of the examples uses the explicit return. What is the recommended approach? 

Thanks,
Tomaz
Reply | Threaded
Open this post in threaded view
|

Re: uFFI ffiCall return value

Esteban Lorenzano
Hi,

In practice it is the equivalent, since the ffiCall has a return type and it takes precedence over the ^ of Pharo.
Personally, I often add the ^ to ffiCalls that have a return to easy the reading, but the output will be the same.

Esteban

On May 10 2021, at 2:12 pm, Tomaž Turk <[hidden email]> wrote:
Dear all,

Should the method that calls Object>>#ffiCall: and variants always return the result of this call? For instance, in uFFI book, there is a method abs: defined as

FFITutorial class >> abs: n [
    ^ self ffiCall: #( int abs (int n) )
]

on page 16, however

FFITutorial >> abs: n [
    self ffiCall: #( int abs (int n) )
]

on page 52 doesn't have an explicit return ^. The book, however, in most of the examples uses the explicit return. What is the recommended approach? 

Thanks,
Tomaz
Reply | Threaded
Open this post in threaded view
|

Re: uFFI ffiCall return value

eftomi
Thanks!
Tomaz