Possible error with ArrayResize in current version (Build 600)

 

Communication with DLL doesn't work as it should. Here are two code samples:

DLL:

FANN_EXTERNAL double TestDouble(double *d){
        d[1] =1;
        d[0] =0.5;
        return d[2];
}

EA:

#import "some.dll"
   double TestDouble(double &o[]);
#import  

double out[5];

int init(){
   out[2] = 0.5;
   double t = TestDouble(out);
   Print("DOUBLE TEST: " + t + " " + out[0] + " " + out[1] + " " + out[2]);

}

Result:

2014.02.08 11:40:31.121 2011.09.06 00:00 ANNEA27 EURAUD,M5: DOUBLE TEST: 0.5 0.5 1 0.5

OTHER VARIANT:

#import "some.dll"
   double TestDouble(double &o[]);
#import  
double out[5];

int init(){
   ArrayResize(out, 10);
   out[2] = 0.5;
   double t = TestDouble(out);
   Print("DOUBLE TEST: " + t + " " + out[0] + " " + out[1] + " " + out[2]);

}


RESULT:

2014.02.08 11:57:57.976 2011.09.06 00:00 ANNEA27 EURAUD,M5: DOUBLE TEST: 0 0 0 0.5


Why?
 
exverxes:

Communication with DLL doesn't work as it should. Here are two code samples:

DLL:

EA:

Result:

2014.02.08 11:40:31.121 2011.09.06 00:00 ANNEA27 EURAUD,M5: DOUBLE TEST: 0.5 0.5 1 0.5

OTHER VARIANT:


RESULT:

2014.02.08 11:57:57.976 2011.09.06 00:00 ANNEA27 EURAUD,M5: DOUBLE TEST: 0 0 0 0.5


Why?
What is coded within TestDouble() ?
 
exverxes:

Communication with DLL doesn't work as it should. Here are two code samples:

DLL:

EA:

Result:

2014.02.08 11:40:31.121 2011.09.06 00:00 ANNEA27 EURAUD,M5: DOUBLE TEST: 0.5 0.5 1 0.5

OTHER VARIANT:


RESULT:

2014.02.08 11:57:57.976 2011.09.06 00:00 ANNEA27 EURAUD,M5: DOUBLE TEST: 0 0 0 0.5


Why?

I experienced same problem, too. I thought it was something C++ related, as I was not C++ educated. A dynamic array cannot be used as a param for dll function call. This information cost me several hours of my life.

 
Ovo:

A dynamic array cannot be used as a param for dll function call. This information cost me several hours of my life.

Eeek, the above code works fine in v509.

Have you seen any piece of documentation for v600 which says that dynamic arrays are not supposed to work, or is this a bug?

 
gchrmt4:

Eeek, the above code works fine in v509.

Have you seen any piece of documentation for v600 which says that dynamic arrays are not supposed to work, or is this a bug?


I only noticed, that dynamic arrays are not supported by structure copy. I have no idea, why they fail in parameter.
 
angevoyageur:
What is coded within TestDouble() ?

The code for TestDouble() is at the top of the page.

When compiled & run with v509, both versions of the code give the same output: DOUBLE TEST: 0.5 0.5 1 0.5

When compiled & run with v604, the two versions are different as posted above. Passing a dynamic array to the DLL is not working. I suppose that this could be a deliberate loss of functionality compared to v509 - though a very unintuitive and dangerous one - but it looks much more like a bug.

 
exverxes:

Why?

... Aaaah, it's not a bug in MT4. It's a missing compiler warning.

You're not meant to use ArrayResize on a statically declared array. If you change the code to double out[]; then the problem disappears.

(When compiling on MT5, the compiler does warn about this use of ArrayResize.)

 

Yeah, I use MT4, there is no such warning, and code worked before ;/ If it is deliberate (and if MT5 works as gchrmt4 had said, it is), then they should have documented it. I have lost quite a lot time tracking this.


By the way, it looks, like when you resize an array, old array is passed to DLL, but new array is used in MQL. You can write all you want on old array, it won't change anything, but at the same time, you won't get null pointer exception.

 
gchrmt4:

The code for TestDouble() is at the top of the page.

When compiled & run with v509, both versions of the code give the same output: DOUBLE TEST: 0.5 0.5 1 0.5

When compiled & run with v604, the two versions are different as posted above. Passing a dynamic array to the DLL is not working. I suppose that this could be a deliberate loss of functionality compared to v509 - though a very unintuitive and dangerous one - but it looks much more like a bug.

Oops,..I was a little blind.
 
angevoyageur:
Oops,..I was a little blind.

...and we should all have reached the correct answer sooner <g>

Declaring a static array and then trying to resize it is a fairly uncommon thing for a programming language to allow, and old MQL4 is relatively unusual in permitting it. Given the type of changes in the new MQL4, one of us really should have got to this answer quicker.

 
gchrmt4:

...and we should all have reached the correct answer sooner <g>

Declaring a static array and then trying to resize it is a fairly uncommon thing for a programming language to allow, and old MQL4 is relatively unusual in permitting it. Given the type of changes in the new MQL4, one of us really should have got to this answer quicker.

mql5 produce a warning :

Cannot be used for static allocated array Test.mq5 22 4

Reported to ServiceDesk.
Reason: