Next: Raw data functions, Previous: Type declarations, Up: Declarations
If a lexical variable is declared to be of fixnum, character
,
short-float
, long-float
, or their subtypes, then it is allocated
on the C stack rather than on the value stack. In addition, the variable
always has a raw datum as its value: 32 bit signed integer for fixnums, 8 bit
character code with 24 bit padding for characters (remember that the font and
bit fields of ECL characters are always 0), 32 bit floating point
representation for short-floats, and 64 bit floating point representation for
long-floats. Similarly, if a lexical variable is named in an object
declaration (see Section 7.1), then it is allocated on the C stack but, in this
case, the variable always has a cell pointer as its value. The user is
strongly recommended to make sure that objects stored in such an object
variable may never be garbage collected unexpectedly. For example,
(do ((x (foo) (cdr x))) ((endp x)) (let ((y (car x))) (declare (object y)) (bar y)))
this object
declaration is completely safe because the value of the
variable y is always a substructure of the value of x, which in
turn is protected against garbage collection. Incidentally, loop variables of
dolist
may always be declared as object variables, since the
dolist
form has essentially the same control structure as the do
form above. On the other hand, the result of evaluation of the following form
is unpredictable, because the cons cell pointed to from the object
variable z may be garbage collected before bar
is called.
(let ((z (cons x y))) (declare (object z)) (foo (cons x y)) (bar z))
Lexical variables that are not declared to be of fixnum,
character, short-float, long-float, or their
subtypes, and that are not named in object
declarations are usually
allocated on the value stack, but may possibly be allocated on the C stack
automatically by the compiler.