with-cast-pointer — Wraps a body of code with a pointer cast to a new type.
Macro
with-cast-pointer(binding-name ptr type) & body body=> value
binding-nameA symbol which will be bound to the casted object.
ptrA pointer to a foreign object.
typeA foreign type of the object being pointed to.
The value of the object where the pointer points.
Executes BODY with POINTER cast to be a pointer to type TYPE. BINDING-NAME is will be bound to this value during the execution of BODY. This is a no-op in AllegroCL but will wrap BODY in a LET form if BINDING-NAME is provided. This macro is meant to be used in conjunction with DEREF-POINTER or DEREF-ARRAY. In Allegro CL the "cast" will actually take place in DEREF-POINTER or DEREF-ARRAY.
(with-foreign-object (size :int)
;; FOO is a foreign function returning a :POINTER-VOID
(let ((memory (foo size)))
(when (mumble)
;; at this point we know for some reason that MEMORY points
;; to an array of unsigned bytes
(with-cast-pointer (memory :unsigned-byte)
(dotimes (i (deref-pointer size :int))
(do-something-with
(deref-array memory '(:array :unsigned-byte) i)))))))