SPL Pointers

 

Like C/C++, SPL supports basic pointers to scalar and array variables. For example:

 

swapval(x, y)

{

    local temp;

 

    temp = *x;

    *x = *y;

    *y = temp;

}

 

a = {1, 2, 3};

b = {10, 20, 30};

 

swapval(&a, &b)

 

a == {10, 20, 30}

b == {1, 2, 3}

 

In the above example, &a refers to the address of variable a. Since x contains the address of a variable, *x refers to the contents of the variable "pointed" to by x. Pointer arithmetic is not supported. Pointer variables are used much less often in SPL than C/C++.

 

The above example can be achieved without pointer variables.

 

swapval2(x, y)

{

    return(y, x);

}

 

(a, b) = swapval2(a, b);

 

Or directly with:

 

(a, b) = (b, a);