On Thu, 15 Sep 2005, float_dublin wrote:

the only reason it could differ, I think is sizeof(int)!=sizeof(float),

In which case 4!=4.

I have not been able reproducing the first bahavor (when f2 is 0). Can you please try this (on your's (GCC) 4.0.1 20050727 (Red Hat 4.0.1-5)) and post results:

#include <cstdio>
#include <cstdlib>

int main() {
  float f1 = 4.5f;
  char *i=(char*)malloc(4);
  *((float*)i) = *((float*)&f1);
  float f2 = *((float*)i);

  printf("f1 = %f, f2 = %f\n", f1,  f2);
  free(i);
  return 0;
}

$ c++ -O2 -march=i686 foo.cpp
$ ./a.out
f1 = 4.500000, f2 = 4.500000


But if I modify the program slightly:

*((float*)i) = *((float*)&f1);
to
*((int*)i) = *((int*)&f1);

$ c++ -O2 -march=i686 bar.cpp
$ ./a.out
f1 = 4.500000, f2 = 0.000000

--
Lars Christian Jensen
_______________________________________________
Help-gplusplus mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to