[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
27.1.6.5 C arrays
C arrays are defined by the <array-type>
<array-type> →(array
<ident>)
<ident> is the name of a previously defined type. Array types are similar to pointer types except that they include their size in their type definition string. Let us suppose the array type declaration:
(type array (array ident) ...)
If ident is the name of a structure type, Bigloo automatically creates structures accessors (see section Struct and Union types). Otherwise, it creates the following functions:
- A creator:
(make-array::array)
This function allocates memory for the array array. The memory is filled with the C
Null
value. - A type checker:
(array?::bool obj::obj)
This function returns
#t
if the argument obj is of type array and#f
otherwise. - A null checker:
(null-array?::bool ::array)
This function returns
#t
if the argument obj isNull
and#f
otherwise. - An equality checker:
(=array*?::bool ::array* ::array*)
This function returns
#t
if its arguments are equal and#f
otherwise. - Accessors and mutators:
(array-ref::ident ::array ::long) (array-set!::obj ::array ::long ::ident)
These functions read and store field values.
Here is an example of a program using array types:
(module foo (extern (type double* (array double) "double [ 10 ]"))) (define (make-vect::double* x y z) (let ((vect (make-double*))) (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.