[Bug c/55040] New: dereferencing type-punned pointer
dilyan.palauzov at aegee dot org
gcc-bugzilla@gcc.gnu.org
Tue Oct 23 18:25:00 GMT 2012
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.
More information about the Gcc-bugs
mailing list