Features of the mql5 language, subtleties and tricks - page 210

 
fxsaber #:

I don't get it. Zeroing is a useful thing, so it makes sense.

There is ZeroMemory for zeroing, and this zeroing generally does not work correctly - here are examples

 
A100 #:

ZeroMemory is for zeroing, and this zeroing generally doesn't work correctly - here are examples

Works great, I use it.

 
fxsaber #:

It works great, I'm using it.

If great, then why this example with F5 hangs, but not with ZeroMemory?

And why here - it compiles with {} butnot withZeroMemory?

 
A100 #:

If great, then why is this example hanging around via F5, but not via ZeroMemory?

Because it's just another bug that will be fixed.

And why here - it compiles with {} butnot withZeroMemory

In this example {} works.

 
fxsaber #:

In this example {} works.

It's a bug that works and it will also be fixed - and it won't compile

 
A100 #:

It's a bug that works and it will be fixed too - and it won't compile

So what's the complaint? I see no reason not to use {}-mechanism in speed-critical places.

 
fxsaber #:

So what's the complaint? I see no reason not to use {}-mechanism in speed-critical places.

Becausea "great" mechanism has already had two bugs (!). At the same time there is a time-tested alternative - ZeroMemory, which is also faster (at least via F5). The choice is obvious

 
A100 #:

To the fact that the"magnificent" mechanism has already had two errors on the fly (!).

These errors have nothing to do with the combat application.

However, there is a time-tested alternative, ZeroMemory, which is also faster (at least via F5). The choice is obvious

I think there is no question which entry is more concise and logical of the following ones.

int i = 0;

int j;
j = 0;

With arrays, it's similar.

 
fxsaber #:

These errors have nothing to do with combat use.

I think there is no question which entry is the more concise and logical of the following.

It is the same with arrays.

Here's the third error (and how many others there are) at once (!):

union X {
    int i;
    double x;
};
void OnStart()
{
    X x[10000] = {}; //(*)
    bool b = true;
    for ( int i = 0; i < ArraySize(x) && (b = (x[i].x == 0.0)); i++ );
    Print( b );
}

Result: false - i.e. zeroing does not occur (!).

But with ZeroMemory

    X x[10000];      //(*)
    ZeroMemory( x ); //(**)

Result: true - everything is fine - complete zeroing

Of course, you have the right to play the lottery and use laconic entry (1 line less) instead of obviously correct one

 
A100 #:

And with ZeroMemory

Result: true - all OK - complete zeroing

struct MqlTick2 : private MqlTick {};

void OnStart()
{
  MqlTick2 Ticks[4] = {}; // OK
  
  ZeroMemory(Ticks); // 'Ticks' - not allowed for objects with protected members or inheritance
}
Reason: