next up previous contents
Next: About this document ... Up: Datatypes representation Previous: Structures   Contents

By value or by reference

Ints, floats and bools are passed by value. For floats it will require sth like this:

        float x,y,r;
        ...
        r = tan2(x,y*2);

to be translated to:

        {
                double _1, _2;
                _1 = x;
                _2 = y*2;
                r = *(double*)tan2(&_1,&_2);
        }

Value returned from tan2() has to be stored in GC_malloc'ed() area, otherwise it wouldn't typeof(tan2) would be not a subtype of *('a,'a)->'a.

Other datatypes (unions, structures, tuples and objects) are passed by reference.

There can be confusion with:

        f(*[int,int] a) 
        {
                let [x,y] = a in {
                        x = 10; 
                        y = 20
                }
        }

        g()
        {
                int x, y;

                x = 5;
                f([x,y]);
                // whatever here x is still 5, or 10?
        }

It is 5. However this more due to implementation, then to anything else, because it is inconsitent with:

        [x, y] = [10, 20];

after which x is 10 and y is 20. But this is general problem with treating variables as addresses on the left side of `='.



Micha³ Moskal 2001-11-29