•  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-FileSWAP a,b
SWAP e(),f()
SWAP *c,d()

a, b: avar or svar
c: pointer to an array descriptor
d, e, f: names of arrays

In its most simple variant the instruction SWAP serves to exchange two
variables of the same type (SWAP a,b), In addition, it can be used for
exchanging two arrays. The process is fast, since in fact only the associated
Descriptors are exchanged, having the effect of also exchanging the
dimensioning of the two arrays. Arrays do not need to be dimensioned for this.
The third variant, where one of the descriptors is addressed directly, is
mainly useful for the indirect passing of arrays to subroutines (see second
example).

Note: The instruction SWAP should be clearly differentiated from the
      function SWAP(), which is discussed in the section on bit operations.

Examples:

    x=1
    y=2
    PRINT x,y
    SWAP x,y
    PRINT x,y

--> The numbers 1, 2, and then 2 and 1 are displayed.

    DIM x(3)
    change(*x())
    PRINT x(2)
    '
    PROCEDURE change(adr%)
      SWAP *adr%,a()
      ARRAYFILL a(),1
      SWAP *adr%,a()
    RETURN

--> The array x() is filled with 1's in the procedure CHANGE without reference
    to the name x(), so the subroutine is of general use. The Descriptor
    address is handed over to the subroutine and by means of SWAP, the array is
    addressed under the name a().

In Version 3 the array name itself can be passed:

    DIM x(3)
    change(x())
    PRINT x(2)
    '
    PROCEDURE change(VAR a())
      ARRAYFILL a(),1
    RETURN