public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/20708] New: strict aliasing warning
@ 2005-04-01  5:32 varun0005 at gmail dot com
  2005-04-01  5:37 ` [Bug c/20708] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: varun0005 at gmail dot com @ 2005-04-01  5:32 UTC (permalink / raw)
  To: gcc-bugs

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;
}

-- 
           Summary: strict aliasing warning
           Product: gcc
           Version: 3.3.4
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: varun0005 at gmail dot com
                CC: gcc-bugs at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/20708] strict aliasing warning
  2005-04-01  5:32 [Bug c/20708] New: strict aliasing warning varun0005 at gmail dot com
@ 2005-04-01  5:37 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-01  5:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-01 05:37 -------
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.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-04-01  5:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-01  5:32 [Bug c/20708] New: strict aliasing warning varun0005 at gmail dot com
2005-04-01  5:37 ` [Bug c/20708] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).