Scheme 48 Manual -- Available facilities

Scheme 48 Manual | Contents | In Chapter: Mixing Scheme 48 and C
Previous: Available facilities | Next: Available facilities

## Available facilities

The following facilities are available for interfacing between Scheme 48 and C:

- Scheme code can call C functions.
- The external interface provides full introspection for all Scheme objects. External code may inspect, modify, and allocate Scheme objects arbitrarily.
- External code may raise exceptions back to Scheme 48 to signal errors.
- External code may call back into Scheme. Scheme 48 correctly unrolls the process stack on non-local exits.
- External modules may register bindings of names to values with a central registry accessible from Scheme. Conversely, Scheme code can register shared bindings for access by C code.

### Scheme structures

The structure `external-calls` has most of the Scheme functions described here. The others are in `dynamic-externals`, which has the functions for dynamic loading and name lookup from the section on Dynamic Loading, and `shared-bindings`, which has the additional shared-binding functions described in the section on the complete shared-binding interface.

### C naming conventions

The names of all of Scheme 48's visible C bindings begin with ``s48_`' (for procedures and variables) or ``S48_`' (for macros). Whenever a C name is derived from a Scheme identifier, we replace ``-`' with ``_`' and convert letters to lowercase for procedures and uppercase for macros. A final ``?`' converted to ``_p`' (``_P`' in C macro names). A final ``!`' is dropped. Thus the C macro for Scheme's `pair?` is `S48_PAIR_P` and the one for `set-car!` is `S48_SET_CAR`. Procedures and macros that do not check the types of their arguments have ``unsafe`' in their names.

All of the C functions and macros described have prototypes or definitions in the file `c/scheme48.h`. The C type for Scheme values is defined there to be `s48_value`.

### Garbage collection

Scheme 48 uses a copying garbage collector. The collector must be able to locate all references to objects allocated in the Scheme 48 heap in order to ensure that storage is not reclaimed prematurely and to update references to objects moved by the collector. The garbage collector may run whenever an object is allocated in the heap. C variables whose values are Scheme 48 objects and which are live across heap allocation calls need to be registered with the garbage collector.

Previous: Available facilities | Next: Available facilities