Friday, March 18, 2011

Harbour/xharbour Diff : 6/57 - PASSING ARRAY AND HASH ITEMS BY REFERENCE by Przemyslaw Czerpak

### PASSING ARRAY AND HASH ITEMS BY REFERENCE ###
=======================================================
Harbour supports passing array and hash items by reference, f.e.:
proc main()
local aVal := { "abc", "klm", "xyz" }, ;
hVal := { "qwe"=>"123", "asd"=>"456", "zxc"=>"789" }
? aVal[1], aVal[2], aVal[3], hVal["qwe"], hVal["asd"], hVal["zxc"]
p( @aVal[2], @hVal["asd"] )
? aVal[1], aVal[2], aVal[3], hVal["qwe"], hVal["asd"], hVal["zxc"]

proc p( p1, p2 )
p1 := '[1]'
p2 := '[2]'

Compiled by Harbour above code shows:
abc klm xyz 123 456 789
abc [1] xyz 123 [2] 789

In xHarbour only passing array items by reference works but does not work
passing hash items by reference though it does not generate either
compile time or run time errors so the above code can be compiled and
executed but it shows:
abc klm xyz 123 456 789
abc [1] xyz 123 456 789

No comments:

Post a Comment