The array does not change when the method is inline

This is part of my stack class. It works fine in flash, but in cpp / windows the push method doesn't always work. I don't understand C ++ well enough to understand why this might be inconsistent.

var arr:Array<T>; public var length(default, null):Int; public function new() { clear(); } public inline function clear():Void { arr = []; length = 0; } public inline function push(t:T):Void { // Log.trace(arr) -> [] arr[length++] = t; // Log.trace(arr) -> [] } 

When push is inline, something like stack.push(0) does not always change the array, since its true length is fixed to 0 (however, the value of the length variable increases). In other cases, it works fine. If I delete the inline , it will work fine all the time.

Generated cpp on insertion (replacing stack.push(0) ):

 ::msg::utils::Stack tmp = this->stack; ::msg::utils::Stack _this = tmp; Array< int > tmp1 = _this->arr; int tmp2 = (_this->length)++; tmp1[tmp2] = (int)0; 

And when not nested (inside push() ):

 Dynamic tmp = this->arr; int tmp1 = (this->length)++; Dynamic tmp2 = t; hx::IndexRef((tmp).mPtr,tmp1) = tmp2; 

Is there something I don't see in C ++? Why does inline code work most of the time, but then fail in other cases?

Recent haxe, hxcpp, openfl etc.

+6
source share
1 answer

This is haxe / hxcpp error. I reduced it to the main case, and it turns out that it only works now if you set the array variable to a new instance, which I accidentally did in another place.

https://github.com/HaxeFoundation/haxe/issues/4187

+2
source

Source: https://habr.com/ru/post/986171/


All Articles