C/C++の宿題を片付けます 96代目
■ このスレッドは過去ログ倉庫に格納されています
0643デフォルトの名無しさん
2007/10/03(水) 00:27:59> [10101010]を右に1ビットシフトした場合
> [10010101]になるか[01010101]になるかは処理系依存
(http://proger.blog10.fc2.com/blog-entry-62.html)
> C言語の規格として、算術シフトか論理シフトかは不定
うそ。規格では次のようになっている。ISO/IEC 9899, 1999 より:
> 6.5.7
> The result of E1 >> E2 is E1 right-shifted E2 bit positions.
> If E1 has an unsigned type or if E1 has a signed type and a
> nonnegative value, the value of the result is the integral
> part of the quotient of E1 / 2^E2. If E1 has a signed type
> and a negative value, the resulting value is implementation-defined.
つまり、E1 が unsigned であるか、もしくは signed かつ E1 ≧ 0 のときに
限って右シフトの動作は定められており、それ以外は implementation-defined。
すなわち、論理シフトやら算術シフトの範囲を超えて処理系の自由。
■ このスレッドは過去ログ倉庫に格納されています