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 returnsnil, because 7 is a number, and not a pointer. The second returnst becausepoint4 is a pointer.
(fli:pointerp 7) (fli:pointerp point4)
The address pointed to by a pointer is obtained usingpointer-address. For example, the following expression returns the address pointed to bypoint4, which was defined to be100.
(fli:pointer-address point4)
Pointers which point to address0 are known as null pointers. Passing the Lisp objectnil instead of a pointer results innil being treated as a null pointer. The functionfli:null-pointer-p tests whether a pointer is a null pointer or not. If the pointer is a null pointer the valuet is returned. We know thatpoint4 points to address100 and is therefore not a null pointer. As a result, the following expression returnsnil.
(fli:null-pointer-p point4)
Another testing function isfli:pointer-eq which returnst if two pointers point to the same address, andnil if they do not. In the previous section we createdpoint3 by making a copy ofpoint1, and so both point to the same address. Therefore the following expression returnst.
(fli:pointer-eq point1 point3)
Two functions are provided to return information about the object pointed to by a pointer,fli:pointer-element-type andfli: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 thatpoint1 was defined in the previous section as a pointer to an:int. As a result the following two lines of code return4 (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.