Array BUG?

Array BUG?

Postby byte-one » Thu Feb 21, 2013 3:25 pm

I make a array with arr := array(30) and then aFill(arr,{}).
When I now say aadd(arr[1],{1,2,3,4}]) all arrays in arr become this aadd() not only arr[1]!
Whe i fill the arr with aeval(arr,{|,index|aadd(arr[index],{1,2,3,4}}) then is it ok.
I use xHarbour.
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: Array BUG?

Postby nageswaragunupudi » Thu Feb 21, 2013 3:45 pm

It is not a bug. It is the expected behavior.

AFill( aArray, {} ) results in filling all elements of aArray with reference to the pointer of the same array {}

Let us see this example:

x := y := {} // both x and y contain the pointer to the same array.
So whether we use the variable x or y, we are operating on the same array.

AAdd( x, 1 ) // this is same as AAdd( y, 1 ) because x and y hold reference to the same array.
Now x[ 1 ] contains 1 and y[ 1 ] also contains 1

AFill( aArray, Array(0) ) is the recommended way. Each element is assigned with pointer to a different array.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Array BUG?

Postby byte-one » Thu Feb 21, 2013 6:09 pm

Thanks much! Is now clear.
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 107 guests