Using typedef to create user-defined types

 

Hello,

According to documentation of MQL5 (https://www.mql5.com/en/docs/basis/types/typedef) is possible to create new types of variables, as well as the standard definitions of C.

So, if I use something like:

typedef uchar   uint8;
typedef short   int16;
typedef int     int32;
typedef ushort  uint16;
typedef uint    uint32;

It suppose to work well, but I getting this error:

'uint8' - unexpected token
'int16' - unexpected token
'int32' - unexpected token
'uint16' - unexpected token
'uint32' - unexpected token

This kind of implementation should works?


Thanks

Documentation on MQL5: Language Basics / Data Types / User-defined Types
Documentation on MQL5: Language Basics / Data Types / User-defined Types
  • www.mql5.com
Language Basics / Data Types / User-defined Types - Reference on algorithmic/automated trading language for MetaTrader 5
 
#define uint8  uchar
#define int16  short
#define int32  int
#define uint16 ushort
#define uint32 uint
 
honest_knave:
Thanks, it works
 
honest_knave:


While this works, it is not as useful as typedef, because you won't get a type warning when assigning different custom types that translate to the same base type.

Is there a reason why typedef doesn't work the way it does in C++?

 
xsgex:


While this works, it is not as useful as typedef, because you won't get a type warning when assigning different custom types that translate to the same base type.

Is there a reason why typedef doesn't work the way it does in C++?

You should write to ServiceDesk.
 

I asked ServiceDesk. Here is their's answer:


MQL5 allows only  creating pointers to functions using typedef.

No other aplications

 
xsgex: Is there a reason why typedef doesn't work the way it does in C++?

Because MetaQuotes didn't code it that way. Define your own

#define  PRICE double            // A PRICE
   #define  PRICE_MAX      (PRICE)EMPTY_VALUE
   #define  PRICE_MIN      (PRICE)0
#define     CHANGE      PRICE    // Difference of two prices.
#define  INDEX    uint           // Zero based.
   #define  INV_INDEX      UINT_MAX
#define  COUNT    uint           //  One based.
   #define  INV_COUNT      UINT_MAX
#define  MONEY    double
#define  SYMBOL   string
 
whroeder1:

Because MetaQuotes didn't code it that way. Define your own

Why? What's the benefit?
 
MarkJoy:

I asked ServiceDesk. Here is their's answer:


MQL5 allows only  creating pointers to functions using typedef.

No other aplications

Then they should update their documentation which clearly states otherwise. Nothing unusual, who cares about the documentation anyway :-d

Thanks for the feedback.

 

I'm learning mql5 with documentation. 

I tried exactly what you did for practicing but It's not working.

They should remove that explanation in official documentation!

Reason: