[Bug c++/16694] New: bad code generated for pointer arithmetic
sebor at roguewave dot com
gcc-bugzilla@gcc.gnu.org
Fri Jul 23 17:58:00 GMT 2004
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
More information about the Gcc-bugs
mailing list