EBSILON®Professional Online Documentation
EbsScript / EbsScript Functions / Pointer Functions
In This Topic
    Pointer Functions
    In This Topic

    Pointer Functions


    These functions are used to be able to perform pointer operations in EbsScript, as they are common e.g. in the C programming language.

    The declaration of a pointer (a reference) is done by "^" in front of the type name.

    The address of a variable is accessed by a "&" in front of the variable name.

    The content of the address to which the pointer refers (i.e. the value stored there) can be accessed by placing a "^" after the pointer variable (dereferencing).

    A variable of type pointer contains the memory address of a variable of a certain type (like integer, real...).

    Simple example:

    var realnumber : real;
        pointertoreal : ^real;
        pointertype : pointer;

    begin

        realnumber := 7.0; 
        pointertoreal := &realnumber; 
        println ("using ^ on pointer: ", pointertoreal^ * pointertoreal^);
        pointertype := pointertoreal;
        pointertoreal^ := 8;
        println ("Square: ", realnumber * realnumber);
    end.

    Ausgabe:
    using ^ on pointer: 49.0
    Square: 64.0

    Name

    Purpose

    Arguments

    Return value

    Example

    copymem

    copies a memory area.

    size = number of elementary data types.

    1: POINTER: Destination

    2: POINTER: Source

    3: INTEGER: Size

    None

     

    dispose

    releases the memory area again, which was allocated by function new to the object, to which the pointer indicates.

    1: POINTER:

    None

    var

    pi:^integer;

     

    begin

    new(pi);

    pi^:=5;

    print (pi^);

    dispose(pi);

    end;

    freemem

    releases the memory area again, which was allocated by function getmem to the object, to which the pointer indicates.

    1: POINTER:

    None

     

    getmem

    creates a new pointer and allocates the necessary memory for the object, to which the pointer indicates.

    Count > 1: array of elements

    1: POINTER:
    2: INTEGER: Count

    None

     

    new

    creates a new pointer and allocates the necessary memory for the object, to which the pointer indicates.

    Count > 1: array of elements

    1: POINTER:
    2: INTEGER: Count

    None

    var

    pi:^integer;

     

    begin

    new(pi);

    pi^:=5;

    print (pi^);

    dispose(pi);

    end;

    sizeOf

    Returns size of the Object or Variable

    Type of object or variable

    INTEGER

     var i: integer;
            arr:array[1..10] of string; type rec_t = record
            i,j:integer;
            r:real;
            end;
    var r:rec_t;
    begin
            println(sizeof(i));
            println(sizeof(arr));
            println(sizeof(r));
            println(sizeof(array [2..5]  
                        of string));
            println(sizeof(array of  
                        string)); 
    end.
    // Output

    10
    3
    4
    1

    addr

    Returns the address of the argument.
    Returns the same as the address operator &

    variable

    INTEGER

    var i: integer;
    begin
             println(addr(i));
             println(&i);
    end.
    // possible output
    0x00000a80
    0x00000a80