Spokes.wiki Search About
Tech Article T1 volatile source ↗ source url
Created
Updated
Also known as
GCC implementation-defined behavior — integers
See also
wg14-n2412 · p1236-signed-integers-twos-complement · branchless-abs

GCC — what it does where C leaves integers to the implementation

The GCC manual's section on implementation-defined integer behaviour is where GCC states its choice for each case the C standard leaves open. Read via research pass 2026-09-28 for the case wg14-n2412 left open. The page names no GCC release number, so this summary is of the online manual as read that day.

What it documents

  • Right shift: "Signed '>>' acts on negative numbers by sign extension." So x >> 31 on a negative 32-bit int gives all ones under GCC. This is the behaviour branchless-abs relies on.
  • Left shift: "GCC does not use the latitude given in C99 and later to treat certain aspects of signed '<<' as undefined." GCC calls this a language extension. -fsanitize=shift (and -fsanitize=undefined) still reports such shifts, and they are still diagnosed where a constant expression is required.
  • Representation: "GCC supports only two's complement integer types, and all bit patterns are ordinary values." The page notes that C23 now requires this.

What it means for the spoke

For GCC, the shift caveat in branchless-abs is closed by the compiler's own promise, not by the C standard. Code that depends on it is portable to GCC by documentation. It is still not portable C, and the sanitizer will still flag a negative left shift. Clang and MSVC are not covered by this page.

Tier

T1. The compiler vendor's own documentation of its own implementation-defined choices.

wg14-n2412 · p1236-signed-integers-twos-complement · branchless-abs