<- ^ ->

Data types

4   Data types

4.1   Pointers

There is no explicit notation of pointers. Structures and unions are always treated as pointers (as in Java). Strings are built in type. Arrays are implemented as abstract type. Pointers to functions are discussed below.

4.2   Structures

They are defined with 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.

4.3   Structure initializers

When initializing structures one has to spell field name along with expression initializing it. For example:

        struct foo {
                int bar;
                string baz;
        }

        void f()
        {
                foo qux = ({ bar = 1, baz = "quxx" });
        }
({ ... }) is also regular expression, for instance:

        void f() 
        {
                foo(({ bar = 1, baz = "qux" }));
        }
<- ^ ->

Data types