This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: The utility of standard's semantics for overflow
- From: Robert Dewar <dewar at adacore dot com>
- To: Dave Korn <dave dot korn at artimi dot com>
- Cc: Theodore dot Papadopoulo at sophia dot inria dot fr, 'Michael Veksler' <VEKSLER at il dot ibm dot com>, gcc at gcc dot gnu dot org
- Date: Wed, 29 Jun 2005 09:34:57 -0400
- Subject: Re: The utility of standard's semantics for overflow
- References: <SERRANOBWFXbEJSGdvy0000029b@SERRANO.CAM.ARTIMI.COM>
Dave Korn wrote:
In fact, doesn't this suggest that in _most_ circumstances, *saturation*
would be the best behaviour?
Actually I think a handlable exception, a la Ada, is the best solution.
Whether saturation is appropriate is really problem dependent. If you
are counting the number of primes less than bla, then saturating is not
likely to be helpful. If you are computing some real quantity with
minimal precision, saturation might be helpful
And of course, since it's undefined, a compiler could entirely
legitimately use saturating instructions (on a platform that supports them)
for signed int arithmetic.
yes, of course, this would indeed be legitimate, and could be an option.
Almost anything is reasonable as an option. I think it would be quite
reasonable to have options for trapping (-ftrapv working nicely :-) and
for wrap around. But I would not normally make either of these the default
in C.
cheers,
DaveK