Conversion from double to int by default

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I am puzzled by the fact that g++ (4.4.1, 64-bit Gentoo) allows me to compile following line without any error:

 int value = 2.5;

Also, the following program is compiled without any error or warning using 'g++ main.cpp':

#include <stdlib.h>
#include <iostream>

int main() {
  int value = abs(2.4);
  value = 2.5;
  std::cout << value << std::endl;
  return 0;
}

I tried to search the web but I still do not have any clue why it converts from double to int by default. This seems pretty dangerous to me. Am I missing something?

 Thank you.

 IH.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux