xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

@

Pass-by-reference operator (unary): passes variables by reference.

Syntax

@ <Variable>

Arguments

<Variable>
<Variable> is the name of any valid memory variable. Field variables cannot be passed by reference.

Description

When a variable is passed by reference to a subroutine, any changes made to the variable are reflected in the calling routine once the called routine has returned.

Normally, variables are passed by value. This means that the called routine receives a copy of the passed value so that the variable's value in the calling routine remains unaffected by assignment operations in the called routine.

When a variable is prefixed with the @ operator in a function call, the called function receives a reference to the variable. The variable can then be assigned a new value in the called function. The changed value is reflected in the calling routine when the called function has finished.

Passing variables by reference is usually required when a subroutine must deliver more than one return value.

Info

See also:FUNCTION, METHOD (Declaration), PROCEDURE
Category: Operators , Special operators
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example shows the difference between a function call with
// and without the @ operator:

   PROCEDURE Main()
      LOCAL cMsg := "Hello World"

      ? GetMsg( cMsg )                 // result: Ok
      ? cMsg                           // result: Hello World

      ? GetMsg( @cMsg )                // result: Ok
      ? cMsg                           // result: Hi there
   RETURN NIL

   FUNCTION GetMsg( cString )
      cString := "Hi there"
   RETURN "Ok"

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe