possible loss of data due to type conversion

Back to topics list To post a new topic, please log in or register
avatar
17
Donex 2015.02.01 00:18
 

My EA always compiled without any warnings, but recently decided to compile again and have been getting these warnings.


For the life of me, I cannot work out why as I'm storing the return value of the File* functions in the correct variable type and only

using those variables as int values in the rest of my code

void StoreOrderOpenPrice(string argFile, int argTicket, string argPair, int argType, double argPrice)
{
   int handle = FileOpen(argFile, FILE_READ|FILE_WRITE|FILE_CSV, ',');

   if(FileSize(handle) > 0)
      FileSeek(handle, 0, SEEK_END);

   if(handle < 0)
      Print(GetErrorDescription(GetLastError()));

   int recorded = FileWrite(handle, argTicket, argPair, argType, argPrice);

   if(recorded < 0)
      Print(GetErrorDescription(GetLastError()));

   FileClose(handle);
}
avatar
Moderator
3419
GumRai 2015.02.01 00:52 #
 

FileWrite returns a uint, not an int.

Also note that it returns zero in the case of an error, so your error reporting will not work correctly 

avatar
Moderator
3419
GumRai 2015.02.01 00:54 #
 
Double click on the warnings and the cursor will show you exactly where they are in the code.
avatar
17
Donex 2015.02.01 01:47 #
 

Thx GumRaj all fixed,   replaced  "  < 0  "  with   " == 0" for the error checking.


cheers

Back to topics list  

To add comments, please log in or register