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]

Re: Casting Bug in GCC 2.95.2


What do you mean by not working?

On ia32 and most other platforms int and long are both 32-bit long.

Thanks,
Andrew Pinski


On Thursday, June 27, 2002, at 05:58 , dtrel wrote:


Casting from char* to: int* or long* generate the same coding.
The int* isn't working in ver 2.95.

Is there a workaround for this or does ver 3.1 solve the problem?

TIA  D'Trel

*------------------------------------------------------------------------*
#include <iostream>

int main () {
int x;
char * cptr;
int  * i_ptr;
long * l_ptr;

cptr = new char[256];
// casting char* to: int* and long*
i_ptr =(int *) cptr;  //same results as: l_ptr=(long*)cptr;
l_ptr =(long *) cptr;

// with int *  < ERROR >
for (x = 0; x <256; x++) cptr[x] = 0;
i_ptr[0] = 1;
i_ptr[1] = 2;
i_ptr[2] = 3;
cout<<endl<<"With int  * = ";
for (x = 0; x < 16; x++) cout<< (int) cptr[x] <<"  ";


// with long * < OK >
for (x = 0; x <256; x++) cptr[x] = 0;
l_ptr[0] = 1;
l_ptr[1] = 2;
l_ptr[2] = 3;
cout<<endl<<"With long * = ";
for (x = 0; x < 16; x++) cout<< (int) cptr[x] <<"  ";

return 0;
}

*------------------------------------------------------------------------*








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