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

 
gchrmt4:

struct RateInfo defined in ExpertSample.cpp is 44 bytes long with MT4 <= 509. In the new version, each RateInfo record is 60 bytes long (for both old EAs and new EAs). Therefore, existing DLLs receiving RateInfo data from ArrayCopyRates() will stop working. Confirmed by Service Desk.

I just found this problem.

So how can I to make DLL receive the correct RateInfo data?

 
Sunaley:

I just found this problem. So how can I to make DLL receive the correct RateInfo data?

https://www.mql5.com/en/forum/148851/page15#898140 may mean that this will be changed back before launch so that old EAs use the old RateInfo structure.

If not, or if you want to recompile your EAs with the new version of MT4, then you need to change your DLL (or add a second version of each function0.

 

So re: my earlier post is it normal behaviour for a uint to change its value and turn negative when typcasted to an int ?

void OnStart()
  {
//---
   uint uticks = GetTickCount();
   int  iticks = uticks;
   Print("uticks = ",uticks,"   iticks = ",iticks);
  }

Output: uticks = 3862831595 iticks = -432135701

 
SDC:

So re: my earlier post is it normal behaviour for a uint to change its value and turn negative when typcasted to an int ?

Yes, it's a constant 32-bit value which isn't changing across the typecasting. What does change is whether the top bit is interpreted as a sign or not. Same as 0xFFFFFFFF = -1.
 

So it is not because the uint is too big for the int ? I just had a thought that maybe it is so I looked up the max values ...

 
SDC:

So re: my earlier post is it normal behaviour for a uint to change its value and turn negative when typcasted to an int ?

Output: uticks = 3862831595 iticks = -432135701


Yes,

int

4

- 2 147 483 648

2 147 483 647

int

uint

4

0

4 294 967 295

unsigned int, DWORD

uticks is too large for an int so it wraps round to a negative.

 

Yes it works properly when I change the int to a long.

 
SDC:

So it is not because the uint is too big for the int ? I just had a thought that maybe it is so I looked up the max values ...

In both cases, the sequence of bits stored in the computers memory remains constant as 11010111 10000100 01111100 01100111

What changes is how that sequence is interpreted. As an int, the top bit (marked in red) is interpreted as a sign for the other 31 bits, where 1 means "negative number". The 31-bits can have 2 147 483 648 possible values, which are interpreted as either positive or negative depending on the top bit.

As a uint, the 32 bits are simply interpreted as a 32-bit value between 0 and 4 294 967 295

 

OK yes I see what your saying now. Thanks for the explanation.

Alright I think I've got uints down, time to move on to the next step, so what is polymorphism again ? ;)

 
SDC:

OK yes I see what your saying now. Thanks for the explanation.

Answering a question which I think you've just deleted, MT4 seems to have different type-casting rules to other languages such as C.

In the following code, the negative int value becomes a positive long value:

   uint ExampleTickCount = 0xE63E21EB;
   int test_int = ExampleTickCount;
   long test_long = (long)test_int;
   MessageBox("int: " + test_int + "\r\nlong: " + test_long);

I find that surprising. In the C equivalent, the sign of the int is preserved when casting to a long int:

   unsigned int ExampleTickCount = 0xE63E21EB;
   __int32 test_int = ExampleTickCount;
   __int64 test_long1 = (__int64)test_int;
   printf("%li: " , test_long1);

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.

Reason: