------- Comment #7 from manu at gcc dot gnu dot org  2009-07-09 15:35 -------
@Jacob,

The C/C++ standards have some precise rules of what can and cannot be done
about pointer casts.

See
http://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/Optimize-Options.html#index-fstrict_002daliasing-749

See also the documentation of -Wstrict-aliasing.

This is warned by GCC by using -Wall.

m...@localhost:~$ gcc --version
gcc (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu4)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

m...@localhost:~$ g++ -Wall  -O2 pr40698.c -c
pr40698.c: In function ‘TwoPointers InterlockedExchange(TwoPointers*,
TwoPointers)’:
pr40698.c:55: warning: dereferencing type-punned pointer will break
strict-aliasing rules
pr40698.c:55: warning: dereferencing type-punned pointer will break
strict-aliasing rules
pr40698.c:56: warning: dereferencing type-punned pointer will break
strict-aliasing rules
pr40698.c: In function ‘int main()’:
pr40698.c:80: warning: dereferencing type-punned pointer will break
strict-aliasing rules
pr40698.c:81: warning: dereferencing type-punned pointer will break
strict-aliasing rules
pr40698.c:63: warning: unused variable ‘i’
pr40698.c:64: warning: unused variable ‘j’


If you have more questions, please do ask.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org


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

Reply via email to