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

 
fxsaber #:

You yourself reported the 4th error. Why is ZeroMemory worse than {} ? I.e. we have some unauthorized mechanism of access to private which is not detected by the compiler for some reason.

Are you reckoning that the Developers won't fix it? At one time the compilerdid not react toZeroMemory either

 
A100 #:

You yourself reported the 4th error. Why is ZeroMemory worse than {} ? I.e. we have some unauthorized mechanism of access to private which the compiler cannot detect for some reason.

I don't think it's an error. The structure doesn't have a constructor but it is being initialized. FileReadStruct - that's a really scary thing...

 
fxsaber #:

I don't see it as an error. The structure has no constructor, it is initialized. FileReadStruct is quite a scary thing then.

uint  FileReadStruct( 
   int          file_handle,        // handle файла 
   const void&  struct_object,      // структура, куда происходит считывание 
   int          size=-1             // размер структуры в байтах 
   );

Judging by the description - it is some kind of self-deception

 
A100 #:

From the description, it sounds like some kind of self-deception.

Well, yes - it's all deception.

 
A100 #:

Judging by the description, this is some kind of self-defeating

Reference to documentation without regard to copy-paste artefacts - strange.

 
fxsaber #:

Links to documentation without regard to copy-paste artifacts - strange.

I see this function for the first time at all - they could have informed me that there is an error in the description

There is a structural error in addition to the description:

struct X {
    X( int i ) : i( i ) {}
    const int i;
};
void OnStart()
{
    X x( 5 );
    FileReadStruct( 0, x, -1 ); //(1) нормально ???
    ZeroMemory( x );            //(2) Error: 'x' - not allowed for objects with protected members or inheritance
}

Why is ZeroMemory worse than FileReadStruct ?

Another hope that developers will not notice it, will postpone it or will be too lazy to fix it (underline the point)?

My argument is simple: at one time ZeroMemory compiled with all this (including private ), but they noticed it, they got hold of it and fixed it.

 
A100 #:

This is the first time I've seen this function - they could have told me there was an error in the description.

I have never looked at the description of this function. Everything is clear from the name.

Besides the description there is also a structural error:

There is no error in the following code.

struct MqlTick2 : private MqlTick {};

void OnStart()
{
  MqlTick2 Ticks[4] = {};

  uchar Bytes[];
  
  StructToCharArray(Ticks[0], Bytes);
  CharArrayToStruct(Ticks[1], Bytes);

  FileReadStruct(0, Ticks[0]);
  FileWriteStruct(0, Ticks[1]);
  
  FileWriteArray(0, Ticks);
  FileReadArray(0, Ticks);
}

Boredom will not win over convenience!


Why is ZeroMemory worse than FileReadStruct ?

You are fond of referring to documentation. It says everything there about ZeroMemory's limitations. But it does not say anything about limitations of File*. As regards ZeroMemory, I judge by what I've got. It is not convenient now, but it seems to have been done on purpose.

But if you compare these two functions, FileReadStruct works only with simple structures. This is a fundamental difference.


This subject is about the peculiarities of MQL5. I pointed to one (it does not work in MQL4). This dialog is, unfortunately, a waste of time

 
fxsaber #:

There are no errors in the following code.

You are fond of referring to the documentation. It says everything about ZeroMemory's limitations there. But it doesn't say anything about File* limitations. As for ZeroMemory, I'm relying on what I've got. It is not convenient now, but it seems to have been done on purpose.

But if you compare these two functions, FileReadStruct works only with simple structures. This is a fundamental difference in principle.

There is an error (the compiler just does not inform us about it at present) and it is this: some function (namely, FileReadStruct) external to the class gets direct access to protected members of this class, which contradicts the very concept of private, protected.

And how is this function better thanZeroMemory and hundreds of other functions? Nothing! - The Developers just haven't got down to it yet.ZeroMemory didn't specify any limitations in documentation beforeeither.But it is there now - and not because it causes you some inconveniences - but because a single principle works - eitherFileReadStruct orZeroMemory, or hundreds of other similar functions - all are equal.

 
A100 #:

that a hundred other similar functions are all equal

FileLoad/FileSave to the inequality box.

Convenience won't win out!

There's no reason to shoot yourself in the foot.

 
fxsaber #:

FileLoad/FileSave more to the inequality box.

There is no reason to shoot yourself in the foot.

It is you who are shooting yourself in the foot - by declaring private. You have limited access to yourself and then will wonder why the code where public access is required for external functions has suddenly stopped working

Reason: