Node:Relationship between SCM and scm_t_bits, Next:Immediate objects, Up:Unpacking the SCM type
SCM
and scm_t_bits
A variable of type SCM
is guaranteed to hold a valid Scheme
object. A variable of type scm_t_bits
, on the other hand, may
hold a representation of a SCM
value as a C integral type, but
may also hold any C value, even if it does not correspond to a valid
Scheme object.
For a variable x of type SCM
, the Scheme object's type
information is stored in a form that is not directly usable. To be able
to work on the type encoding of the scheme value, the SCM
variable has to be transformed into the corresponding representation as
a scm_t_bits
variable y by using the SCM_UNPACK
macro. Once this has been done, the type of the scheme object x
can be derived from the content of the bits of the scm_t_bits
value y, in the way illustrated by the example earlier in this
chapter (see Cheaper Pairs). Conversely, a valid bit encoding of a
Scheme value as a scm_t_bits
variable can be transformed into the
corresponding SCM
value using the SCM_PACK
macro.
scm_t_bits SCM_UNPACK (SCM x) | Macro |
Transforms the SCM value x into its representation as an
integral type. Only after applying SCM_UNPACK it is possible to
access the bits and contents of the SCM value.
|
SCM SCM_PACK (scm_t_bits x) | Macro |
Takes a valid integral representation of a Scheme object and transforms
it into its representation as a SCM value.
|