NAME

array - format of array header

SYNOPSIS

#include <basic/string.h>
#include <basic/array.h>

DESCRIPTION

Arrays are stored with a header:
/*	Basmark BASIC Compiler
 *
 * Copyright 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992
 *	by Basmark Corporation
 *	Cleveland, Ohio, USA	*/

struct array {
	union {
		short		*arr_int;
		float		*arr_flt;
		double		*arr_dbl;
		struct string	*arr_str;
		char		*arr_chr;
	} arr_ptr;
	short arr_dim;
};
Arr_ptr points to the linear list of array elements.  Arr_dim is the first dimension of the list of array dimensions.  Additional dimensions are stored after the first dimension, beyond the end of the structure.  The dimensions may be accessed in a somewhat structured fashion by assigning to a pointer the address of arr_dim and indexing off the pointer. 

The linear list of array elements is stored with the lowest order element first.  The list of dimensions is stored with lowest order dimension first. 

Normally arrays are stored in column-major order: the last subscript in the BASIC code has the lowest order.  If basic(1) is invoked with the -R switch, arrays are stored in row-major order: the first subscript in the BASIC code has the lowest order. 

Each dimension stored in arr_dim is adjusted for the OPTION BASE and represents the number of elements along the dimension.  If the OPTION BASE is zero, the number of elements is one larger than the dimension specified in the BASIC code. 

For a static array, the array header is stored in the data segment and the elements are stored in the bss segment.  The header of a static array must not be altered especially because a COMMON static array has a header in each module that uses the array. 

For a dynamic array, the array header is stored in the bss segment and space for the elements is allocated at run-time.  Before a dynamic array is dimensioned and after it is erased, the arr_ptr is zero.  The array dimensions may be altered when the array is dimensioned, but the number of dimensions may not be altered. 

An array is made available to a subprogram by a pointer to its header only.  No record is maintained of the attributes of column-major vs. row-major or static vs. dynamic, nor the values of the OPTION BASE or the number of dimensions.  Consequently, a subprogram that operates on an array in a manner dependent on these attributes and values must determine them by other means.  Usually this requires including these attributes and values in the specification of the subprogram. 

FILES

/usr/include/basic/string.h
/usr/include/basic/array.h

SEE ALSO

string(inc), array(misc), chain(misc)
common(stmt), option base(stmt)
basic(1) in the Supplemental Documentation section

from The Basmark QuickBASIC Programmer’s Manual by Lawrence Leinweber