Categories
C++ Visual Studio

warning C4244: ‘argument’ : conversion from ‘double’ to ‘int’, possible loss of data

Full error message: warning C4244: ‘argument’ : conversion from ‘double’ to ‘int’, possible loss of data

Error occured on Visual Studio 2003 when compiling a C++ project.

The warning occurred because i was calling the abs function and i did not have included yet the math.h file. The reason that this warning appeared was due to the abs function that was already loaded with other libraries (stdlib.h) and it had only one defined as int abs(int) but I needed the double abs(double) overload. This way the compiler needed to let me know about the implicit cast from double to int.

Example:

double y = 1.2454;
double x = abs((double)y);

Fix:

#include <math.h>

The fix in my case is the following code added to the header of the file #include <math.h>

One reply on “warning C4244: ‘argument’ : conversion from ‘double’ to ‘int’, possible loss of data”

In case of C use fabs() in place of abs()for double or float data type. As function overloading is not supported in C.
can use only abs() function for any data type in C++

Comments are closed.