Using Pointers

Many VTScada functions require or return pointers. A pointer is a reference to the memory address where a variable's value is stored. You can create a pointer variable by using the & notation in front of an existing variable name.

For example

Y = 7;   { "Y" is a the name of a variable, within which is stored the number "7" }
Ptr = &Y;  { ptr is the name of a variable, within which is stored a pointer to the memory address of Y }

Pointers must be dereferenced before the data they point to can be used. Dereferencing means accessing the value stored in the assigned memory location. A pointer can be dereferenced by placing an asterisk before it. For example:

X = *Ptr + 1;

A dereferenced pointer can be used to store a new value into the location or object at which it is pointing. For example:

Ptr = &Y;
*Ptr = 7;

This is equivalent to the expression "y = 7;".

If the pointer "ptr" is used in any expression requiring a value other than a pointer value (for example, a numeric value), the result is invalid, as "ptr" is a pointer to a value, not a value itself. For example:

W = Ptr + 1

In this example, w is set to invalid, as the pointer "ptr" was not dereferenced. VTScada will not take this to mean the next memory address (VTScada does not support pointer arithmetic). What should have been written is:

W = *Ptr + 1