Array Variables
The following syntax refers to an array variable:
arrayname [subscript] {[subscript]}
Syntax Notes:
• You must subscript the variable, because only scalar-valued elements (integers, floating-point, and character strings) are legal EQUEL values.
• When the array is referenced, the EQUEL preprocessor notes the number of indices but does not evaluate the subscript values. Consequently, even though the preprocessor confirms that the correct number of array indirections is used, it accepts illegal subscript values. You must verify that the subscript is legal. For example, the preprocessor accepts both of the following references, even though only the first is correct:
## float salary_array[5]; /* declaration */
salary_array[0] /* references */
salary_array[+-1-+]
• A character string, declared as an array of characters, is not considered an array and cannot be subscripted in order to reference a single character. In fact, single characters are illegal string values, since all character string values must be null-terminated. For example, if the following variable were declared:
## static char abc[3] = {'a', 'b', 'c'};
you cannot access the character "a" in an EQUEL statement with the reference:
abc[0]
To perform such a task, declare the variable as an array of three single character strings:
## static char *abc[3] = {"a","b","c"};
• Any variable that can be denoted with array subscripting can also be denoted with pointers. This is because the preprocessor only records the number of indirection levels used when referencing a variable. The indirection level is the sum of the number of pointer operators preceding the variable reference name and the number of array subscripts following the name. For example, if a variable is declared as an array:
## int age_set[2];
it can be referenced as either an array:
age_set[0]
or a pointer:
*age_set
If you use the pointer variant, you must verify that the pointer does not immediately follow a left parenthesis without a separating space, as "(*" is a reserved operator. For example:
## retrieve ( *age_set = e.age )
Note the space between the "(" and the "*".
• In an EQUEL statement, do not precede references to elements of an array with the ampersand operator (&) to denote the address of the element.
• Do not subscript arrays of variable addresses that are used with param target lists. For example:
## char target_list[200];
## char *addresses[10];
## retrieve (param(target_list, addresses))
For more information about parameterized target lists, see
Dynamically Built Param Statements (see
Dynamically Built Param Statements).