Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: scanf() |
| Date | 2012-08-12 16:33 -0700 |
| Organization | None to speak of |
| Message-ID | <ln8vdju1lq.fsf@nuthaus.mib.org> (permalink) |
| References | (6 earlier) <7337238e-c54d-496a-a29f-c96799218e81@googlegroups.com> <lnwr15t0i1.fsf@nuthaus.mib.org> <cfaea4d2-9a6b-483b-8439-e5e2106ea065@googlegroups.com> <lnhas7u9np.fsf@nuthaus.mib.org> <e119a1a7-94eb-4bd6-9ec2-ea3c209c7fe9@googlegroups.com> |
Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
> בתאריך יום ראשון, 12 באוגוסט 2012 21:39:54 UTC+1, מאת Keith Thompson:
>> Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
>> > It mean the implementation decides what the result of the operation will
>> > be.
>>
>> No, the implementation needn't decide *anything*.
>>
> Someone writes scanf(). It's possible, though unlikely for someone given
> such a job, that he's never considered that exponents might be out of
> range. If he has considered that possibility, he must decide what to do
> with such input. He might write an error message, quietly return a NaN, or
> return a corrupted result which retain backwards comptability with a previous
> version of the function. There's a case for all of these. But he's got to
> opt for something.
As you acknowledge, the developer needn't even consider the
possibility that exponents might be out of range -- or that there
might be a sufficiently long sequence of digits to produce an
out-of-range value without using an exponent.
Someone implementing scanf() might simply perform a series of
arithmetic operations that will work correctly with in-range
values, and *assume* that it will fail in some clean fashion with
out-of-range values. He might fail to consider what could happen
with all the compilers under which the code might run (run-time
libraries aren't necessarily tied to specific compilers), or how
optimization might affect the results. Adding code to allow for
overflow might significantly slow down cases that *don't* overflow;
he might deliberately choose performance over clean behavior for
undefined cases. Or he might simply take the standard's statement
that the behavior is undefined as a license not to worry about it.
Treating undefined behavior as if it were merely unspecified or
implementation-defined is foolish.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
scanf() Edward Rutherford <edward.p.rutherford79@REMOVETHIS.gmail.com> - 2012-08-06 20:58 +0000
Re: scanf() Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-06 17:29 -0400
Re: scanf() Keith Thompson <kst-u@mib.org> - 2012-08-06 14:40 -0700
Re: scanf() James Kuyper <jameskuyper@verizon.net> - 2012-08-06 17:39 -0400
Re: scanf() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-08-06 22:49 +0100
Re: scanf() Edward Rutherford <edward.p.rutherford79@REMOVETHIS.gmail.com> - 2012-08-07 18:37 +0000
Re: scanf() James Kuyper <jameskuyper@verizon.net> - 2012-08-07 15:01 -0400
Re: scanf() Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-07 15:03 -0400
Re: scanf() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-08-07 20:51 +0100
Re: scanf() John Bode <jfbode1029@gmail.com> - 2012-08-09 14:00 -0700
Re: scanf() Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-08-11 03:08 -0700
Re: scanf() Keith Thompson <kst-u@mib.org> - 2012-08-11 10:40 -0700
Re: scanf() Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-08-11 13:34 -0700
Re: scanf() "BartC" <bc@freeuk.com> - 2012-08-11 23:04 +0100
Re: scanf() James Kuyper <jameskuyper@verizon.net> - 2012-08-11 19:20 -0400
Re: scanf() Keith Thompson <kst-u@mib.org> - 2012-08-11 17:30 -0700
Re: scanf() Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-11 20:41 -0400
Re: scanf() Keith Thompson <kst-u@mib.org> - 2012-08-11 18:13 -0700
Re: scanf() Keith Thompson <kst-u@mib.org> - 2012-08-11 18:16 -0700
Re: scanf() Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-11 21:32 -0400
Re: scanf() Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-08-12 04:07 -0700
Re: scanf() James Kuyper <jameskuyper@verizon.net> - 2012-08-12 08:03 -0400
Re: scanf() Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-08-12 06:41 -0700
Re: scanf() Keith Thompson <kst-u@mib.org> - 2012-08-12 13:39 -0700
Re: scanf() Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-08-12 14:20 -0700
Re: scanf() Keith Thompson <kst-u@mib.org> - 2012-08-12 16:33 -0700
Re: scanf() "Heinrich Wolf" <invalid@invalid.invalid> - 2012-08-13 12:22 +0200
Re: scanf() Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-09-05 00:13 +0300
Re: scanf() Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 14:18 -0700
Re: scanf() Keith Thompson <kst-u@mib.org> - 2012-09-07 15:02 -0700
Re: scanf() Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 17:25 -0700
Re: scanf() Keith Thompson <kst-u@mib.org> - 2012-09-07 18:35 -0700
Re: scanf() Seungbeom Kim <musiphil@bawi.org> - 2012-08-12 21:05 -0700
Re: scanf() Robert Wessel <robertwessel2@yahoo.com> - 2012-08-11 17:37 -0500
csiph-web