Kolejna ciekawostka:
Operator przesunięcia w prawo (right shift) w przypadku kiedy lewym operandem jest liczba ujemna ma zachowanie zależne od implementacji (implementation defined).
Większość kompilatorów decyduje się na przesunięcie arytmetyczne (arithmetic shift) ale podobno są takie, które realizują to jako logical shift.

Chyba założe sobie tag z ciekawostkami :) #ciekawostkicpp
#cpp
  • 4
  • Odpowiedz
  • Otrzymuj powiadomienia
    o nowych komentarzach

To tak dla potomnych:
C99 (6.5.7.5):
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 / 2E2. If E1 has a signed type and a negative value, the resulting value is implementation-defined

C++ (aktualny draft, 5.8.3):
The value of E1 >> E2
  • Odpowiedz