Apple Developer Connection
Advanced Search
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page >

データ型の変換

文字列からlongへのキャストや浮動小数点型から整数型への変換など、いくつかのデータ型の変換では、PowerPCとx86のアーキテクチャでは、異なる方法で実行します。浮動小数点型から整数型へ変換するときに、マイクロプロセッサは値の小数点以下の部分を破棄します。整数部分の値が整数型で表現できない場合の動作は未定義です。

Listing 2-2にアーキテクチャに依存するコードの例を示します。このようなコードはアーキテクチャに依存しないように変更する必要が生じます。PowerPCマイクロプロセッサでは、このリストの変数x7fffffff、つまりINTMAXに相当します。x86マイクロプロセッサでは、変数x80000000、つまりINTMINに相当します。

Listing 2-2  アーキテクチャに依存するコード

int main (int argc, const char * argv[])
{
    double  a;
    int     x;
 
    a = 5000000.0 * 6709000.5;  // または非常に大きな任意の値
    x = a;
    printf("x = %08x \n",x);
    return 0;
} 


< Previous PageNext Page >


Last updated: 2006-03-08




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice