Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #66303

Re: Fgets question

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Fgets question
Date 2015-07-24 12:15 -0700
Organization None to speak of
Message-ID <ln6159z7s2.fsf@kst-u.example.com> (permalink)
References (4 earlier) <kfnr3o9qtds.fsf@x-alumni2.alumni.caltech.edu> <lnpp3tjp0u.fsf@kst-u.example.com> <kfntwsylnr6.fsf@x-alumni2.alumni.caltech.edu> <lnfv4ifvzj.fsf@kst-u.example.com> <kfnio99h465.fsf@x-alumni2.alumni.caltech.edu>

Show all headers | View raw


Tim Rentsch <txr@alumni.caltech.edu> writes:
> Keith Thompson <kst-u@mib.org> writes:
[...]
>> To repeat the relevant passage (N1570 7.21.2p2):
>>
>>     A text stream is an ordered sequence of characters composed into
>>     lines, each line consisting of zero or more characters plus a
>>     terminating new-line character.  Whether the last line requires
>>     a terminating new-line character is implementation-defined.
>>
>> For an implementation where the last line "requires" a terminating
>> new-line character, you suggest that the implementation could
>> ignore any characters following the last new-line.  It's equally
>> possible that an implementation could behave as if the terminating
>> new-line were there, so you could write "hello" to a text stream
>> and then read "hello\n" from the same text stream.  I see no clue
>> in the standard that either behavior is preferred over the other
>> -- or over any of a number of other plausible behaviors.
>>
>> There may have been some *intent* to define the behavior, but the
>> standard just doesn't do so.
>
> I believe whether that is so depends on how one interprets
> the text - for some interpretations it does, for other it does
> not.  Do you agree with that, or do you disagree?

Not in this case, no.  I see no hint of any definition of what
the behavior should be if a new-line character is required and is
not present.

It's badly worded because it's the standard's job to impose
requirements on implementations and on programmers; here it's trying
to impose a requirement on a line in a text stream.  The bad wording
makes it difficult to infer the intent.

You suggest an interpretation whereby any characters after the
last new-line are not part of the stream.  I see no possible way
to infer that meaning from the text.  It's certainly one possible
reasonable behavior -- but adding an implicit new-line is equally
reasonable given the way it's worded.

>> I agree that that passage is badly worded, even if the intent is for the
>> behavior to be undefined.
>
> Okay, glad we agree on that.
>
>> Incidentally, I find it plausible that the behavior is intended to be
>> undefined.  I can imagine an system where a text file *must*
>> have a new-line on the last line, and reading a file that violates that
>> could have bad consequences.  I think the committee intended to allow
>> conforming implementations for such systems.
>
> I believe it is possible, and perhaps even likely, that the
> intention was for the behavior to be undefined.  My point is
> that what is intended is not completely clear, and the text
> could be read in several different ways, some of which do
> not define the behavior,

Agreed.

>                          and some of which do define (at
> least partially) the behavior.

Since I see no definition of the behavior, I can't agree with that.

I can accept that the committee might have intended to define the
behavior, but they failed to do so.

[...]

>> The bottom line is that I disagree with your assertion that the
>> standard might define the behavior for text streams.  By my
>> reading, it simply doesn't.
>
> Yes, by your reading.  Isn't it possible that other readings
> might define it?

Not as far as I can see.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"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


Thread

Fgets question Paul N <gw7rib@aol.com> - 2015-07-06 14:06 -0700
  Re: Fgets question Barry Schwarz <schwarzb@dqel.com> - 2015-07-06 15:09 -0700
    Re: Fgets question Keith Thompson <kst-u@mib.org> - 2015-07-06 16:41 -0700
      Re: Fgets question Paul N <gw7rib@aol.com> - 2015-07-07 15:16 -0700
  Re: Fgets question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-06 23:13 +0100
    Re: Fgets question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-07 00:57 +0100
  Re: Fgets question Keith Thompson <kst-u@mib.org> - 2015-07-06 16:29 -0700
    Re: Fgets question Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-11 05:16 -0700
      Re: Fgets question Keith Thompson <kst-u@mib.org> - 2015-07-11 14:04 -0700
        Re: Fgets question Richard Damon <Richard@Damon-Family.org> - 2015-07-11 19:56 -0400
        Re: Fgets question Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-15 09:26 -0700
          Re: Fgets question Keith Thompson <kst-u@mib.org> - 2015-07-15 10:42 -0700
            Re: Fgets question Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-20 10:53 -0700
              Re: Fgets question Keith Thompson <kst-u@mib.org> - 2015-07-20 12:51 -0700
                Re: Fgets question Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-24 10:10 -0700
                Re: Fgets question Keith Thompson <kst-u@mib.org> - 2015-07-24 12:15 -0700
                Re: Fgets question Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-26 16:41 -0700
                Re: Fgets question Keith Thompson <kst-u@mib.org> - 2015-07-27 11:42 -0700
                Re: Fgets question Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-30 15:42 -0700

csiph-web