ArrayFill question

Back to topics list To post a new topic, please log in or register
avatar
1220
ggekko 2016.07.18 22:11
 

Hi guys,

This code

#define N_ARRAY 5
   int myArray[];

   ArrayResize(myArray,N_ARRAY);

   Print("Before: ",myArray[0],"/",myArray[N_ARRAY-1]);
   ArrayFill(myArray,0,WHOLE_ARRAY,7);
   Print("After: ",myArray[0],"/",myArray[N_ARRAY-1]);

 gives 0/0 in "After" line.

But this code

#define N_ARRAY 5
   int myArray[];

   ArrayResize(myArray,N_ARRAY);

   Print("Before: ",myArray[0],"/",myArray[N_ARRAY-1]);
   ArrayFill(myArray,0,ArraySize(myArray),7);
   Print("After: ",myArray[0],"/",myArray[N_ARRAY-1]);

gives 7/7.

"WHOLE_ARRAY" doesn't work.

ArraySize(myArray) does work.

Why?

Thanks


avatar
13009
WHRoeder 2016.07.19 21:38 #
 
ggekko: Why?
  1. WHOLE_ARRAY

    Used with array functions. Indicates that all array elements will be processed. Means the number of items remaining until the end of the array, i.e., the entire array will be processed

    -- Other constants - Named Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
  2. This is a user's forum not Metaquotes.
avatar
1229
FMIC 2016.08.20 17:34 #
 
According to the documentation the, ArrayFill() function does not mention that you can use a count of 0 or WHOLE_ARRAY with that function. In other words, you have assumed it does, but it actually needs an explicit count. Only some array functions allow the use of a 0 count or WHOLE_ARRAY to mean the entire array, but ArrayFill() is not one of them.
Back to topics list  

To add comments, please log in or register