I ported some code from windows (vs2010) to gcc
a piece of it looks like:
double r1 /* = some value */;
double r2 /* = some value */;
double diff = abs(r1-r2);
std::cerr<< r1 << ", " << r2 << ", " << diff<< std::endl;
it compiles on gcc (arm-linux-gnueabihf-g++ (Raspbian 6.3.0-18+rpi1+deb9u1) 6.3.0 20170516) with -Wall -Wextra
without warnings.
The result is:
0.121, 0.0709839, 0
0.015, 0.131958, 0
0.015, 0.00799561, 0
0.21, 0.00799561, 0
0.182, 0.205994, 0
0.015, 0.00799561, 0
On windows the result is correct. There are double-overloads on the abs
functions.
I am not using namespace std;
. It seems that under gcc these overloads does not exist in global namespace.
I do not know what exactly the standard says, but i would have expected at least a warning about the double->int-conversion on passing the the difference to the abs
function.
Do i have something missed? Why do i not get this warning?
abs
for integer values, considerfabs
instead (if you wish to avoid using the STL for some reason.std::
before yourabs
.#include <math.h>
instead of<cmath>
it works properly. Apparentlymath.h
brings everything into global namespace, whilecmath
selectively brings a single overload. Huh.-Wall
and-Wextra