This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Division by zero
- From: Bernd Jendrissek <berndj at prism dot co dot za>
- To: gcc at gcc dot gnu dot org
- Date: Mon, 12 Feb 2007 11:19:49 +0200
- Subject: Re: Division by zero
- References: <45CDC415.3060107@adacore.com>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sat, Feb 10, 2007 at 03:09:41PM +0200, Robert Dewar wrote:
> Ian Lance Taylor wrote:
> > "Jie Zhang" <jzhang918@gmail.com> writes:
> >> But now gcc seems to optimize it away. For the following function:
> >>
> >> $ cat t.c
> >> #include <limits.h>
> >> void foo (int rc)
> >> {
> >> int x = rc / INT_MAX;
> >> x = 4 / x;
> >> }
> >
> > I believe we still keep division by zero in general. In your example
> > it gets optimized away because it is dead code. Nothing uses x.
Right. Sometimes it's tricky to remember that NOT reciting Hamlet's
soliloquy also qualifies as "undefined behaviour"! :)
> And it is certainly reasonable to do this optimization given that
> the result of the division is undefined in C.
There's nothing wrong with foo(INT_MAX). Or variants involving INT_MIN.
- --
A PC without Windows is like ice cream without ketchup.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFF0DEcwyMv24BBd/gRAqkXAJ90Oi+pgZAWwE9nwu7HIA/AbYF32QCfaurK
bqj67tA92Uqcwj+jfvUrQTQ=
=WBmH
-----END PGP SIGNATURE-----