bcc icon indicating copy to clipboard operation
bcc copied to clipboard

Array of Struct index data is copied instead of referenced

Open davecamp opened this issue 3 years ago • 8 comments

Win x64 v129.3.45 release

SuperStrict

Struct Test
	Field x:Float
	Field y:Float
	Field z:Float
	
	Method Set(x_:Float, y_:Float, z_:Float)
		x = x_
		y = y_
		z = z_
	EndMethod
EndStruct

Local data:Test[5]
For Local i:Int = 0 Until 5
	data[i].Set(i, i, i)
Next

I was expecting this code to alter the Struct instance values at the index of the array. However the output code works on a temporary copy of the struct data from the index, and then the copy goes out of scope without affecting the contents of the array.

c output for the 'For loop' creates a copy to do the work with, which gets discarded without affecting the array contents.

BBINT bbt_i=0;
for(;(bbt_i<5);bbt_i=(bbt_i+1)){
	struct _m_untitled1_Test bbt_=((struct _m_untitled1_Test*)BBARRAYDATA(bbt_data,1))[((BBUINT)bbt_i)];
	__m_untitled1_Test_Set_v_fff((struct _m_untitled1_Test*)&bbt_,((BBFLOAT)bbt_i),((BBFLOAT)bbt_i),((BBFLOAT)bbt_i));
}

davecamp avatar Jul 06 '21 01:07 davecamp