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++/36971] New: Portability issue from gcc 2.96 to gcc 4.1.1 for c++ casting


Hello i have code working in gcc 2.96 and porting it to gcc 4.1.1 gives me a
complete different result; please suggest what should i change in my code to
make to portable for gcc 4.1.1 specific

//code that was working in  gcc 2.96
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
typedef struct c
{
int a;
int b;
char bb[0];
};

class d:public c
{
public:
virtual ~d(){;}
std::string xyz;
short yy;
virtual void hello()
{
cout<<"hello"<<endl;
}

};


main()
{
c *c1 = new c; //c object

c1->a = 5;
c1->b = 6;

d *ptr = reinterpret_cast<d*> (c1);
cout<<ptr->a<<endl<<ptr->b<<endl;
}
**************************************
output  gcc 2.96
5
6
**************************************
**************************************
output gcc 4.1.1
6
0
***************************************
**************************************
is it a bug in gcc 2.96 that got fixed in gcc 4.1.1 (any differences in vptr
layout for both gcc versions ?


-- 
           Summary: Portability issue from gcc 2.96 to gcc 4.1.1 for c++
                    casting
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: shyam_77_2000 at yahoo dot com


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


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