|
From: Angel Tsankov on 14 May 2008 14:34 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 14 May 2008 14:45 * 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?
|
Pages: 1 Prev: Need a way for forgetful developers Next: How to create a universal .exe ??? |