Re: Understanding a simple C program
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Mon, 29 Oct 2007 16:29:46 -0700
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"
.
- References:
- Understanding a simple C program
- From: CJ
- Re: Understanding a simple C program
- From: user923005
- Re: Understanding a simple C program
- From: CJ
- Re: Understanding a simple C program
- From: user923005
- Re: Understanding a simple C program
- From: Joachim Schmitz
- Re: Understanding a simple C program
- From: Martien Verbruggen
- Re: Understanding a simple C program
- From: pete
- Re: Understanding a simple C program
- From: Martien Verbruggen
- Re: Understanding a simple C program
- From: pete
- Re: Understanding a simple C program
- From: Martien Verbruggen
- Re: Understanding a simple C program
- From: Richard Bos
- Re: Understanding a simple C program
- From: Martien Verbruggen
- Re: Understanding a simple C program
- From: Keith Thompson
- Re: Understanding a simple C program
- From: Kenneth Brody
- Understanding a simple C program
- Prev by Date: Re: A string collection abstract data type
- Next by Date: Re: C return a++ - is it safe?
- Previous by thread: Re: Understanding a simple C program
- Next by thread: Re: Understanding a simple C program
- Index(es):
Relevant Pages
|