BYREF
 
Syntax


FUNCTION name (parameter list)  [AS INTEGER | AS STRING | AS SINGLE]
  parameter list = parameter [, parameter list]
  parameter  =  [BYVAL] paramname [AS INTEGER] 
                    |  [BYVAL] paramname AS SINGLE
                    |  [BYVAL] paramname(size) AS STRING 
                    |   BYREF paramname AS STRING 
                    |   BYREF paramname() AS STRING 
                    |   [BYREF] paramname() [AS INTEGER]
                    |   [BYREF] paramname() AS SINGLE 

Description


Used as a modifier in parameter declarations for FUNCTIONs or SUBs.

BYREF passes a pointer to the parameter to the FUNCTION or SUB.   This allows a function to read AND write the original source parameter.

An advantage in BYREF use with STRINGs, is that extra space is not required and the STRING does not have to be copied for the FUNCTION or SUB procedure.  Constant strings may be passed BYREF, but any code that attempts to modify a constant string will cause a Data Abort.

BYVAL is assumed if nothing specified for single variables or STRINGs

Arrays of INTEGERs or SINGLEs can be passed, but are always passed BYREF, so the BYREF modifier is optional.

Example


function toupper(a(100) as string) as string 
  dim i as integer 
  
  for i=0 to 100
    if a(i)=0 then exit 
    if a(i) <= "z" and a(i) >= "a" then a(i) = a(i) - &H20
  next i
  return a
end function

main:

print toupper("asdf")                   '  will print ASDF

Differences from other BASICs

See also