•  Back 
  •  Main 
  •  Index 
  •  Tree View 
  •  Cross references 
  •  Help 
  •  Show info about hypertext 
  •  View a new file 
Topic       : The GFA-Basic Compendium
Author      : GFA Systemtechnik GmbH
Version     : GFABasic.HYP v2.98 (12/31/2023)
Subject     : Documentation/Programming
Nodes       : 899
Index Size  : 28056
HCP-Version : 3
Compiled on : Atari
@charset    : atarist
@lang       : 
@default    : Document not found
@help       : Help
@options    : +g -i -s +z
@width      : 75
@hostname   : STRNGSRV
@hostname   : CAB     
@hostname   : HIGHWIRE
@hostname   : THING   
View Ref-FilePROCEDURE proc(var,VAR var1[,var2,...])
FUNCTION func(var,VAR var1[,var2,...])

var1, var2: any variable type

VAR-parameters allow variables themselves to be passed and not just their
contents. They make it possible, not only to pass values into a procedure or
function but also, to pass variables which can then be changed within the
procedure or function. If the command VAR is found in the parameter list of a
procedure or function, all of the variables that follow will be treated as
VAR-parameters.

With VAR-parameters, unlike with global variables there is no danger of
unintended side-effects. Using VAR-parameters complete arrays can be passed.
VAR-parameters are not allowed within the calling line to a procedure or
function, only within its definition.

Note: VAR-parameters must always appear as the last elements of a
      parameter list.

The use of VAR-parameters is generally quicker than the use of ordinary
parameters or pointers.

Examples:

    sum(13,12,a)
    sum(7,9,b)
    PRINT a,b
    PROCEDURE sum(x,y,VAR z)
      z=x+y
    RETURN

--> Two pairs of numbers are added, the values being passed to the variables a
    and b. Then the numbers 25 and 16 are printed on the screen.

    DIM a(9)
    FOR i%=0 TO 9
      a(i%)=RND
    NEXT i%
    mean(0,9,a(),m)
    PRINT "mean = ";m
    PROCEDURE mean(from%,to%,VAR array(),mean)
      mean=0
      FOR i%=from% TO to%
        ADD mean,array(i%)
      NEXT i%
      DIV mean,to%-from%+1
    RETURN

--> The arithmetic array filled with random numbers is calculated and printed
    out.

Note: In Version 2 it was possible to achieve the effect of passing local
      variables by passing their pointers. Using this method in Version 3 may
      result in the error message 'Pointer (*x) error'. It is therefore
      strongly recommended that VAR-parameters are used to pass local
      variables.