2. Embedded QUEL for C : C Variables and Data Types : Variable and Type Declarations : A Structure with a Tag and a Body
 
Share this page                  
A Structure with a Tag and a Body
The syntax of a C structure declaration with a tag and a body is:
struct tag_name {
  structure_declaration {structure_declaration}
};
where structure_declaration is:
type_specification
   member {member};
In the context of a simple variable declaration, the syntax is:
struct tag_name {
  structure_declaration {structure_declaration}
[structure_variable_name];
In the context of a type declaration, the syntax is:
typedef struct tag_name {
  structure_declaration {structure_declaration}
structure_type_name;
Syntax Notes:
Wherever the keyword struct appears, the keyword union can appear instead. The preprocessor treats them as equivalent.
Each member in a structure_declaration has the same rules as a variable of its type. For example, as with variable declarations, the type_specification of each member must be a previously defined type or another structure. Also, you can precede the member name by asterisks or follow it by brackets. Because of the similarity between structure members and variables, the following discussion focuses only on those areas in which they differ.
A structure member can be a nested structure declaration. For example:
## struct person 
## { 
##        charname[40]; 
##        struct 
##        { 
##            int day, month, year; 
##        } birth_date; 
## } owner;
Only structure members that will be referenced in EQUEL statements need to be declared to EQUEL. The following example declares a C structure with the fileloc member that is not known to EQUEL:
##  struct address {
##    int        number;
##    char        street[30];
##    char        town[20];
##    short        zip;
      FILE        *fileloc;    /* Unknown to EQUEL */
## } addr[20];
Although the preprocessor permits an initial value after each member name, do not put one there because it causes a compiler syntax error.
If you do not specify the structure_variable_name, the declaration is considered a declaration of a structure tag.
A structure variable can be initialized, but the preprocessor does not verify that the initial value is a structure aggregate.
The following example illustrates the use of a tag and a body:
## define max_employees 1500
## typedef struct employee
## {
##       char        name[21];
##       short        age;
##       double        salary;
## } employee_desc;
## employee_desc employees[MAX_EMPLOYEES];
## employee_desc *empdex = &employees[0];