r/C_Programming • • Jun 15 '26

Question Question regarding unsigned integers

What's the difference between an unsigned int and a normal integer?

11 Upvotes

93 comments sorted by

View all comments

Show parent comment

2

u/pjl1967 Jun 17 '26

Yes, that's correct. Referring to the C11 standard §6.2.5¶9:

A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type.

So, according to that, you're right. Unlike some others in this thread, I'll simply say thanks for calling that out.

But ...

In §H.2.2, though informative, says (emphasis, mine):

C’s unsigned integer types are ‘‘modulo’’ in the LIA−1 sense in that overflows or out-of-bounds results silently wrap.

So even the standard says "overflow" in an informative way.

In my response, I never said anything along the lines of "The standard says..." So I too was trying to be informative, not normative.