[public | private] (struct | union | protocol) [name-id]
{
[ element-decl; [ element-decl; … ] ]
};
[public | private] case_union [name-id]
{
case expression1:
[ element_decl; … ]
[
case expression2:
[ element_decl; … ]
…
]
[
default:
[ element_decl; … ]
]
};
element-decl:
[ (field-decl | typedef-decl | const_decl | user-defined-type-decl) ; …]
field-decl:
type var-decl [, var-decl …] ;
var-decl:
(id | id[expression] | id:expression | id as type-id * [(expression)] )
The first syntax form allows you to define structure or union, while the second form allows you to define a case union.
When public
keyword is placed before the structure declaration, the structure becomes a public user-defined type and appears in Protocols List Tool Window. A private keyword may be used to prevent the structure from being listed in the list of user-defined types in the Structure Binding dialog. If omitted, a structure declaration is private by default. Applies only to user-defined types, declared on the global scope.
A special directives may appear within a declaration of a structure, union or a case union:
hidden:
visible:
A hidden:
directive hides all subsequent fields and visible:
directive makes fields visible. By default, all fields are visible. Hiding a field only hides it from the screen, the field remain visible when referenced in expressions.
This and subsequent sections provide an in-depth description of user-defined types.
Each user-defined type creates a scope. All enclosed constants, enumerations, typedefs, native functions and user-defined types are then included into this newly created scope.
A structure, union or case union may be nameless. Nameless types are allowed anywhere besides the global scope. A nameless type may also be used in the typedef declaration:
typedef struct
{
// …
} A;
equivalent to:
struct A
{
// …
};
while the following fragment creates a structure named A and its aliases B and C:
typedef struct A
{
// …
} B,C;