Download MetaTrader 5

How to copy a structure passed by address to a function?

To add comments, please log in or register
Mihai Ionescu
1488
Mihai Ionescu  

I have this situation:

double findStuff(double target, TMyStruct &left, TMyStruct &right, TMyStruct &_solution, double err=0.0000001) {
   TMyStruct cleft, cright;
   cleft = left; 
   cright = right;
   
   //...
}

 But it doesn't work,

I get nasty values from functions to which I pass structure members like:

lineEquation(cleft.d, val1, cright.d, val2, target);

 

After 2 days of searching for bugs, I don't know how to copy left and right structures, to cleft and cright respectively. 

Anyone help?

Mihai Ionescu
1488
Mihai Ionescu  

After some testing,

It seem that copying like this works,

The problem appears when I pass cleft.d and cright.d members to lineEquation function => there's the problem or bug 

 

If I copy cleft.d and cright.d to some double variables, and I pass these variables to lineEquation function => works flawlessly.

The nasty results appear only when I pass cleft.d and cright.d to lineEquation directly. 

Compiler issue?

Rashid Umarov
Admin
12315
Rashid Umarov  

Firstly, you should know about copying of simple structures  - https://www.mql5.com/en/docs/basis/types/casting#casting_structure

If it won't help please write to Servicedesk.

Documentation on MQL5: Language Basics / Data Types / Typecasting
  • www.mql5.com
Language Basics / Data Types / Typecasting - Documentation on MQL5
Mihai Ionescu
1488
Mihai Ionescu  
Rosh:

Firstly, you should know about copying of simple structures  - https://www.mql5.com/en/docs/basis/types/casting#casting_structure

If it won't help please write to Servicedesk.


Here is the structure:

 

struct TMyStruct {

   double d;

   double p[15][6];

   double tabel[15][15];

};

 From what I understand, this is a simple structure, and theoretically should not have a problem when copy it to a variable of the same structure.

I saw that I can print cleft.d and cright.d, and everything is fine.

The problem appears when I pass cleft.d and cright.d to lineEquation function.

The best way would be to reproduce this problem in a simple case, to prove the bug. 

 

Rashid Umarov
Admin
12315
Rashid Umarov  
Could you write to Servicedesk with details?
Get in touch with developers using Service Desk!
  • www.mql5.com
We therefore attach great importance to all user reports about issues in our programs and try to answer each one of them.
Mihai Ionescu
1488
Mihai Ionescu  
Rosh:
Could you write to Servicedesk with details?

I tried to duplicate the problem,

I kept the same everything I could,

But in the test script, it works fine.

I've made 2 screenshots, with the results in my real script, and with the results in test script.

I've put some explanations in comments

I drop this issue for now, as I have a temporary solution that it works (using 2 more variables as I explained above).

I've attached the archive with all 5 files. 

Files:
test.zip 15 kb
To add comments, please log in or register