Passing Array as a function input argument

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
17
Vlaser91 2015.09.16 19:59 #
 
I truly cannot see the issue here. If you have the solution, kindly provide it with a brief comment. Thanks
avatar
125
zirkoner 2015.09.16 21:41 #
 
Vlaser91:
I truly cannot see the issue here. If you have the solution, kindly provide it with a brief comment. Thanks

What are the parameters of your function, you wrote different things :

int arraytest(int a, int b[]);

then

int arraytest(int a, int & b);

That's not the same.

avatar
17
Vlaser91 2015.09.16 22:30 #
 
zirkoner:

What are the parameters of your function, you wrote different things :

then

That's not the same.

Based on the different comments I changed it from the initially reported declaration. My goal is to pass an array ultimately.
avatar
126
Demos 2015.09.16 23:38 #
 
Vlaser91:

Can I get some help here guys please, so I do #import the relevant .dll and then before closing the #import statement I refer to my function as

int arraytest(int a, int & b);

Then somewhere along the code I have defined the following array:

int cc[5] = { 1, 2, 3, 4, 5 };


and try to pass it as argument in the function in the following way:

Alert(arraytest(5,cc[]));


That throws a compilation erro

Alert(arraytest(5,cc[]));

r '] expression expected'

Hello,

You can read the documentation about Arrays here  https://docs.mql4.com/basis/types/dynamic_array

It says "Dynamic array object", but iti is a general info page about static arrays as well.

Well, things can at some point get complicated because you are using an external DLL, involving (most likely) pointer arithmetic. It would be easier to make it directly inside MQL, but nevertheless, you can try after import, to put this line

int arraytest(int a, int & b [] ); /* I included braces */

 

Oh, and on calling, do not put [ ],, 

Alert(arraytest(5,cc)); /* i removed braces */

 

best regards 

avatar
17
Vlaser91 2015.12.06 17:57 #
 
Demos:

Hello,

You can read the documentation about Arrays here  https://docs.mql4.com/basis/types/dynamic_array

It says "Dynamic array object", but iti is a general info page about static arrays as well.

Well, things can at some point get complicated because you are using an external DLL, involving (most likely) pointer arithmetic. It would be easier to make it directly inside MQL, but nevertheless, you can try after import, to put this line

 

Oh, and on calling, do not put [ ],, 

 

best regards 


Hi just thought I should give the community an update. Ultimately nothing worked. My guess is that it got pretty confused from the fact that I was trying to pass an INT + Array as function inputs. Ultimately I dropped the INT input (was just the array size) and I replaced it with a simple sizeof(a) command in C++ inside the .dll. It worked. Thanks all for you input!

Back to topics list   | 1 2  

To add comments, please log in or register