= Unsigned integer arithmetic in C
{title2=$x\mathbin{\mathrm{op}}y\pmod{2^w}$}
For a $w$-bit unsigned <integer> type without padding, <C programming language> arithmetic on that type reduces results modulo $2^w$. In particular, subtracting two `uint32_t` timestamps gives their modular difference when that subtraction is evaluated in the 32-bit unsigned type. <Integer> promotions must be checked for narrower types or unusual implementations. Signed <integer overflow> has different rules and must not be treated as the same operation.<C11 committee draft N1570>[Section 6.2.5 paragraph 9 and Section 6.3.1.1]{ref}
Back to article page