On Fri, Aug 03, 2018 at 15:54:24 +0200, Martin Husemann wrote: > On Fri, Aug 03, 2018 at 08:28:55PM +0700, Robert Elz wrote: > > Where is the signed arithmetic that was supposedly a probem? > > Ah, stupid C integer promotion rules. uint16_t is promoted to int > here, not unsigned int or size_t.
Hmm, i don't think that's true. 22.214.171.124 Usual arithmetic conversions ... Otherwise, the integer promotions are performed on both operands. Then the following rules are applied to the promoted operands: If both operands have the same type, then no further conversion is needed. Otherwise, if both operands have signed integer types or both have unsigned integer types, the operand with the type of lesser integer conversion rank is converted to the type of the operand with greater rank. ntohs returns unsigned uint16_t, sizeof returns unsigned size_t, so uint16_t, that has "lesser integer convertion rank" (i.e. it's smaller) should be converted to size_t automagically. -uwe