2. Embedded QUEL for C : C Variables and Data Types : Variable Usage : Using a Structure Member
 
Share this page                  
Using a Structure Member
The syntax EQUEL uses to refer to a structure member is the same as in C:
structure.member{.member}
Syntax Notes:
The structure member the above reference denotes must be a scalar value (integer, floating-point or character string). There can be any combination of arrays and structures, but the last object referenced must be a scalar value. Thus, the following references are all legal in an EQUEL statement, assuming they all translate to scalar values:
employee.sal   /* Structure member */
person[3].name /* Member of element of an array */
structure.mem2.mem3.age /* Deeply nested member */
The preprocessor does not check any array elements that are referred to in the structure reference and not at the very end of the reference. Consequently, both of the following references are accepted, even though one must be wrong, depending on whether "person" is an array:
person[1].age
person.age
Structure references can also include pointers to structures, denoted by the arrow operator (->). The preprocessor treats the arrow operator exactly like the dot operator and does not check to see that the arrow is used when referring to a structure pointer and that the dot is used when referring to a structure variable. For example, the preprocessor accepts both of the following references to a structure, although only the second one is legal C:
## struct
## {
## char *name;
## int  number;
## } people[10], *one_person;

people[i]->name /* Should use the dot operator */
one_person->name
/* Correct use of pointer qualifier   */
In general, the preprocessor supports unambiguous and direct references to structure members, as in the following example:
ptr1->struct2.mem3[ind4]->arr5[ind6][ind7]
In this case, the last object denoted, "arr5[ind6][ind7]," must specify a scalar-valued object.
References to structure variables cannot contain grouping parentheses. For example, assuming "struct1" was declared correctly, the following reference causes a syntax error on the left parenthesis:
(struct1.mem2)->num3
The only exception to this rule occurs when grouping a reference to the first and main member of a structure by starting the reference with a left parenthesis followed by an asterisk. Note that the two operators, "(" and "*" must be bound together without separating spaces, as in the following example:
(*ptr1)->mem2
Because "(" and "*" are reserved when not separated by spaces, you must make sure to use the pointer operator (*) correctly after parentheses when dereferencing simple pointers. For more information, see Pointer Variables.
Structures declared with the varchar storage class do not reference the structure members. For more information, see Using a Varying Length String Variable (Varchar) (see page Using a Varying Length String Variable (Varchar)).