NextPrevUpTopContentsIndex

3.2 Pointer testing functions

A number of functions are provided for testing various properties of pointers. The most basic, pointerp, tests whether an object is a pointer. In the following examples the first expression returns nil , because 7 is a number, and not a pointer. The second returns t because point4 is a pointer.

(fli:pointerp 7) (fli:pointerp point4)

The address pointed to by a pointer is obtained using pointer-address. For example, the following expression returns the address pointed to by point4 , which was defined to be 100 .

(fli:pointer-address point4)

Pointers which point to address 0 are known as null pointers . Passing the Lisp object nil instead of a pointer results in nil being treated as a null pointer. The function null-pointer-p tests whether a pointer is a null pointer or not. If the pointer is a null pointer the value t is returned. We know that point4 points to address 100 and is therefore not a null pointer. As a result, the following expression returns nil .

(fli:null-pointer-p point4)

Another testing function is pointer-eq which returns t if two pointers point to the same address, and nil if they do not. In the previous section we created point3 by making a copy of point1 , and so both point to the same address. Therefore the following expression returns t .

(fli:pointer-eq point1 point3)

Two functions are provided to return information about the object pointed to by a pointer, pointer-element-type and pointer-element-size. In practice, it is the pointer which holds the information as to the type of the object at a given memory location--the memory location itself only contains data in the form of bytes. Recall that point1 was defined in the previous section as a pointer to an :int . As a result the following two lines of code return 4 (the size of an :int ) and :int .

(fli:pointer-element-size point1) (fli:pointer-element-type point1)

The question of pointer types is discussed further in the next section.


LispWorks Foreign Language Interface User Guide and Reference Manual - 14 Mar 2008

NextPrevUpTopContentsIndex