This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/36971] New: Portability issue from gcc 2.96 to gcc 4.1.1 for c++ casting
- From: "shyam_77_2000 at yahoo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Jul 2008 09:08:08 -0000
- Subject: [Bug c++/36971] New: Portability issue from gcc 2.96 to gcc 4.1.1 for c++ casting
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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