MetaTrader 4 Build 574 with Updated MQL4 Language and Market of Applications Released - page 22

 
gchrmt4:

In fact, unless my brain is addled at the end of a long day, I think the MT4 behavior is not just confusing, but wrong.


In MT4, it turns out that this:

int test_int = ExampleTickCount

is not the same as this:

int test_int = (int)ExampleTickCount

If you don't do an explicit cast, then the new variable "remembers" that its value used to be unsigned, and affects future casts.

 
I have no experience with C or C++, so I get surprised multiple times a day. Just a moment ago I realized, that I can reimplement public virtual method as private, but it still can be invoked, if casted.
 
Ovo:
I have no experience with C or C++, so I get surprised multiple times a day. Just a moment ago I realized, that I can reimplement public virtual method as private, but it still can be invoked, if casted.

I don't know about Java, but what you are describing is normal - if nevertheless surprising - for C++. In effect, you can't fully re-declare public functions as private because you can indeed still invoke them via a cast of the base class.

http://stackoverflow.com/questions/5753833/c-overriding-public-private-inheritance

 
gchrmt4:

I don't know about Java, but what you are describing is normal - if nevertheless surprising - for C++. In effect, you can't fully re-declare public functions as private because you can indeed still invoke them via a cast of the base class.

http://stackoverflow.com/questions/5753833/c-overriding-public-private-inheritance


Thanks. In Java, methods cannot reduce scope in descendants. But I did not think that it was bug, I just I got surprised. I test everything I am not sure with.
 
gchrmt4:


In MT4, it turns out that this:
int test_int = ExampleTickCount

is not the same as this:
int test_int = (int)ExampleTickCount

If you don't do an explicit cast, then the new variable "remembers" that its value used to be unsigned, and affects future casts.

Just wondering why you would expect them to be the same?
 
ubzen:
Just wondering why you would expect them to be the same?

Because - unless I've got the testing of this wrong - in the first example test_int doesn't just hold a value; it also carries with it a memory of a previous use and version of that value. It's a sort of "homeopathic" int, which remembers that it used to be a uint in the same way that homeopathic remedies are supposed to remember the substance which now exists only as 1 atom per squillion particles.

Plus the fact that, as a default position, I'd expect MT4 to be similar to C.

 

Yes the question I deleted was, why does typcasting it to a long not turn it to a negative value too ? But I thought your explanation covered that ...

Here is my test script I'm using GetTickCount() because it returns a uint value.

void OnStart()
  {
   uint uticks = GetTickCount();
   int iticks = uticks;
   long lticks = uticks;

   Print("uticks = ",uticks);
   Print("iticks = ",iticks);
   Print("lticks = ",lticks);
  }

Output:

  • uticks = 3867100516
  • iticks = -427866780
  • lticks = 3867100516

 

Perhaps the conclusion Raptor and I came to earlier was the correct one, the uint is a positive value to big for an int so the int wraps around to a negative value, whereas it is not too big for a long so the long remains the same value as the uint ?

 
gchrmt4:

Because - unless I've got the testing of this wrong - in the first example test_int doesn't just hold a value; it also carries with it a memory of a previous use and version of that value. It's a sort of "homeopathic" int, which remembers that it used to be a uint in the same way that homeopathic remedies are supposed to remember the substance which now exists only as 1 atom per squillion particles.

Plus the fact that, as a default position, I'd expect MT4 to be similar to C.

Well I know only mql4. I've finished a tutorial on C++ about 2 weeks ago. I went C++ because "my" impression was that mql4+ would be closer to C++.

I wonder if anyone who visits know how C++ handles it........

I believe that mql4+ have some sort of garbage_collector / virtual memory envrionment and maybe thats why it keeps the foot_prints but I'm just speculating.

Anyways I see 2 different actions ... having 2 different results ... and I don't think theres a Right / Wrong with that.

Just perhaps what someone expects vs how its implemented.

 
SDC: Perhaps the conclusion Raptor and I came to earlier was the correct one, the uint is a positive value to big for an int so the int wraps around to a negative value, whereas it is not too big for a long so the long remains the same value as the uint ?
Yes.
Reason: