This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/16694] New: bad code generated for pointer arithmetic


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]