Struct Access Operators

You can address collections of Structs by name and individual Structs by name and index using the Struct access operators—the de-reference operator (->) and the index operator ({N}).

A variable or parameter of type struct is an ordered collection of references to one or more Structs. A collection of one can be treated as an individual Struct.

Each Struct in the collection may or may not have a name, and may include multiple members with the same name. You therefore need to be able to access Structs by name (if they have one) or by their index position in the Struct (if they do not have a name, or there are multiple members with the same name).

Struct Access Operators
Operator Symbol Syntax Description
De-reference operator ->

Variable->Name

Returns a collection of references to all Struct members with the specified name.
->* Variable->* When used with the * asterisk wildcard, it returns a collection of references to all members of a Struct.

Important: The * wildcard can only be used after the dereference operator. It cannot be used in constructs such as vStruct->c* to get all Structs whose names begin with c.

Struct index operator

{N}

Variable->Name{N}

Returns a reference to a single member of a Struct based on its index position in the collection of references.

Access Structs by Name or Index

The Struct access operators enable you to:

  • Access members by name; for example, get all Struct members named chapter:
    vBookStruct->chapter
  • Access members by name and index; for example, get the second member named chapter.
    vBookStruct->chapter{2}
  • Get a collection of Structs; for example, get all members of the Struct referred to by variable vBookStruct:
    vBookStruct->*

    This returns the title, toc, preface, and all chapter members.

  • Get all members in several Structs; for example, get all members of all Struct nodes called chapter:
    vBookStruct->chapter->*

    This returns title and section members.

  • Access a Struct from a collection by its index position only; for example, get the second member in a Struct, regardless of its name:

    vBookStruct->*{2}

Related Topics