typedef Statement - Problems

 

Hi,

may be I'm a little bit foggy-brained. I'm stumbling on a simple MQL5 typedef statement.

#property strict
int OnInit() {
   typedef uint my_uint;
   return(INIT_SUCCEEDED);
}

Compiler Problem

Am' I stupid now?  What is wrong with my code? I do not understand....

Thanks for every answer

Matthias

BTW: I'm using Metaeditor Build 2769

 
Dr Matthias Hammelsbeck:

Hi,

may be I'm a little bit foggy-brained. I'm stumbling on a simple MQL5 typedef statement.

Am' I stupid now?  What is wrong with my code? I do not understand....

Thanks for every answer

Matthias

BTW: I'm using Metaeditor Build 2769

Nothing is wrong. It just doesn't work.

typedef can only be used for function pointer, despite what the documentation says.

 
Alain Verleyen:

Nothing is wrong. It just doesn't work.

typedef can only be used for function pointer, despite what the documentation says.

Thanks for your answer. You are very helpful.

The documentation seems to be out of date. 

 

I was glad to find this here too, so thanks.

Unfortunately this code example about function pointers doesn't compile either:

//--- declare a pointer to a function that accepts two int parameters
   typedef int (*TFunc)(int,int);
//--- TFunc is a type, and it is possible to declare the variable pointer to the function
   TFunc func_ptr; // pointer to the function
//--- declare the functions corresponding to the TFunc description
   int sub(int x,int y) { return(x-y); }  // subtract one number from another
   int add(int x,int y) { return(x+y); }  // addition of two numbers
   int neg(int x)       { return(~x);  }  // invert bits in the variable
//--- the func_ptr variable may store the function address to declare it later
   func_ptr=sub;
   Print(func_ptr(10,5));
   func_ptr=add;
   Print(func_ptr(10,5));
   func_ptr=neg;           // error: neg does not have int (int,int) type
   Print(func_ptr(10));    // error: two parameters needed



After that there is another function pointer example about buttons and dialogs but I didn't bother.

Edit: Found this: https://www.mql5.com/en/forum/190869
And this:
https://www.mql5.com/en/forum/313077
Reason: