Hello,
given a simple code:
#include <math.h>
long hyp(long height, long base)
{
return sqrt(height * height + base * base);
}
int main(void)
{
long h = hyp(10, 20);
return 0;
}
I compile this on Debian 4.0 (gcc (GCC) 4.1.2 20061115 (prerelease) (Debian
4.1.1-21)):
#gcc -ansi -pedantic -W -Wall -lm hyp.c
As I understand, according to standard sqrt returns double, but we assign
result to long, resulting in information loss. Nevertheless I get no
warning, why is it so?
Hope it's strictly C related question.
With best regards, Roman Mashak.
given a simple code:
#include <math.h>
long hyp(long height, long base)
{
return sqrt(height * height + base * base);
}
int main(void)
{
long h = hyp(10, 20);
return 0;
}
I compile this on Debian 4.0 (gcc (GCC) 4.1.2 20061115 (prerelease) (Debian
4.1.1-21)):
#gcc -ansi -pedantic -W -Wall -lm hyp.c
As I understand, according to standard sqrt returns double, but we assign
result to long, resulting in information loss. Nevertheless I get no
warning, why is it so?
Hope it's strictly C related question.
With best regards, Roman Mashak.
Comment