MetaTrader 4 Platform Update build 625: Magazines in MetaTrader Market and New MetaViewer - page 14

 
seemore:

Wow, not in my MT4 !


2014.03.28 17:44:12.245 v_exp EURUSD,M5: Alert: Volume[1] - 3214

2014.03.28 17:44:13.3343 v_exp EURUSD,M5: Alert: Volume[1] - 756

2014.03.28 17:44:10.218 v_exp EURUSD,M5: Alert: Volume[1] - 3214

2014.03.28 17:44:12.225 v_exp EURUSD,M5: Alert: Volume[1] - 756

2014.03.28 17:44:10.218 v_exp EURUSD,M5: Alert: Volume[1] - 3214

2014.03.28 17:44:11.225 v_exp EURUSD,M5: Alert: Volume[1] - 756



angevoyageur:
Ah I see your problem now. I am using build 628 and you ?


I am using 625, but I cannot see the problem and I cannot replicate it, but I am using a script as there are no ticks at the weekend.

I always have and still do use commas instead of plus signs in Alerts and Prints. I've never investigated whether using the plus sign can cause difficulties or not.

 
GumRai:


I am using 625, but I cannot see the problem and I cannot replicate it, but I am using a script as there are no ticks at the weekend.

I always have and still do use commas instead of plus signs in Alerts and Prints. I've never investigated whether using the plus sign can cause difficulties or not.


There are certain times when using comma gives different output instead of using plus signs. Applicable vice versa.
 
WHRoeder:

Complex plus returns a complex (value of Add.) Your try assignment says it returns a try but you return a reference (this.) The code crashes but I think it shouldn't compile. Try: try* operator=(...


Try it, it compiled, ran and crashed mt4.
 
williamwong:

This code crashes MT4. I was following the example in the help:

complex operator+(const complex &r) const { return(Add(this,r)); }


If the function Print() is called from within the body of "operator=":

#property strict

class try
{
int a;
public:
try operator=(try &o)
{
   Print("operator=");
   a=o.a;
   return this;
}
};

void OnStart()
  {
   try x;
   try y;
   y=x;
  }

then there is no crash and the log has a message with the reason of crashing:

edward@beast:~$ cat VMs/VBox-4.2/Windows/WinXP-32-PreSP4/Forex/Working-AlpariNZ/Host/2.txt 
19:08:04 Script 1 EURUSD,H1: loaded successfully
19:08:04 1 EURUSD,H1: initialized
19:08:04 1 EURUSD,H1: operator=
...
[An enormous number of the last message repetitions]
...
19:08:04 1 EURUSD,H1: operator=
19:08:04 stack overflow
19:08:04 1 EURUSD,H1: uninit reason 0
19:08:04 Script 1 EURUSD,H1: removed

Probably, the code "a=o.a" within the body of "operator=" causes "operator=" is called recursively rather than the member "a" is assigned a value of "o.a".

This fact and the fact your original code enforces MT4 to crash (i.e. in case when the function Print() is not called from within the body of "operator=") are definitely the faults of MetaQuotes programmers.

You can avoid stack overflow error by defining the copy constructor (and the default constructor either as when the copy one is defined by a programmer the default one in this case is not generated by the compiler automatically) because the object is copied on "operator=" returning in accordance to its current definition:

#property strict

class try
{
int a;
public:
try()
{
   Print("try()");
}
try(try &o)
{
   Print("try(try &)");
   a=o.a;
}
try operator=(try &o)
{
   Print("operator=");
   a=o.a;
   return this;
}
};

void OnStart()
  {
   try x;
   try y;
   y=x;
  }

This code produces the next messages in the log:

19:32:15 Script 1 EURUSD,H1: loaded successfully
19:32:15 1 EURUSD,H1: initialized
19:32:15 1 EURUSD,H1: try()
19:32:15 1 EURUSD,H1: try()
19:32:15 1 EURUSD,H1: operator=
19:32:15 1 EURUSD,H1: try(try &)
19:32:15 1 EURUSD,H1: uninit reason 0
19:32:15 Script 1 EURUSD,H1: removed

As you can see thanks to the function Print() calls inserted into the code that two object instances of the class "try" were constructed, then "operator=" was called and finally the copy constructor is called. The latter one is called on returning from the "operator=".

By the way, where did you find the information about operator overloading support in the updated MQL4 language from?

 
simpleton:

...

By the way, where did you find the information about operator overloading support in the updated MQL4 language from?

https://docs.mql4.com/basis/function/operationoverload
 
williamwong:

Everytime i reinstall, it creates another user folder. Any idea how do i point it to the old user folder?

angevoyageur:
You can't.


See this article Data Structure in MetaTrader 4 Build 600 and Higher


you need to use /portable mode parameter to launch any instance of mt4. I don't see why anyone does NOT use the portable mode. I install separate mt4 installations in one folder outside the program files folder.

This allows you to use the install folder for everything and keeps things much more organized, just like mt4 <b510.

 
simpleton:

If the function Print() is called from within the body of "operator=":

then there is no crash and the log has a message with the reason of crashing:

Probably, the code "a=o.a" within the body of "operator=" causes "operator=" is called recursively rather than the member "a" is assigned a value of "o.a".

This fact and the fact your original code enforces MT4 to crash (i.e. in case when the function Print() is not called from within the body of "operator=") are definitely the faults of MetaQuotes programmers.

You can avoid stack overflow error by defining the copy constructor (and the default constructor either as when the copy one is defined by a programmer the default one in this case is not generated by the compiler automatically) because the object is copied on "operator=" returning in accordance to its current definition:

This code produces the next messages in the log:

As you can see thanks to the function Print() calls inserted into the code that two object instances of the class "try" were constructed, then "operator=" was called and finally the copy constructor is called. The latter one is called on returning from the "operator=".

By the way, where did you find the information about operator overloading support in the updated MQL4 language from?

class try
  {
   int               a;
public:
   void operator=(try &o)
     {
      a=o.a;
     }
  };

This above code did not crash. If expression "a=o.a" causes a recursive call, it is strange that the 2 versions of codes behave differently.

 
nondisclosure:

I'm only seeing one value getting returned in your output. Where's the other one?

Sorted out ...


Thank you for your inputs guys!

 
angevoyageur:

Explicit type casting.

Thanks!!
 
williamwong:

This above code did not crash. If expression "a=o.a" causes a recursive call, it is strange that the 2 versions of codes behave differently.


Probably. Or probably not.

What definitely clear is that recursion takes place. And the number of its calls can be easily counted:

#property strict

uint cnt = 0;

class try
{
int a;
public:
try operator=(try &o)
{
  Print("cnt = ", cnt++);
   a=o.a;
   return o;
}
};

void OnStart()
  {
   try x;
   try y;
   y=x;
  }

Contents of the log:

01:31:21 Script 1 EURUSD,H1: loaded successfully
01:31:21 1 EURUSD,H1: initialized
01:31:21 1 EURUSD,H1: cnt = 0
01:31:21 1 EURUSD,H1: cnt = 1
01:31:21 1 EURUSD,H1: cnt = 2
...
01:31:21 1 EURUSD,H1: cnt = 160643
01:31:21 1 EURUSD,H1: cnt = 160644
01:31:21 1 EURUSD,H1: cnt = 160645
01:31:21 stack overflow
01:31:21 1 EURUSD,H1: uninit reason 0
01:31:21 Script 1 EURUSD,H1: removed

Execution of the expression "y=x;" definitely caused 160646 calls to "operator=" until stack overflow.

Reason: