[cfe-dev] -ftrapv

Eli Friedman eli.friedman at gmail.com
Thu Apr 2 08:10:26 PDT 2009


On Thu, Apr 2, 2009 at 5:57 AM, David Chisnall <csdavec at swansea.ac.uk> wrote:
> I'm not sure I understand this comment.  Smalltalk uses signed
> integers, so -ftrapv, not -ftrapu, is appropriate, but -ftrapu can be
> useful in a number of cases, for example in the implementation of
> calloc() which needs to multiply two size_t quantities together and
> check for overflow, and in any other situation involving computation
> of array offsets where some additional checks while debugging might be
> helpful.

Checking overflow on a particular multiply two unsigned integers might
be appropriate, but it's not appropriate to change all unsigned
multiplies to check for overflow.  The result is well-defined, so any
check would break valid code.

-Eli




More information about the cfe-dev mailing list