From: Angel Tsankov on
Hello!

Does the C language provide a portable way to detect an overflow when adding
two objects of type size_t?

Regards,
Angel Tsankov


From: Alf P. Steinbach on
* Angel Tsankov:
>
> Does the C language provide a portable way to detect an overflow when adding
> two objects of type size_t?

size_t is unsigned and obeys arithmetic modulo 2^n, where n is the
number of value representation bits. Therefore all you have to do is
check whether the sum is less than one of the operands. Either one
will do.

Cheers, & hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?