Array Bug or not Bug?

 
Hi SLAWA,

//If I have four element array:

int time[4];
.
.
.
.
//Is the following equivalent to write all elements to "0"?

time[4]={0,0,0,0};
ArrayInitialize(time,0);

//If yes than the first does not work.
 
int aiTest[4];
int time[4];
time[4]={0,0,0,0};
int time2[4]={0,0,0,0};
string asTest[4];
Print("aiTest[2]=",aiTest[2]," asTest[2]=",asTest[2]," time[2]=",time[2]," time2[2]=",time2[2]);

it does work? Take care.
 
int aiTest[4];
int time[4];
time[4]={0,0,0,0};
int time2[4]={0,0,0,0};
string asTest[4];
Print("aiTest[2]=",aiTest[2]," asTest[2]=",asTest[2]," time[2]=",time[2]," time2[2]=",time2[2]);

it does work? Take care.

//Try this one!
//It does not work for me.
int time2[4];

time2[0]=01038971;
time2[1]=31038972;
time2[2]=21038973;
time2[3]=11038974;

time2[4]={0,0,0,0};


Print("time2=",time2[2]);
 
from experimentation and of the example Slawa has shown the curly braces are only to be used to initiate the values for the array elements:
int time2[4] = {01038971,31038972,21038973,11038974};
Print("time2[2]=",time2[2]); // 21038973
time2[2]=0;
Print("time2[2]=",time2[2]); // 0
Take care.
 
from experimentation and of the example Slawa has shown the curly braces are only to be used to initiate the values for the array elements:
int time2[4] = {01038971,31038972,21038973,11038974};
Print("time2[2]=",time2[2]); // 21038973
time2[2]=0;
Print("time2[2]=",time2[2]); // 0
Take care.

Well, that does not make any sense!
The initialization is writing a value into array element which is different from current value.
So if you have a code and intialize your array with the curly braces within the init() function it will work on load.
However, subsequent "Refresh" from the dropdown menu will not reinitialize your array because some value is written in it, causing an error.
This is serious BUG .
 
The array is refreshed, change the chart time frame and init() is called as well as global variables initiated before the init(). Take care.
 
The array is refreshed, change the chart time frame and init() is called as well as global variables initiated before the init(). Take care.

I guess that we are on different wave length.
My original question was:
//Is the following equivalent to write all elements to "0"?
time[4]={0,0,0,0};
ArrayInitialize(time,0);
So the answer is NO!

As to your concept:

If I define array "init time[4];" external to all functions than I cannot use subsequent "init time[4]={0,0,0,0};" in start() or init() function as needed.
So in order to do Refresh, the use of curly braces as initialization of global array is impractical if the initialization is global to other subroutines.
FYI, compile, change of properties, Refresh will perform somewhat different initializations in init(). They are not same.
For example:
in SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
The buffer line width "2" will not get initialized after compile or by Refresh.
Only after load or change of property.
 
int time[4];
.
.
.
//Is the following equivalent to write all elements to "0"?
time[4]={0,0,0,0};
ArrayInitialize(time,0);

NO
In first line: int time[4] // variable "time" has been initialised by MT4 as {0,0,0,0}

In line 6: time[4]={0,0,0,0}; program is referencing element number 5?

If the program requires all elements set back to zero use:
ArrayInitialize(time,0)
Or to recycle the variable use:
int time[4]

The setting up of the array can be initiated anywhere in the program, the filling in of the values for the elements can be carried out anywhere in the program.
 
int time[4];
.
.
.
//Is the following equivalent to write all elements to "0"?
time[4]={0,0,0,0};
ArrayInitialize(time,0);

NO
In first line: int time[4] // variable "time" has been initialised by MT4 as {0,0,0,0}

In line 6: time[4]={0,0,0,0}; program is referencing element number 5?

If the program requires all elements set back to zero use:
ArrayInitialize(time,0)
Or to recycle the variable use:
int time[4]

The setting up of the array can be initiated anywhere in the program, the filling in of the values for the elements can be carried out anywhere in the program.

Thanks for clarifying some issues.
My confusion started by assuming that
.
.
int time[4] = {0,0,0,0};
// is same as
time[4] = {0,0,0,0};

//and that it is curly braces which determine the status of the array, which is still most logical conclusion in this case.
 

time[4]={0,0,0,0};

There is invalid expression.
It should be
int time[4]={0,0,0,0};


or as sx ted has written

int time2[4] = {01038971,31038972,21038973,11038974};


In your case You attempt to assign fifth element. Check GetLastError - it should be "out of range"

 

time[4]={0,0,0,0};

There is invalid expression.
It should be
int time[4]={0,0,0,0};


or as sx ted has written

int time2[4] = {01038971,31038972,21038973,11038974};


In your case You attempt to assign fifth element. Check GetLastError - it should be "out of range"


Thanks Slawa,
Should this work with string?
string time[4];
.
.
.
ArrayInitialize(time,"");
Reason: