struct and opt_struct keywords.
struct s {
int a;
string b;
};
is roughly equivalent of C's:
typedef struct {
int a;
char *b;
} *s;
So, name s can be used (only) without any struct or
opt_struct,
as type. You should note, that structures are passed by pointer (or by
reference if you prefer C++ naming style), therefore changes made to
struct inside function are reflected in state of it on the caller side.
You can access fields of structure with `.' operator.
Now, what opt_struct is all about. struct value is always
valid, i.e.
it has to be initialized with object instance, and you cannot assign
null pointer to it (BTW: null is keyword).
opt_struct's are not. They can
be initialized with null, as well as assigned null. This
involves runtime
check on each access to opt_struct value. When you try to access
opt_struct value, that is null, Null_access
exception is raised.
If you do:
void f(s1 x)
{
s1 y;
y = x;
y.fld = 0; // here you also modify x.fld
}
In general assigning values other then int's, bool's and
float's
copies pointer, not content, i.e. makes an alias of object.
[[structures are not yet implemented at all]]