In an attempt to convert a float value bytewise to an integer, this function returns the following unexpected GCC warnings at optimization level -O2 and -O3 on x86_64: unsigned int myfunc() { float _f=2.5; unsigned int *_x=(unsigned int *)&_f; return *_x; } gcc -O2 -Wall test12.c -c test12.c: In function 'myfunc': test12.c:4:10: warning: '_f' is used uninitialized test12.c:2:9: note: '_f' declared here It compiles correctly, at least. The warning goes away when -fno-strict-aliasing is applied.
This code is undefined for violating C/C++ aliasing rules. The warning is because of the undefinedness of the code.
>In an attempt to convert a float value bytewise to an integer, You should use memcpy instead (or an union which itself a GCC extension).
Thank you for the suggestion. I'll try the union.