- (define-foreign-variable NAME TYPE [STRING])syntax
Defines a foreign variable of name NAME (a symbol). STRING should be the real name of a foreign variable or parameterless macro. If STRING is not given, then the variable name NAME will be converted to a string and used instead. All references and assignments (via set!) are modified to correctly convert values between Scheme and C representation. This foreign variable can only be accessed in the current compilation unit, but the name can be lexically shadowed. Note that STRING can name an arbitrary C expression. If no assignments are performed, then STRING doesn't even have to specify an lvalue. See that define-foreign-variable will not generate C declarations or memory allocation code; use it to include references to variables in external C code. To actually create Scheme variables visible from C, use define-external (see the Manual section on Callbacks). For example, the following code:
(import (chicken foreign)) (define-foreign-variable x double "var_x") (print x)
will not work, because a reference to var_x will be inserted in the C code, but no declaration will be included (this can be easily verified by translating the program into C with csc -t program.scm). Changing the second line to (define-external x double 0.5) will work (and the value 0.5 will be printed).