| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
26.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
Nullvalue. - A type checker:
(ptr?::bool obj::obj)
This function returns
#tthe argument obj is of type ptr and#fotherwise. - A null checker:
(ptr-null?::bool ::ptr)
This function returns
#tif its argument isNulland#fotherwise. - A null creator:
(make-null-ptr::ptr*)
This function creates a
NULLvalue of type ptr*. - An equality checker:
(=ptr*?::bool ::ptr* ::ptr*)
This function returns
#tif its arguments are equal and#fotherwise. - 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 October 23, 2011 using texi2html 5.0.
