Programmer Guide/Command Reference/GOSUBX: Difference between revisions
From STX Wiki
Jump to navigationJump to search
(Created page with '<code>GOSUBX <var>label</var> [<var>arguments</var>]</code> :Like <code>GOSUB</code> but no new variable namespace is created (i.e. the subroutine uses the same environment as th…') |
No edit summary |
||
Line 1: | Line 1: | ||
GOSUBX <var>subroutine</var> [<var>arguments</var>] | |||
Like the <code>[[Programmer Guide/Command Reference/GOSUB|GOSUB ]]</code> statement, <code>GOSUBX</code> will call the local subroutine starting at the <var>subrlabel</var> label, and mandatorily ending with an appropriate [[Programmer_Guide/Command_Reference/EXIT|EXIT]] statement. Note that, unlike the plain <code>[[Programmer Guide/Command Reference/GOSUB|GOSUB]]</code>, <code>GOSUBX</code> will ''not'' create a new execution environment, instead executing the subroutine ''in the execution environment of the caller'', meaning that any changes to local variables done in the subroutine will be ''permanent'' and, hence, visible to the caller. | |||
For this reason, the <code>GOSUBX</code> statement can can be a useful tool if numerous arguments and data need to be passed hither and thither, but it should be used with extreme care, because changing the variables of the callers may be done as easily unintentionally. |
Revision as of 16:46, 23 March 2011
GOSUBX subroutine [arguments]
Like the GOSUB
statement, GOSUBX
will call the local subroutine starting at the subrlabel label, and mandatorily ending with an appropriate EXIT statement. Note that, unlike the plain GOSUB
, GOSUBX
will not create a new execution environment, instead executing the subroutine in the execution environment of the caller, meaning that any changes to local variables done in the subroutine will be permanent and, hence, visible to the caller.
For this reason, the GOSUBX
statement can can be a useful tool if numerous arguments and data need to be passed hither and thither, but it should be used with extreme care, because changing the variables of the callers may be done as easily unintentionally.