This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/16694] New: bad code generated for pointer arithmetic
- From: "sebor at roguewave dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Jul 2004 17:58:51 -0000
- Subject: [Bug c++/16694] New: bad code generated for pointer arithmetic
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The program below produces unexpected output when compiled with gcc
3.4.0 on Solaris 7: both lines of the output should be the same.
$ cat t.cpp && g++ --version && g++ t.cpp -static && ./a.out
struct X
{
int i;
int j;
int k;
};
extern "C" int printf (const char*, ...);
void foo (const X *p)
{
printf ("%p: %u\n", p, unsigned (p - (X*)0));
}
void bar (const X *p)
{
printf ("%p: %u\n", p, (unsigned)p / sizeof (X));
}
X *p;
int main ()
{
foo (p = new X);
bar (p);
}
g++ (GCC) 3.4.0
Copyright (C) 2004 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.
5e6f0: 2863343764
5e6f0: 32233
--
Summary: bad code generated for pointer arithmetic
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: sebor at roguewave dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16694