typedef pointer to function issue, or bug. can anyone help?

 
typedef double (*TFuncD)  (double);  //Double in, double out

int OnStart()
{
   TFuncD f=NULL;
   if (s2funcx("1", f))
    printf("nr %.2f   f(nr)=%.2f", 361, f(361.0));

   
   return(0);    
  }

double func1(double nr) {return nr/10;}
double func2(double nr) {return nr/100;}

TFuncD s2funcx(string s)
{
    if (s=="1") return func1;
    else if (s=="2") return func2;
    return NULL;
}

bool s2funcx(string s, TFuncD &func)
{
    TFuncD f = s2funcx(s);
    if (f == NULL) return false;
    return true;
}

I get this compilation error for this test script:

2019.05.09 15:05:19.565    _test_s2funcx (GER30,M1)    invalid function pointer call in '_test_s2funcx.mq5' (7,41)


For other test script i received no compilation error, but when loading the script, error: EX5 file failed to load (or something)

I cannot reproduce this error now, i will follow up with another comment, if i bump into it again.


Can somebody explain to me what it's happening?

Is it an error? is it a bug?

Because, in other parts of my code, I use those pointers to functions with success.

this is the first time i have issues with it.

 
typedef double (*TFuncD)  (double);  //Double in, double out

int OnStart()
{
   TFuncD f=NULL;
   if (s2funcx("1", f) && (f != NULL))
    printf("nr %.2f   f(nr)=%.2f", 361, f(361.0));

   
   return(0);    
  }

double func1(double nr) {return nr/10;}
double func2(double nr) {return nr/100;}

TFuncD s2funcx(string s)
{
    if (s=="1") return func1;
    else if (s=="2") return func2;
    return NULL;
}

bool s2funcx(string s, TFuncD &func)
{
    TFuncD f = s2funcx(s);
    if (f == NULL) return false;
    
    func = f;
    
    return true;
}


nr 361.00   f(nr)=36.10
 
Florin Ionesko:

I get this compilation error for this test script:

2019.05.09 15:05:19.565    _test_s2funcx (GER30,M1)    invalid function pointer call in '_test_s2funcx.mq5' (7,41)


For other test script i received no compilation error, but when loading the script, error: EX5 file failed to load (or something)

I cannot reproduce this error now, i will follow up with another comment, if i bump into it again.


Can somebody explain to me what it's happening?

Is it an error? is it a bug?

Because, in other parts of my code, I use those pointers to functions with success.

this is the first time i have issues with it.

bool s2funcx(string s,TFuncD &func)
  {
   func=s2funcx(s);
   if(func == NULL) return false;
   return true;
  }
 

thank you very much fxsaber!!

 

thank you Alain,

it's obvious now

 

EX5 failed loading error

i suspect it was because some line ending character or some other space character.

I've deleted the function that was the culprit, and reconstructed it (copied it by hand from another place)

(no change to actual code whatsoever, just wrote it again from scratch, word for word, from another file)

then the compilation error was gone.


Other than some space character, i cannot understand what would be the issue.

anyway, now everything works, thanks again

Reason: