Depending on optimization level the output differ as follows:
With unexpected output:
$ gcc -Wall -O3 otest.c -o otest
$ otest
*x: 0
y: 2048.899902
y: 0.000000
With expected output:
$ gcc -Wall -O2 otest.c -o otest
$ otest
*x: 45000e66
y: 0.000000
y: 2048.899902
source code :
#include <stdio.h>
int main(void)
{
float y = 2048.9;
void *p = &y;
unsigned int *x = p;
printf(" *x: %x \n",*x);
*x = 0;
printf(" y: %f \n",y);
*x = 0x45000e66;
printf(" y: %f \n",y);
return 0;
}
gcc version is 4.2.1.
Am I missing any important directive ?