This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

cast float * to unsigned long *


I compiled the following code cast.c with gcc 3.2 on Redhat 8.0 / i386.

#include <stdio.h>

int main(){
  float h = 0;
  printf("%lx\n", *(unsigned long *)&h);
  printf("%lx\n", *(unsigned long *)&h);
}

But the output is different between optimization options.

$ gcc -O cast.c
$ ./a.out
0
0

$ gcc -O2 cast.c
$ ./a.out
4212a2d0
0

Is this a bug or a behavior allowed by ANSI?

SUSUKITA, Ryutaro
The Institute of Physical and Chemical Research (RIKEN)
Computational Science Division



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]