|
From: | Kon Lovett |
Subject: | Re: Re : Re : [Chicken-users] do I use define-foreign-variable correctly ? |
Date: | Wed, 7 Feb 2007 11:02:44 -0800 |
On Feb 7, 2007, at 10:41 AM, minh thu wrote:
2007/2/7, minh thu <address@hidden>:2007/2/7, Kon Lovett <address@hidden>: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Feb 7, 2007, at 6:41 AM, minh thu wrote: > > > #>! > > #include <X.h> > > #include <keysym.h> > > <# > > > > (define-foreign-variable c-escape-key int "XK_Escape") > > (define escape-key c-escape-key) > >> > Do I need to have those two lines too be able to use escape- key as a> > Scheme symbol for the C #defined XK_Escape value ? >> Umm, depends. Do you want it visible outside of the compilation unit> (i.e. exportable)? The escape-key, yes; the c-escape-key, no.In fact, if I intend the API to be portable above other system, I should export'ESCAPE without being related to the C counterpart, right ?
Once 'ESCAPE-KEY' is defined the relationship to the "C counterpart" is lost, only the int value is retained.
> then '(define escape-key (foreign-value > "XK_Escape" int))' is enough. Thanks ! > (I might make the symbol uppercase just > to emphasize it is a constant.) Ok. > Also 'define-foreign-variable' has > overhead that you don't want for a constant, it isn't mutable so > conversion should only be done once. ('foreign-value' is a wrapper> around 'define-foreign-variable' that creates the variable, gets its'> value, & throws away the variable, returning only the value.)Do I understand correctly : define-foreign-variable has overhead in thiscase since I don't need it to be mutable and foreign-value has not that overhead ?
Not after use, no.
Thanks, thu
[Prev in Thread] | Current Thread | [Next in Thread] |