This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/55040] New: dereferencing type-punned pointer


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55040

             Bug #: 55040
           Summary: dereferencing type-punned pointer
    Classification: Unclassified
           Product: gcc
           Version: 4.7.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: dilyan.palauzov@aegee.org


Compiling

root@home:~ # cat strict-aliasing.c
 #include <stdio.h>
#include <string.h>

int main() {
  char x[10];
  float y = 1.28;
  float *z = (float*)x;
  memcpy(x, &y, sizeof(float));
  printf("%f\n", *(float*)x);
  printf("%f\n", *z);
  return 0;
}

with gcc -O2 -Wall strict-aliasing.c -o strict-aliasing
prints:
  strict-aliasing.c: In function âmainâ:
  strict-aliasing.c:9:3: warning: dereferencing type-punned pointer will break
strict-aliasing rules [-Wstrict-aliasing]

which is a warning for the first printf, but not for the second printf. 
According to my understanding, there is no difference between the first and
second printf, so there shall be even number of warnings.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]