Download MetaTrader 5

Possible loss of data due to type conversion bug?

To add comments, please log in or register
niquedegraaff
63
niquedegraaff  

The next very simple piece of code...

// Get chart dimensions
int chart_height = ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS, 0);

 .. produces a beautiful compiler warning.. :

possible loss of data due to type conversion Nique - BO5M.mq4 64 22

Is this a bug?
Fernando Carreiro
2279
Fernando Carreiro  
ChartGetInteger() returns a "long", not an "int".
niquedegraaff
63
niquedegraaff  
Then they need to fix this doc:
Example:
void OnStart()
  {
   int height=ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0);
   int width=ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);
   Print("CHART_HEIGHT_IN_PIXELS =",height,"pixels");
   Print("CHART_WIDTH_IN_PIXELS =",width,"pixels");
  }
https://docs.mql4.com/chart_operations/chartgetinteger
Fernando Carreiro
2279
Fernando Carreiro  
The docs are correct! It is just the example that is outdated for "strict" compilation, although probably still valid for the old style of non-strict compilation.
To add comments, please log in or register