[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
27.1.6.3 C pointers
C pointers are defined by the <pointer-type>
<pointer-type> →(pointer
<ident>)
<ident> is the name of a previously defined type. Let us suppose the pointer type declaration:
(type ptr (pointer ident) ...)
If ident is the name of a structure type, Bigloo automatically creates structure accessors (see section Struct and Union types). Otherwise, it creates the following functions:
- A creator:
(make-ptr::ptr nb::long)
This function allocates memory for nb elements of type ident and returns a ptr to this zone. The memory is filled with the C
Null
value. - A type checker:
(ptr?::bool obj::obj)
This function returns
#t
the argument obj is of type ptr and#f
otherwise. - A null checker:
(ptr-null?::bool ::ptr)
This function returns
#t
if its argument isNull
and#f
otherwise. - A null creator:
(make-null-ptr::ptr*)
This function creates a
NULL
value of type ptr*. - An equality checker:
(=ptr*?::bool ::ptr* ::ptr*)
This function returns
#t
if its arguments are equal and#f
otherwise. - Accessors and mutators:
(ptr-ref::ident ::ptr ::long) (ptr-set!::obj ::ptr ::long ::ident)
These functions read and store field values.
Here is an example of a program using pointer types:
(module foo (extern (type double* (pointer double) "double *"))) (define (make-vect::double* x y z) (let ((vect (make-double* 3))) (double*-set! vect 0 x) (double*-set! vect 1 y) (double*-set! vect 2 z) vect)) (define (vect-norm vect::double*) (sqrt (+ (expt (double*-ref vect 0) 2) (expt (double*-ref vect 1) 2) (expt (double*-ref vect 2) 2)))) (print (vect-norm (make-vect 1.2 4.5 -4.5)))
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on March 31, 2014 using texi2html 5.0.