i am trying UFFI code the code is : FFICContantExamples class>>absMinusFortyTwo ^ self ffiCall: #( int abs ( TheAnswer ) ) module: LibC but it shows error. how to solve this ? <http://forum.world.st/file/t372453/Capture.png> -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
Where did you get this example? The straightforward answer is that "TheAnswer" appears to be undefined. In this context, 'ffiCall:' is expecting a valid C expression that indicates the type of a formal argument, followed by the formal argument. Based on the examples in the UFFI booklet, I would expect that to be something like 'int -42' rather than "TheAnswer". But knowing more of the context of where you got your code would help... -t -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
that means i cant able to use Theanswer ? i attach my screenshot how i initialize the value in variable . <http://forum.world.st/file/t372453/Capture.png> -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
Try using this expression: ^ self ffiCall: #( int abs ( int TheAnswer ) ) module: LibC i.e., add 'int' to tell Pharo that 'TheAnswer' is to be interpreted as a C integer. -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
There has been a change in how the constant values needs to be declared (because in a 64bit environment, you cannot âguessâ the type by its value: 42 can be (int32)42 or (int64)42. Hence, you need to be explicit on the time. Thatâs why @tbrunz suggestion is accurate. Now, I remember writing that example years ago, but I do not remember where :P Can you point me to the source, so I can correct it ? (it should have been done before, but better later than never ;) Esteban
On 1 Apr 2020, at 06:57, tbrunz <wild.ideas@gmail.com> wrote:
Try using this expression:
^ self ffiCall: #( int abs ( int TheAnswer ) ) module: LibC
i.e., add 'int' to tell Pharo that 'TheAnswer' is to be interpreted as a C integer.
-- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
El 1 abr 2020, a las 9:31, Esteban Lorenzano <estebanlm@gmail.com> escribió:
There has been a change in how the constant values needs to be declared (because in a 64bit environment, you cannot âguessâ the type by its value: 42 can be (int32)42 or (int64)42. Hence, you need to be explicit on the time.
Parentheses are not needed anymore (yet they are still supported I guess) :) You can now do int -42 Since there is no ambiguity possible, and this is consistent with int x ;)
Thatâs why @tbrunz suggestion is accurate.
Now, I remember writing that example years ago, but I do not remember where :P Can you point me to the source, so I can correct it ? (it should have been done before, but better later than never ;)
I wonder if for Pharo9 we should put the UFFI parser in strict mode. Strict mode should - not let people use constants without type declarations (because not doing so is a source of bugs) - not let people use String declarations without declaring encodings (because not doing so is a source of bugs) Of course, strictness is just a flag that people could turn off, at their own risk...
Esteban
On 1 Apr 2020, at 06:57, tbrunz <wild.ideas@gmail.com> wrote:
Try using this expression:
^ self ffiCall: #( int abs ( int TheAnswer ) ) module: LibC
i.e., add 'int' to tell Pharo that 'TheAnswer' is to be interpreted as a C integer.
-- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
participants (4)
-
Esteban Lorenzano -
Guillermo Polito -
shawon58 -
tbrunz