ArrayResize() question - page 2

 
Alain Verleyen:

I removed some of my post as I confused with another thread.

It works as it is. You can't expect the language to work as you wish, YOU have to follow the language rules.

From documentation :


I've understood the situation since Marco gave the passage in docs about static arrays.

MT5 wants to make the array static when initialized like that, ok, their choice. 

But I don't like 100% followers, sorry. Like "shut up and do".

This is a forum, for talking, input, feedback, (and ideally voting)

I just put out my opinion, against MT5 devs's choice, which I find it not intuitive.

 
Marco vd Heijden:

No in the first example it should be static because you specify it will only be dynamic if it can not determine type and fill in or calculate elements.

Once you specify:

It makes all the difference.

If you want dynamic first declare open or endless situation:

then it can not know or calculate type and size so it HAS to assume dynamic.

then specify:

Resize, and then fill.

It's logical operations not intuitive.

for me it is only logically, once you specify:

it's way of managing resources here.

if this wasn't so, how would it have to calculate resources? it would not have a clue and go funky.

Marco,

I understand that you accepted their logic, as yours.

And that you don't like (my) intuition, ok.

What I'm saying, is the compiler should let the array dynamic. It should not make the array static.

Allocate, manage, whatever, but in the end, let the array dynamic.

That's my point.

 

int a[] = {0,1,2,3,4,5}; 


//should be equivalent with the following

int a[];
ArrayResize(a, 6);
for (int i=0; i<6; i++) {
  a[i] = i;
}
 
It's only logical, and this is actually working in our favor.

And if you want to blame someone, blame Bjarne Stroustrup.

Have you read his books?


Once it sees your initializer list, it will calculate size and that's the way it is / was designed.

there is more about this and why it's like that in his books i can recommend them it has to do with several things actually.

 
Marco vd Heijden:
It's only logical, and this is actually working in our favor.

And if you want to blame someone, blame Bjarne Stroustrup.

Have you read his books?



I appreciate your insistence.

I don't want to blame anyone, just want to express my opinion that's all.

I didn't  read his books.

I'm curious if, in c++, after writing your example above, the programmer would be able to resize the array.

But that's c++ anyway, not mql5.

 

I found this link   

So in c++ there are only static arrays (although a guy says you can use malloc and realloc afterwards, which means you can resize the array afterwards)

For dynamic arrays, std:vector.

=> there's no blame for Bjarne Stroustrup anyway.

So it's all about MQL5, and the decision to make the array static when initialized, which I don't agree, my opinion. 

But maybe it's a bug,  not even a conscious decision of mql5 devs.

Can you resize a C++ array after initialization?
Can you resize a C++ array after initialization?
  • stackoverflow.com
I'm learning to program, and C++ is my first language. Don't bother using pointers to show me - I don't understand them yet, and won't bother until I have more free time to dedicate to this. I was assigned (I'm not taking classes - just learning with a few friends helping me out) a merge sort algorithm, with the algorithm explained but not the...
 

yes well it has got to do with:

‘‘ability to grow’’ vs. ‘‘guaranteed to be allocated in a fixed location’’

And:

‘‘elements do not move when elements are added’’ vs. ‘‘contiguously allocated.’’

If you do not understand this, i rest my case.

 
Mihai Ionescu:

I appreciate your insistence.

I don't want to blame anyone, just want to express my opinion that's all.

I am sorry but your opinion doesn't matter. It's not a matter of opinion. No offense.
...

But maybe it's a bug,  not even a conscious decision of mql5 devs.

It's definitely not a bug.
Reason: