Structures

Structures allow you to organize information to increase the overall clarity of your code. Much like a structure in C, these are collections of variables and their values, placed under one name.

The use of a structure is illustrated by the following example:

Mod()

[

  Dims  STRUCT[

    LENGTH;

    WIDTH;

    HEIGHT;

  ];

]

Main

[

   …

]

 

An instance of the structure Dims can now be assigned to a variable as follows:

A  =  Dims();

You can also assign values to the various nodes in the same statement:

A  =  Dims(15, 30, 45);

In either, the variable A will now contain an array that is 3 items long and that can be indexed using the keywords Length, Width and Height as defined in the structure.  In effect, Length is taken to mean "index 0 of the array stored in A",  Width will mean "index 1 of the array stored in A", etc.

The values can now be used as shown in the following examples:

Example 1:

Rval  =  A\Width;

Rval now holds the value 30.

Example 2:

A\Length  =  42;

42 is now the value stored in index position 0 of our structure.

You can also use array indexing notation to access the underlying data:

A[1] == 30;

Topics in this section:

The Theory Behind Structures

Extending Structures