StringToShortArray - MQL4

 
struct s
  {
   int               i;
   ushort            u[6];
   double            d;
  };

void OnStart()
  {
   s s1;
   ushort u[6];
   string txt="string to be copied";
   Print(StringToShortArray(txt,u)," characters copied to the static array u[6]");
   Print("contents of u[6] array: ",ShortArrayToString(u));
   Print(StringToShortArray(txt,s1.u)," characters copied to the array inside the s1 structure");
   Print("contents of the array inside s1: ",ShortArrayToString(s1.u));
  }

output:

20 characters copied to the static array u[6]

contents of u[6] array: string to be copied

0 characters copied to the array inside the s1 structure

contents of the array inside s1: 


Question 1: Why and how it copies 20 elements into a 6 element static array?

Question 2: Why the same does not happen when the target array is inside a struct?





 
MAD:

output:

20 characters copied to the static array u[6]

contents of u[6] array: string to be copied

0 characters copied to the array inside the s1 structure

contents of the array inside s1: 


Question 1: Why and how it copies 20 elements into a 6 element static array?

Question 2: Why the same does not happen when the target array is inside a struct?





Unlike MT5, MT4 resizes static arrays(which is what StringToShortArray() does) , with the exception of class and struct members.

struct s
  {
   int               i;
   ushort            u[];
   double            d;
  };