Hi all!
How can I represent a 'const int' type within gambit's ffi? Lets say I have the C funciton:
const int adder(int n){ blablabla...} and I want to interface that function with a c-lambda, how can I do that? If I try to omit the 'const' for the parameter's type, I get an error (bad type convertion) when compiling with g++ ("invalid conversion from ‘const void*’ to ‘void*'")...
I haven't seen anything talking about 'const' types in the ffi documentation...
By the way, I'd like to thank you all for always answering and answering quickily to all my (and others) questions! It really helps and motivates me to program in scheme! ^_^
David
Afficher les réponses par date
Because it's a different type (unknown to gambit), you have to provide the conversion routines yourself. these should be the same as converting ints, though, so it should be pretty easy. something like (below code is incomplete):
(c-declare #<<end typedef const int cint;
// define the conversions ___BEGIN_CFUN_SCMOBJ_TO_CINT (s, c, i) ___BEGIN_CFUN_SCMOBJ_TO_INT(s, c, i) ___END_CFUN_SCMOBJ_TO_CINT (s, c , i) ... etc etc, map all of then to INT ... ___BEGIN_CFUN_CINT_TO_SCMOBJ (c, s) ... ___END_CFUN_CINT_TO_SCMOBJ (c , s) ... ___BEGIN_SFUN_CINT_TO_SCMOBJ (c , s, i) ... ___END_SFUN_CINT_TO_SCMOBJ (c , s, i) ... ___BEGIN_SFUN_SCMOBJ_TO_C (s, c) .. ___END_SFUN_SCMOBJ_TO_C (s, c) ... end ) (c-define-type cint "cint" "CINT_TO_SCMOBJ" "SCMOBJ_TO_CINT")
You'll probably have to cast away the const when converting from scmobj to cint, also, for obvious reasons.
On 9/12/07, David St-Hilaire sthilaid@iro.umontreal.ca wrote:
Hi all!
How can I represent a 'const int' type within gambit's ffi? Lets say I have the C funciton:
const int adder(int n){ blablabla...} and I want to interface that function with a c-lambda, how can I do that? If I try to omit the 'const' for the parameter's type, I get an error (bad type convertion) when compiling with g++ ("invalid conversion from 'const void*' to 'void*'")...
I haven't seen anything talking about 'const' types in the ffi documentation...
By the way, I'd like to thank you all for always answering and answering quickily to all my (and others) questions! It really helps and motivates me to program in scheme! ^_^
David
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list