Bartc wrote, On 07/12/08 13:19:
> "Ben Bacarisse" <> wrote in message
> news:...
>> "Bartc" <> writes:
>
>>> (Possibly related: if I execute printf("Hello World\n") under Windows,
>>> and redirect the output to a file, as in hello >output, I get CR CR LF
>>> at the end. I've forgotten the reason for this; anyone known why?)
>>
>> Name and shame the compiler and (more likely "or") the library. It
>> helps to know what to avoid. I've not seen that behaviour and I would
>> want to avoid it as far as possible.
>
> I've just remembered the reason: I was calling C's printf() from a language
> that expanded "\n" to CR,LF actually in the string literal.
That is a bad design choice for the language. After all, it means it
does not follow the conventions of the system it is running on unless
that happens to be DOS/Windows (well, anything using that convention,
but not any of the many other systems).
> Because printf writes to stdout and stdout is in text mode, the LF results
> in an extra expansion.
Another argument for why the design of that language was bad.
> But the CR,CR,LF is only seen when directed to a
> file.
It is probably "seen" otherwise, at least by the OS, just not so visible
to the average user.
> So not a C problem other than stdout being awkward to set to binary mode.
I would say it was a problem with the design of the other language. Had
the other language either followed the same convention that C does (as
many languages do) or implemented its own library (as others do) then it
would not be a problem. In any case, I don't think stdout was really
provided for binary output, it was (I think) provided to provide the
main textual output to the user of the program (via whatever mechanism
such output might arrive, be it email from a cron job, output on a
telytype or whatever).
--
Flash Gordon
If spamming me sent it to
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at
http://clc-wiki.net/