This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/37609] New: Pointer arithmetic yields strange result
- From: "john dot spelis at 3dlabs dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 21 Sep 2008 16:00:12 -0000
- Subject: [Bug c/37609] New: Pointer arithmetic yields strange result
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
An expression using ptr arithmetic yields an unusual result
unless a cast is applied;
The problematic expression;
MaxTimings = ((EDIDDetailed *) &pExt->checksum) - pDTD;
works only when cast as;
MaxTimings = (((uintptr_t) &pExt->checksum) - ((uintptr_t)
pDTD))/sizeof(*pDTD);
This occurs on compilers back to 3.0.3 when testing on a x86. It's also present
in a cross compiler built using 4.3.0 source
Works on a Sun/Solaris compiler.
A test program is attached
--
Summary: Pointer arithmetic yields strange result
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: john dot spelis at 3dlabs dot com
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37609