Files
2025-10-25 03:02:53 +03:00

64 lines
2.2 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[expr.shift]
# 7 Expressions [[expr]](./#expr)
## 7.6 Compound expressions [[expr.compound]](expr.compound#expr.shift)
### 7.6.7 Shift operators [expr.shift]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L7230)
The shift operators << and >> group left-to-right[.](#1.sentence-1)
[shift-expression:](#nt:shift-expression "7.6.7Shift operators[expr.shift]")
[*additive-expression*](expr.add#nt:additive-expression "7.6.6Additive operators[expr.add]")
[*shift-expression*](#nt:shift-expression "7.6.7Shift operators[expr.shift]") << [*additive-expression*](expr.add#nt:additive-expression "7.6.6Additive operators[expr.add]")
[*shift-expression*](#nt:shift-expression "7.6.7Shift operators[expr.shift]") >> [*additive-expression*](expr.add#nt:additive-expression "7.6.6Additive operators[expr.add]")
The operands shall be prvalues of integral or unscoped enumeration type and integral
promotions are performed[.](#1.sentence-2)
The type of the result is that of the promoted
left operand[.](#1.sentence-3)
The behavior is undefined if the right operand is negative, or greater
than or equal to the width of the promoted left operand[.](#1.sentence-4)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L7258)
The value of E1 << E2 is the unique value congruent toE1×2E2 modulo 2N,
where N is the width of the type of the result[.](#2.sentence-1)
[*Note [1](#note-1)*:
E1 is left-shifted E2 bit positions;
vacated bits are zero-filled[.](#2.sentence-2)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L7267)
The value of E1 >> E2 is E1/2E2,
rounded towards negative infinity[.](#3.sentence-1)
[*Note [2](#note-2)*:
E1 is right-shifted E2 bit positions[.](#3.sentence-2)
Right-shift on signed integral types is an arithmetic right shift,
which performs sign-extension[.](#3.sentence-3)
— *end note*]
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L7276)
The expression E1 is sequenced before the expression E2[.](#4.sentence-1)