with-cast-pointer
Prev | Objects | Next

## Name

with-cast-pointer — Wraps a body of code with a pointer cast to a new type. Macro

## Syntax

    	  with-cast-pointer (binding-name ptr type) & body body => value

## Arguments and Values

`binding-name`

  A symbol which will be bound to the casted object.

`ptr`

  A pointer to a foreign object.

`type`

  A foreign type of the object being pointed to.

value

  The value of the object where the pointer points.

## Description

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.

## Examples

    (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)))))))

## Side Effects

None.

## Affected by

None.

## Exceptional Situations

None.

Prev | Up | Next
+null-cstring-pointer+ | Home | def-foreign-var