Passing parameters by reference

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
OhioJoe
Posts: 131
Joined: Wed Nov 22, 2017 12:51 pm
Location: United States

Passing parameters by reference

Post by OhioJoe »

This works in VO

Code: Select all

LOCAL cParam AS STRING
cParam := " "
Joe( @cParam )
?cparam  // expecting it to be "Hello"

FUNCTION Joe( cString AS USUAL ) AS VOID STRICT
	cString := "Hello"
	RETURN
But when I try in X# I get the following error:

Code: Select all

error XS9109: Argument 1 may not be passed with the '@' prefix	
nor does it allow the "REF" keyword

??

Thanks in advance for any help
Joe Curran
Ohio USA
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Passing parameters by reference

Post by Chris »

Hi Joe,

This indeed works in VO, but it shouldn't since the function is strongly typed to be accepting a USUAL by value, but the code is doing something very different, it is passing a STRING by reference.

If you change it to accept a STRING by reference, then it will work:

Code: Select all

FUNCTION Joe( cString REF STRING ) AS VOID STRICT
or you can define it to accept a USUAL by reference and instead type your LOCAL cParam AS STRING instead of USUAL:

Code: Select all

LOCAL cParam AS USUAL
FUNCTION Joe( cString REF USUAL) AS VOID STRICT
Finally, you could also remove strong typing form the function and it will work either way:

Code: Select all

FUNCTION Joe( cString ) AS VOID CLIPPER
but I would not suggest to do this, since you will lose all compile time checking.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
OhioJoe
Posts: 131
Joined: Wed Nov 22, 2017 12:51 pm
Location: United States

Passing parameters by reference

Post by OhioJoe »

Thank you, Chris.
Joe Curran
Ohio USA
Post Reply