Any changes in C23's aliasing rules (or a gcc problem?)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Just came across the following test case

#include <stdio.h>

int main (void)
{
  float a = -248.75;
  printf ("%f\n", a);

  unsigned char* ptr = (unsigned char*) &a;
  for (size_t i = 0; i < sizeof (a); i++)
  {
    printf ("%.2X ", ptr[i]);
  }
}

Compiled with gcc v13.2 (or master) and -O3 -std=c2x.

The for loop prints "00 00 00 00" which is because "a"
is not written to the frame, but read in the loop thus garbage.

With -fno-strict-aliasing, output is "00 C0 78 C3" as expected.

https://godbolt.org/z/GMcez7M95

What am I missing?

Johann




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux