MT4 build 1320, MQL4 bug report: weird thing about struct

 
struct aaa
{
        ulong _u0;
        ulong _u1;

        aaa operator=( const aaa &_a )
        {
                _u0 = _a._u0;
                _u1 = _a._u1;

                return _a;
        }

        aaa()
        {
                _u0 = _u1 = 0;
        }
};

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
        aaa a;
        aaa b;
        aaa c;

        a = b = c;
}
The codes above will generate "Stack Overflow", endless "aaa::operator=" will be called forever.
Files:
mql4bug.png  8 kb
 
  1. Your function returns a copy of its argument. Which means, it has to call itself to assign the value to the copy. Infinite recursion.

    How To Ask Questions The Smart Way. 2004
              Don't rush to claim that you have found a bug.
    Questions Not To Ask
              My program doesn't work. I think system facility X is broken.

    It is almost always your code.

  2. When you do a a = (b = c), the result should be a reference to b, so you can do the a = b. Return a pointer of this.
 
William Roeder:
  1. Your function returns a copy of its argument. Which means, it has to call itself to assign the value to the copy. Infinite recursion.

    How To Ask Questions The Smart Way. 2004
              Don't rush to claim that you have found a bug.
    Questions Not To Ask
              My program doesn't work. I think system facility X is broken.

    It is almost always your code.

  2. When you do a a = (b = c), the result should be a reference to b, so you can do the a = b. Return a pointer of this.

The "a = b = c;" will be done like this if it work normally: set c to b, return c, set c to a, done.

1. don't know what do you really want to mean, but the code pass a reference of "_a" to return value, I never see any other compiler of other languages will treat "_a" as "this" or the variable which owned the function body, such as c++ or c#, this operator function will be just a set function never should be recursive. If you define it as "void operator=( aaa &_a);" then you will be not able to set "a = b = c;" but only "b = c;", "a = b;" could be done.

2. Dude, have you ever try these code on your Meta Editor? Pointer can not be applied to a "struct".

3. Thanks for reply, but you are not helping.

Reason: