Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing parameter by reference to a procedure

Status
Not open for further replies.

adekunleadekoya

Programmer
May 19, 2008
30
What is wrong with this code ?

/*******************************

set i 30;

proc test {x} {

upvar 1 $x xy;

set x 4;

set xy 2;

return $xy;

}

test $i;

puts $i;

**************************************/






 
To explain the original error, the line of code:
test $i
is parsed as
test 30
because you assigned i a value of 30. Subsequently in your procedure the variable x now has a value of 30. You were doing an upvar against the value 30. You wanted to do an upvar against the value i. Then
upvar 1 $x xy
would parse as
upvar 1 i xy
Which would then cause xy to point to the same thing as i is pointing to. Then, changing xy in the routine will change i globally.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top