Re: Understanding a simple C program



Kenneth Brody <kenbrody@xxxxxxxxxxx> writes:
Keith Thompson wrote:
Martien Verbruggen <mgjv@xxxxxxxxxxxxxxxxxx> writes:
[...]
I find the above logic a little stretched. The standard specifies that
whether or not a newline is needed is implementation defined. You now
argue that the behaviour is undefined, because the standard does not
describe what the behaviour should be if the implementation requires a
newline, but none is provided. I'd expect that the implementation
documents what happens. That should be its job after this clause.

No, the implementation's only job here is to document whether a
trailing new-line is required or not. The standard doesn't require
anything more than that (though an implementer is free to provide
additional documentation).

Is an implementation allowed to say that the behavior of leaving off
the terminating newline is dependent on things outside the scope of
the C compiler?

For example, suppose you are sending the output to a printer, which
won't print the last line if it's not newline-terminated, even though
the C implementation guarantees that it will send everything up to
the final non-newline character? However, if going to the screen,
the output will be just fine.

One solution in that case would be to say that the trailing new-line
is required (leaving the behavior undefined if it's missing), and then
go ahead and describe what happens in some cases.

Though if the documentation made a more realistic statement that the
trailing new-line is not required if you're writing to a file, but
leaving it off might have unpredictable consequences if you're writing
to a device, I for one wouldn't complain.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: m/(/*[.| ]**/)/ to try and match C-Style multiline comments. No matches found.
    ... The correct way to get the period to match a newline is to add the /s ... Keep reading the documentation. ... read up on character classes and regexp modifiers. ...
    (comp.lang.perl.misc)
  • Re: All programs are undefined, Re: Why this works???
    ... line requires a terminating new-line character. ... well-defined programs of that dialect. ... a trailing newline is not required.'' ... The requirement belongs to the C standard, ...
    (comp.lang.c)
  • Re: write function
    ... Unix has no problem with programs ... with newline, and might not process the last line correctly ... A file that contains characters organized into one or ... ISO C standard), ...
    (comp.unix.programmer)
  • Re: Is this fully portable and/or smart?
    ... file is a newline: ... There's a lot of that kind of stuff in the "standard", ... If your implementation's fseek() function can fail without properly ... It IS a bother, a real bother, but what are you going ...
    (comp.lang.c)
  • Re: question concerning screen control
    ... and perhaps move the cursor to a new location (other than newline) for ... Not within standard C, no. ... Again, there's no way to move the cursor to a particular line, without ... If you're program _really_ needs screen control, ...
    (comp.lang.c)