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

13

u/markuspeloquin Jun 15 '26

It will always work as you describe (it's easier for ALUs to just treat all addition/subtraction the same), unless the compiler decides it can be optimized out and uses different instructions.

3

u/HarderFasterHarder Jun 16 '26

It it always works. Until it doesn't.

-2

u/flatfinger Jun 15 '26

The authors of the C Standard uses the term "Undefined Behavior" as a catch-all for, among other things, constructs which were expected to behave predictably on most environments but might behave unpredictably on some. Some people promote the lie that that the term "implementation-defined behavior" is used for that purposes, but that term is limited to things that all implementations are required to define.