For union only initialize the first member, swap the fields and the test will run. Let's think if it's worth to change behavior to become what most users expect.
Consider that I have changed - now I check the 1st term for x[i].i == 0 (before the condition was x[i].x == 0.0)
union X {
int i;
double x;
};
voidOnStart()
{
X x[10000] = {}; //(*)bool b = true;
for ( int i = 0; i < ArraySize(x) && (b = (x[i].i == 0)); i++ );
Print( b );
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
ZS: I've also seen macros like
I don't get it.
I don't get it.
there is a lot of information online about the convenience of such a macro, google "macro while 0"
https://russianblogs.com/article/9410298326/
There was an example of while(0) in this thread a long time ago
https://www.mql5.com/ru/forum/170952/page141#comment_12897922
To make it clear, it is only for static (this is all about C++). For local variables, if there is a user c-tor, there is no nulling.
I liked the explanation itself, which does not contradict OOP in any way.
When you create a simple structure object, the following happens:
When the declaration goes through {}, another one is inserted between items 1-2 - filling the allocated memory with zeroes.
With this logic, OOP does not suffer in any way. It is a valid mechanism.
When {} is declared, another one is inserted between points 1-2 - filling the allocated memory with zeros.
With this logic, OOP does not suffer in any way. Valid mechanism.
The logic suffers here: why do we need to zero it if there will be a constructor afterwards anyway?
The logic itself suffers here: why zero out if there will be a constructor afterwards anyway?
Because a structure with a constructor cannot be used in a union.
For union only initialize the first member, swap the fields and the test will run.
Let's think if it's worth to change behavior to become what most users expect.
Consider that I have changed - now I check the 1st term for x[i].i == 0 (before the condition was x[i].x == 0.0)
Result: false
And with ZeroMemory - true
there is a lot of information online about the convenience of such a macro, google "macro while 0"
https://russianblogs.com/article/9410298326/
All this mess is just to put a semicolon at the end of a macro. I use curly brackets in macros everywhere and have no problems.
Consider that I have changed - now I check the 1st term for x[i].i == 0 (previously the condition was x[i].x == 0.0)
Result: false
And with ZeroMemory - true.
Yes. mql bug
(and in C++ it returns true).