Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: heading level fixed.

...

Code Block
bgColor#FFCCCC
langc
#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:

...