chickadee » foreign » locations » #$

(location NAME)syntax
(location X)syntax
#$read

This form returns a pointer object that contains the address of the variable NAME. If the argument to location is not a location defined by define-location, define-external or let-location, then

(location X)

is essentially equivalent to

(make-locative X)

(See the manual section on locatives for more information about locatives)

Note that (location X) may be abbreviated as #$X.

(define-external foo int)
((foreign-lambda* void (((c-pointer int) ip)) "*ip = 123;") 
  (location foo))
foo                                                                    ==> 123

This facility is especially useful in situations, where a C function returns more than one result value:

#>
#include <math.h>
<#

(define modf
  (foreign-lambda double "modf" double (c-pointer double)) )

(let-location ([i double])
  (let ([f (modf 1.99 (location i))])
    (print "i=" i ", f=" f) ) )

See location and c-string* for a tip on returning a c-string* type.

location returns a value of type c-pointer, when given the name of a callback-procedure defined with define-external.