Using typedef to create user-defined types


According to documentation of MQL5 ( 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?


#define uint8  uchar
#define int16  short
#define int32  int
#define uint16 ushort
#define uint32 uint

Thanks, it works…

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++?

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

#define  PRICE double            // A PRICE
   #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

Why? What’s the benefit?