To be honest, I don't want to argue. I want to understand how compilers can follow these rules and follow f.e. (from "6.3.2.3 Pointers" of C99 standard)
A pointer to an object or incomplete type may be converted to a pointer to a different object or incomplete type.
at the same time.
And I asked you to explain the results of compiling one example... I'm afraid that the only explanation is that it is not "valid standard C program"...
As for @Khrys example. He shows that GCC's optimizer is better than FPC's one considering floats. But what is the impact of strict aliasing optimization? The code
int foo(float *f, int *i)
{
*i = 1;
*f = 0.0;
return *i;
}
compiled with gcc 14.2.0 -O2 or -O3 produces
movl $1, %eax
movl $1, (%rdx)
movl $0x00000000, (%rcx)
ret
what we see in his post.
Compiled with (-O2 or -O3) and -fno-strict-aliasing:
movl $1, (%rdx)
movl $0x00000000, (%rcx)
movl (%rdx), %eax
ret
Is there much difference in performance of
movl $1, %eax and
movl (%rdx), %eax?
At last, -fstrict-aliasing option alone has no impact on results of compilation without optimization.
And now I feel that I have to stop this discussion.