ArrayInsert() issues with fixed arrays and docs

 
   //--- destination array
   int c[10];
    for(int i=0;i<10;i++) 
      c[i]=i; 
      
   //--- source array   
   int d[10]; 
   for(int i=0;i<10;i++) 
      d[i]=10+i; 
      
//--- display arrays before inserting the elements 
   Print("Arrays c[10] and d[10], before calling ArrayInsert()"); 
   ArrayPrint(c); 
   ArrayPrint(d); 
//--- insert 3 elements from the source array and show the new set of the receiving array 
   ArrayInsert(c,d,4,0,3); 
   Print("After calling ArrayInsert(c,d,4,0,3)"); 
   ArrayPrint(c);

//Output:
/*
Arrays c[10] and d[10], before calling ArrayInsert()
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
After calling ArrayInsert(c,d,4,0,3)
0 1 2 3 4 5 6 7 8 9

*/


Also, documentation doesn't fit with the test:

If the function is used for a fixed-size array, the size of the dst_array[] receiving array itself does not change. Starting from the dst_start position, the elements of the receiving array are shifted to the right (the last counts of the elements "come off"), while the elements copied from the source array take their place.

And this shows an overwriting, not a "come off":

/*
  Execution result
   Before calling ArrayInsert()
   0 1 2 3 4 5 6 7 8 9
   After calling ArrayInsert()
   0 1 2 3 10 11 12 7 8 9
*/


Anyway, if arrays are dynamic, they work fine.

 
Florin Ionesko:

Testing ArrayInsert() in the code example on ArrayInsert() gives:

ERR_ARRAY_RESIZE_ERROR

4007

Not enough memory for the relocation of an array, or an attempt to change the size of a static array


So I suspect that MetaQuotes has changed the way ArrayInsert() works for static arrays and hasn't updated the documentation to suit.

 

Modify

int array_dest[10]; 

to this

int array_dest[]; 
ArrayResize(array_dest,10);