Declares the name of a structure and gives its implementation.
Struct struct_name [ type_list ] [ Is base_type ] [ Does trait_name ]… [ Where generic_constraints ] … [ data_members ] [ procedure_members ] End [ Struct ]
- Mandatory name for the structure.
- Optional. See Type List for more information.
- Optional value type:
an elementary data type (
Intfor example) or the name of a different structure.
- Optional keyword that you can use again and again.
- The name
Doesis a trait, a construct that specifies behavior. See Does Clause (Traits) for more information.
- Optional keyword that you can use again and again. See Where Clause (Generics) for more information.
- Mandatory one or more declaration statements.
You can use
- Optional procedure declarations.
You can use
- Completes the statement.
You can also use
- You can change this part of the syntax. See @Option Directive for more information.
Struct is short for “structure”.
You can put a structure only in some locations.
These include modules (
Library), and declarations of
You cannot put a structure in a procedure.
See Declaration Contexts and Default Access Levels for more information.
A bit field is an integer member with a width in bits specified in code.
You use the data types
UBits only in a structure.
You must supply the width between parentheses after one of these keywords.
The width must be an integer literal in the range 1 thru 128.
Optionally you can supply a value type between the keyword and the left parenthesis, written between brackets (
This is known as the storage boundary type.
If supplied, then the width must be in the range one thru the size of the type in bits.
UBits is short for “unsigned bit field”.
SBits is short for “signed bit field”.
When you use
SBits, the most significant bit is reserved as a sign bit.
If you supply a storage boundary, then each field uses some number of bits from the storage. You typically try to use all of the bits in one or more field declarations. But if there are bits that are not used, then these are known as padding.
If a structure mixes bit fields and named types, then the named types will usually be put in boundaries. The type of CPU sets the boundaries, counted from the start of the Struct: Intel processors usually have 8-bit boundaries, while Motorola processors usually have 16-bit boundaries. A bit field must not go across a boundary.
- Nested structures
- You can put one structure in a different structure. The outer structure contains the inner (or nested) structure. But you cannot get access to the elements of an inner structure through the outer structure. You must declare a variable with the data type of the inner structure.
- Member declaration
- Traits, supplied with the clause
Does, must be abstract. You must supply implementations for all procedures declared by all the traits.
- Access level
- Structures and their members are public by default.
But the procedure types
subare always private.
- A structure is in scope all through its container element (namespace, module, class, or structure). The scope of all members of a structure is the full structure.
- A structure, as a data type, does not have a lifetime. But each instance of a structure has a lifetime. You control the lifetime of an instance by how and where you declare it.
- Code that is not in the structure must qualify the name of a member with the name of that structure. If code in an inner structure refers to an un-qualified name, then ViviFire tries to find it in the inner structure. If it does not find the element, then it tries the next outer block in sequence.
- Memory used
Struct point x As Real64 y As Real64 End Struct