Errors, bugs, questions - page 1876

 
Compilation error
struct STRUCT
{
  long l;
  
  STRUCT( void )
  {
  }
};

union UNION
{
  STRUCT Value; // 'STRUCT' has constructor and cannot be used as union member
};
 

1. When will there be a description of the union in the documentation?

2. Is it a replacement for simple structures?

3. Will the union type conversion be supported as described for structures in the documentation?

 

here's how you can use union to copy a structure into a char array:

struct DATA
  {
   int      var1;
   uint     var2;
   float    var3;
   double   var4;
  };

union NAME_BIT
  {
   char  buff[20];
   DATA  data;
   NAME_BIT() {
      ArrayInitialize(buff, 0);
   }
  };

int OnInit() {
   NAME_BIT _space, _un_space;
   _space.data.var1 = 100;
   _space.data.var2 = 78;
   _space.data.var3 = 1.999 f;
   _space.data.var4 = .0357;
   
   ArrayCopy(_un_space.buff, _space.buff);
   
//---
   return INIT_SUCCEEDED;
}

so you can try to fix the problem here. In fact, everything that was in_space copied to_un_space, the main thing about alignment of structures not to forget about the size of the array buffer, although I changed the location of fields in the structure and the data are still copied correctly, but it's better to stick to the alignment of the structures. It's a crutch but at least it works ))

 
Alexey Viktorov:

Why is the array zeroed out twice?

)) forgot to remove, just initialise and that's it, already corrected ))
 
MetaEditor crashes on F7
union UNION
{
  uchar Bytes[sizeof(MqlTick)];
  MqlTick Tick;
};

void OnStart()
{
  UNION a, b;
   
  a = b;
}
 
Konstantin:

most likely because the size of the array needs to be declared as a constant, especially since the size of MqlTick obviously won't change ))
An array is declared as a constant. Editor crash.
 
fxsaber:
MetaEditor crashes on F7

same song, most likely due to copying a = b; without it everything is fine
 
fxsaber:
Array and is declared as a constant. Editor crash.

didn't have time to delete ))
 
Can you tell me if there are plans to add the use of a template to the union, so that you can do this:
template<typename T>
union structToBytes
{
  uchar bytes[sizeof(T)];
  T data;
};
 

What is the time of clearing the cache of the testing agent in MT5?

But in my case it turns out so - I optimized, then I run a test on real ticks, in this case I have created a cache for 6GB. When I change the date of testing, the cache is released.

But here I have a cache is overwritten in 5 minutes - is it normal? If you do not restart the test, ie, went away from the computer, came back, and he again writes to you here and there 6GB, no hard drive is not enough, will be erased.

Isn't it more logical to clear the cache when you change the test date, advisor or when you unload the terminal?