This is the mail archive of the gcc-help@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]

Strange cast problem


I've made two cross compile toolchains for xscale big endian platform
using "crosstool", and both of them have the same problem.
The first one is gcc-3.3.6 with glibc-2.2.5, and the second one is
gcc-3.4.5 with glibc-2.3.6.
Both are made under cygwin.

While using these two compiler, I have problem in casting int to double.
But there's no problem while using the manufacturor provided compiler.
The following is the source code to show the problem.

#include <stdio.h>
#include <string.h>

int main()
{
int i;
double db_test, db_test1;
int int_test;
char buf[8];

int_test = 100;
db_test = 100;
db_test1 = (double)int_test;

memcpy(buf, &db_test, sizeof(double));
for(i=0; i<sizeof(double); i++)
printf("%02x ",buf[i]);

printf("\n----\n");

memcpy(buf, &db_test1, sizeof(double));
for(i=0; i<sizeof(double); i++)
printf("%02x ",buf[i]);
printf("\n");

if( db_test == db_test1 )
printf("Your compiler is ok!\n");
else
printf("What's the matter with your compiler?\n");

return(0);
}

If the compiler is ok, this program should print out:
-----------------output begin-------------------
40 59 00 00 00 00 00 00
----
40 59 00 00 00 00 00 00
Your compiler is ok!
-----------------output end---------------------

But when using these two compilers, this program prints out:
-----------------output begin-------------------
40 59 00 00 00 00 00 00
----
00 00 00 00 40 59 00 00
What's the matter with your compiler?
-----------------output end---------------------


Does anyone can help me to solve this problem?

Thanks in advance.




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