For some data type conversions, such as casting a string to a long and converting a floating-point type to an integer type, the PowerPC and x86 architectures perform differently. When the microprocessor converts a floating-point type to an integer type, it discards the fractional part of the value. The behavior is undefined if the value of the integral part cannot be represented by the integer type.
Listing 2-2 shows an example of the sort of code that is architecture-dependent. You would need to modify this code to make it architecture-independent. On a PowerPC microprocessor, the variable x shown in the listing is equal to 7fffffff or INTMAX. On an x86 microprocessor, the variable x is equal to 80000000 or INTMIN.
Listing 2-2 Architecture-dependent code
int main (int argc, const char * argv[]) |
{ |
double a; |
int x; |
a = 5000000.0 * 6709000.5; // or any really big value |
x = a; |
printf("x = %08x \n",x); |
return 0; |
} |
Last updated: 2007-02-26