This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/55040] New: dereferencing type-punned pointer
- From: "dilyan.palauzov at aegee dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 23 Oct 2012 18:25:00 +0000
- Subject: [Bug c/55040] New: dereferencing type-punned pointer
- Auto-submitted: auto-generated
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.