Bug 20708 - strict aliasing warning
Summary: strict aliasing warning
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.3.4
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-01 05:32 UTC by varun
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description varun 2005-04-01 05:32:03 UTC
since in case where you are doing "float **q=(void *)&i" then
according to strict-aliasing rules we get " warning: dereferencing type-punned
pointer will break strict-aliasing rules" , but same thing if done using a
temporary variable then why strict-aliasing warning doesn't appear.. According
to my understanding of strict aliasing if some unqualified version of pointer is
pointing to the address space then it is violating  strict aliasing rule. So in
second case also float ** pointer is pointing to the int address space then why
strict aliasing rules are not violated. If ther is some error in my
understanding of strict aliasing then please inform .

 .the exact programs are following and command line was gcc -Wall -O2
test1.c test2.c....In this why test1.c not giving warning but test2.c giving
violation of strict-aliasing warning.
//test1.c
#include <stdio.h>
#include <stdlib.h>
int main()
{ int *i;
float **q;
int **r;
i =(int *)malloc(sizeof(int));
r=&i;
q=(float **)r;
return 0;
}
//test2.c
int main(){
int *i;
float **q; 
i =(int *)malloc(sizeof(int));
q= (float **) &i;
return 0;
}
Comment 1 Andrew Pinski 2005-04-01 05:37:00 UTC
Casting to void* first, makes the aliasing warning go way.  This is expected behavior.

Realy the only undefinedness is when you access via two different types.