Article View: comp.std.c
Article #4572Re: Undefined result vs. int's holding undefined values.
From: Chris Torek
Date: Fri, 05 Jan 1996 23:25
Date: Fri, 05 Jan 1996 23:25
45 lines
1995 bytes
1995 bytes
In article <4ck70b$rd7@news.informix.com> Daniel Wood <dwood> wrote:
>THE TEST CASE, on SCO:
(I think this means that INT_MIN is (-2147483647 - 1) and INT_MAX is
2147483647.)
>main() { f(-2147483647, 1879048192); }
>
>f(int x, int y) {
> int r;
>
> if ((r=(x-y)) > 0)
> printf("1: r greater than 0\n");
>
> if (r > 0)
> printf("2: r greater than 0\n");
>}
>
>On SCO only the second print occurs.
I believe this is conformant.
Section 3.3, p. 39, ll. 15--18 (original ANSI numbering):
If an /exception/ occurs during the evaluation of an expression
(that is, if the result is not mathematically defined or not in
the range of representable values for its type), the behavior is
undefined.
When undefined behavior occurs anywhere in any otherwise-conforming
program, the behavior of the entire system becomes undefined. A system
that sometimes prints one, sometimes the other, sometimes neither,
sometimes both, and sometimes prints insults, remains compliant.
>Saying a result is undefined "IS NOT EQUAL TO" saying that a C int variable
>can actually hold an undefined value. If you think the test case is running
>acceptably, as described above, then tell me the section of the standard that
>states or implies that an int variable can hold an undefined value.
See above. Whether something can `hold an undefined value' is
irrelevant; undefined *behavior* occurs on overflow, and that is
all that matters to the Standard.
--
In-Real-Life: Chris Torek, Berkeley Software Design Inc
El Cerrito, CA Domain: torek@bsdi.com +1 510 234 3167
Technical Details
Message-ID:
<4ckc23$2ov@elf.bsdi.com>Path:
arc1-ca.pugleaf.net!cs.umd.edu!not-for-mailReferences:
<4ck70b$rd7@news.informix.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!cs.umd.edu!not-for-mail From: torek@elf.bsdi.com (Chris Torek) Newsgroups: comp.std.c Subject: Re: Undefined result vs. int's holding undefined values. Date: 5 Jan 1996 15:25:55 -0800 Organization: Berkeley Software Design, Inc. Message-ID: <4ckc23$2ov@elf.bsdi.com> References: <4ck70b$rd7@news.informix.com> Reply-To: torek@bsdi.com NNTP-Posting-Host: elf.bsdi.com