Casting Bug in GCC 2.95.2
dtrel
dtrel@yahoo.com
Thu Jun 27 15:13:00 GMT 2002
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;
}
*------------------------------------------------------------------------*
More information about the Gcc-bugs
mailing list