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

 
A100 #:

You are shooting yourself in the foot - by declaring private. You have limited yourself access and then will wonder why the code, where external functions need public access, suddenly stops working

Everything works fine for me and will work fine. It's none of my business if you don't use private.

 
fxsaber #:

It works fine for me and will continue to do so. It's none of my business if you don't use private.

You are contradicting yourself - simple structures and private are incompatible things.

Forum on trading, automated trading systems and strategy testing

Peculiarities of mql5, tips and tricks

fxsaber, 2021.11.17 07:53

If you compare the two functions, FileReadStruct works only with simple structures. This is a fundamental difference.

Even Wikipedia knows this: plainold data(POD) isa type of data in modern high-levelprogramming languages that has a rigidly defined layout of fields in memory and does not require access restrictions and automaticcontrol.
 
A100 #:

You are contradicting yourself by writing about simple structures and private - they are incompatible things

Even Wikipedia knows this: plainold data(POD) isa data type in modern high-levelprogramming languages that has a rigidly defined layout of fields in memory and does not require restricted access and automaticcontrol.

The context was clear without reading the terminology. Simple - no strings, dynamic arrays or class objects at any nesting level.

With this definition, simple can always be a union field.

struct MqlTick2 : private MqlTick {};

union UNION
{
  MqlTick2 Tick;
  uchar Bytes[sizeof(MqlTick2)];
};

void OnStart()
{
  UNION u;
  
  ArrayInitialize(u.Bytes, 0); // обнулили u.Tick
}
private gives no guarantee of immutability from the outside. And that's a good thing.
 
fxsaber #:

The context was clear without reading into the terminology. Simple - no strings, dynamic arrays and class objects at any nesting level.

With this definition, simple can always be a union field.

private does not guarantee immutability from the outside. And this is a good thing.

Already starting to confuse the elementary - immutability is const, not private

 
A100 #:

You are already starting to get confused about elementary - immutability is const, not private

You just didn't understand what was meant. Perhaps I'm not explaining it well. It doesn't matter anymore.

 
fxsaber #:

It works fine for me and will continue to do so. If you don't use private - it's none of my business.

If you use {} instead of ZeroMemory - it can't work perfectly - I showed you this by concrete example- there is no zeroing (but you still may think otherwise)

 
A100 #:

If you use {} instead of ZeroMemory - it cannot work perfectly - I showed you this by concrete example

I'm just perfectly aware of what, where and why I apply it. The peculiarity was voiced. There was no desire to discuss tastes.

 
fxsaber #:

I'm just perfectly aware of what, where and why I apply it. The specifics were voiced. There was no desire to discuss tastes.

The reasons for not using it were voiced accordingly

 
A100 #:

If you use {} instead of ZeroMemory - it cannot work perfectly - I showed you this by concrete example- there is no zeroing (but you still may think otherwise)

For union we initialize only first member, swap fields and the test will run.
Let's consider whether we should change the behavior to the detriment of speed to make it the way most users expect it to be.


The File... appeared when privacy and constancy didn't exist, we didn't think to change this behaviour yet, as we don't consider it critical.

 
Ilyas #:

The File... appeared when privacy and constancy didn't exist, we didn't think to change this behaviour yet, as we don't consider it critical.

And there is no need to change behavior of existing functions - it is enough to add new correct functions (with some prefix/suffix) and declare previous ones obsolete with a corresponding warning

Reason: