[Bug c++/36964] New: reintrepret_cast corrupts data / does not work as expected

2008-07-29 Thread shyam_77_2000 at yahoo dot com
Hello the following program does not work in gcc 4.1.1 compiler
//tried to analyse it and found vptr is laid out in front and so its shifting 4
bytes and data gets c

#include
#include
using namespace std;
typedef struct c
{
int a;
int b;
char bb[0];
};
class d: public c
{
public:
virtual ~d() {;}
string x;
short y;
}d1;

main()
{
c c1; // c object
c1.a=5;
c1.b=6;

d1.x="abc"; //d object
d1.y=4;

d *ptr = reinterpret_cast(&c1);

cout<a<b<
Compile
g++ test.cpp
OUTPUT:
6
-1074749676

wheras the expected answer is 5 and 6.


where is the vptr laid out in binary layout of object? and why it skips 4 bytes
always.


-- 
   Summary: reintrepret_cast  corrupts data / does not work as
expected
   Product: gcc
   Version: 4.1.1
Status: UNCONFIRMED
  Severity: major
  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=36964



[Bug c++/36971] New: Portability issue from gcc 2.96 to gcc 4.1.1 for c++ casting

2008-07-30 Thread shyam_77_2000 at yahoo dot com
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
#include
#include
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"b = 6;

d *ptr = reinterpret_cast (c1);
cout

[Bug c++/36971] Portability issue from gcc 2.96 to gcc 4.1.1 for c++ casting

2008-08-01 Thread shyam_77_2000 at yahoo dot com


-- 

shyam_77_2000 at yahoo dot com changed:

   What|Removed |Added

 CC||shyam_77_2000 at yahoo dot
   ||com
   Severity|normal  |major


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