1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Doc: mention platform-dependent behavior of bitshift operators

There have been several recent complaints that << and >> don't behave
the same way on all supported platforms.  There is a risk that <<
overflows the signed integer type, which is undefined behavior, and there
are platform-dependent behaviors from shifting by numbers of bits >= the
bitwidth of the type, and also from shifting by negative values.

Document this to warn unsuspecting users of these facts.

Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAApHDvr0O6ZF8NO=Rq9Q+Sz=FHT=NZ1kkNTXZDcNph-OWuk7TQ@mail.gmail.com
Backpatch-through: 14
This commit is contained in:
David Rowley
2026-10-01 15:15:58 +13:00
parent a36e2f7cd2
commit 45277ca0d1

View File

@@ -26,6 +26,13 @@
are resolved by using the type appearing later in these lists.
</para>
<para>
The behavior of bitwise shifting, both left and right, has
platform-dependent behavior both in cases of left shifting that results in
a signed overflow and in cases of the results of shifting by more bits
than exist in the type or from shifting by a negative value.
</para>
<table id="functions-math-op-table">
<title>Mathematical Operators</title>