Article View: comp.std.c
Article #4588Re: Undefined result vs. int's holding undefined values.
From: Robert Corbett
Date: Tue, 09 Jan 1996 06:00
Date: Tue, 09 Jan 1996 06:00
31 lines
2019 bytes
2019 bytes
In article <4cpv1n$apm@der.twinsun.com>, Paul Eggert <eggert@twinsun.com> wrote: >thads@csn.net (Thad Smith) writes: > >> it is possible to rewrite the function so that it doesn't >> invoke undefined behavior > >Yes. But it slows things down measurably for an interpreter to use >such a clumsy method for integer overflow detection. The (x + y < x) >!= (y < 0) method requires a comparison, an exclusive OR of the >comparison result bit with a sign bit, and a conditional branch. >The method you suggested requires a comparison, a conditional branch, a >subtraction, another comparison, and another conditional branch. > >Since this is comp.std.c, I'll mention that the (x + y < x) != (y < 0) method >and Daniel Wood's example both port to any C implementation >claiming conformance to LIA-1 (ISO/IEC 10967-1:1994(E), >`Information technology -- Language independent arithmetic -- Part 1: >Integer floating point arithmetic' <ftp://crl.dec.com/pub/misc/lia-1-dis.ps.Z>) >if INT_MODULO is true (which is the only plausible value for INT_MODULO >for real-world C compilers). I doubt whether Wood's compiler vendor >claims LIA-1 conformance today, but this may become more important in >the future, and perhaps Wood can point his vendor at LIA-1 and say that >it's time to read the handwriting on the wall. It will also be true for any implementation conforming to IEEE Std 1754. I urge all users to insist that their vendors' implementations conform to IEEE Std 1754. Sincerely, Robert Corbett
Technical Details
Message-ID:
<4ct0a6$eom@engnews2.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!lupa!corbettReferences:
<4ck70b$rd7@news.informix.com> <4cmg0s$1mb@der.twinsun.com> <oZA8wQ9ytpjN084yn@csn.net> <4cpv1n$apm@der.twinsun.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!lupa!corbett From: corbett@lupa.eng.sun.com (Robert Corbett) Newsgroups: comp.std.c Subject: Re: Undefined result vs. int's holding undefined values. Date: 9 Jan 1996 06:00:38 GMT Organization: Sun Microsystems Computer Corporation Message-ID: <4ct0a6$eom@engnews2.Eng.Sun.COM> References: <4ck70b$rd7@news.informix.com> <4cmg0s$1mb@der.twinsun.com> <oZA8wQ9ytpjN084yn@csn.net> <4cpv1n$apm@der.twinsun.com> NNTP-Posting-Host: lupa.eng.sun.com