In a c-lambda, what are the types of the argument variables ___arg1, ___arg2, and so on? It seems like they are statically resolved to the types I passed in to the c-lambda, and everything happens that I expect to happen:
(define %%addOne (c-lambda (int) int "___result=___arg1+1;"))
(display (%%addOne 10))
This correctly prints out 11, and other various operations on pointers seemed to work too. For example, if 'ctx' is a structure with a 'id' field, and 'ctxp' is defined as (pointer ctx), the following function works fine:
(define %%useCtx (c-lambda (ctxp) int "___result=(*___arg1).id;"))
Basically, my question is when do I need to use ___CAST on the argument variables? Is it something I should be doing most of the time for safety, to suppress warnings or for some other reason? Or is it something done in a special case I haven't encountered yet? I've seen it done in other gambit FFI's and I'm wondering if the other was just paranoid or something (and if I should be).
Afficher les réponses par date
The short answer is:
#define ___arg1 ___CFUN_CAST(OSVERSIONINFOW*,___arg1_voidstar)
which expands to
(OSVERSIONINFOW*)(___arg1_voidstar)
At 03:08 -0400 2007/09/09, James Long wrote:
In a c-lambda, what are the types of the argument variables ___arg1, ___arg2, and so on? It seems like they are statically resolved to the types I passed in to the c-lambda, and everything happens that I expect to happen:
(define %%addOne (c-lambda (int) int "___result=___arg1+1;"))
(display (%%addOne 10))
This correctly prints out 11, and other various operations on pointers seemed to work too. For example, if 'ctx' is a structure with a 'id' field, and 'ctxp' is defined as (pointer ctx), the following function works fine:
(define %%useCtx (c-lambda (ctxp) int "___result=(*___arg1).id;"))
Basically, my question is when do I need to use ___CAST on the argument variables? Is it something I should be doing most of the time for safety, to suppress warnings or for some other reason? Or is it something done in a special case I haven't encountered yet? I've seen it done in other gambit FFI's and I'm wondering if the other was just paranoid or something (and if I should be). _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
James Long wrote:
Basically, my question is when do I need to use ___CAST on the argument variables? Is it something I should be doing most of the time for safety, to suppress warnings or for some other reason? Or is it something done in a special case I haven't encountered yet? I've seen it done in other gambit FFI's and I'm wondering if the other was just paranoid or something (and if I should be).
I don't see any reason to use such casts (if the types are already what you want).
___CAST is just a macro expanding to a C cast btw, I think Marc introduced it because it is easier to search for in the sources (for when you want to get rid of them or find insecure places).
I'm only using casts for hackery on the Gambit data types (e.g. treating pointers as fixnums), or turning the body of a homogenous vector which has been passed as scheme-object into a C vector (for using the C array access syntax) (e.g. (##c-code "char *foo= ___CAST(char*,___BODY(___ARG1)); .. foo[i]= ..." ...)).
Christian.