...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdio.h> void f(void) { if (sizeof(int) == sizeof(float)) { float f = 0.0f; int *ip = (int *)&f; (*ip)++; printf("float is %f\n", f); } } |
Compliant Solution
In this compliant solution, the standard C function nextafterf()
is used to round towards the highest representable floating-point value:
...
When GCC 3.4.6 compiles this code with optimization, the assignment through the aliased pointer is effectively eliminated.
Compliant Solution
This compliant solution uses a union
type that includes a type compatible with the effective type of the object:
...