Structures - Crestron SIMPL+ Reference Manual

Language reference guide
Hide thumbs Also See for SIMPL+:
Table of Contents

Advertisement

Crestron SIMPL+
Language Reference Guide - DOC. 5797G
®

STRUCTURES

A structure is a collection of one or more variables grouped together under a single
name. These variables, called structure fields or members, may consist of both integer
and string datatypes. Structures help organize related data because they allow
variables to be grouped together as a unit instead of as separate entities.
Structure datatypes can only be defined globally. Variables of a defined structure
datatype may be declared both globally and locally and passed as function arguments.
Structures are always passed to functions by reference. INTEGER,
LONG_INTEGER, SIGNED_INTEGER, SIGNED_LONG_INTEGER and
STRING are the only SIMPL+ datatypes allowed to be used as structure member
fields. INTEGER and LONG_INTEGER can include 1 and 2 dimensional arrays.
String arrays are not permitted.
The syntax for defining a structure is as follows:
STRUCTURE struct_name
{
type member1;
type member2;
.
.
.
type memberN;
};
The keyword, STRUCTURE, tells the compiler that a new datatype is being defined.
Each type is one of the SIMPL+ datatypes, INTEGER, LONG_INTEGER,
SIGNED_INTEGER, SIGNED_LONG_INTEGER or STRING. Struct_name is the
name for the structure that will be used as the new datatype.
Declaring a variable of a structure datatype is as follows:
struct_name var_name;
An example of a structure would be an entry in a phone book. The phone book
contains many entries, all containing the same three pieces of information: the
person's name, address and phone number. The structure would be defined as
follows:
STRUCTURE PhoneBookEntry
{
STRING Name[50];
STRING Address[100];
STRING PhoneNumber[20];
};
PhoneBookEntry OneEntry;
PhoneBookEntry Entry[500];
In this example, the name, PhoneBookEntry, is the datatype defined that will
encapsulate the structure fields, Name, Address and PhoneNumber. Two variables
are then defined to be of this datatype. The variable, OneEntry, is a variable that
contains one instance of the datatype, PhoneBookEntry.
Software
®
SIMPL+
67

Advertisement

Table of Contents
loading

Table of Contents