CTFE output is kind of weired

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jul 8 16:24:58 PDT 2017


On Saturday, July 8, 2017 10:12:29 PM MDT Era Scarecrow via Digitalmars-d-
learn wrote:
> On Saturday, 8 July 2017 at 21:29:10 UTC, Andre Pany wrote:
> > app.d(17):        called from here: test("1234\x0a5678\x0a")
> >
> > I wrote the source code on windows with a source file with \r\n
> > file endings.
> > But the console output has only the character X0a. In addition
> > not the content of tmp is shown but the full content with the
> > slice information [4..10].
> >
> > Is this the intended behavior?
>
>   The escape sequence says it's hex, and 0a translates to 10, and
> 0d is 13; \r\n is usually a 13,10 sequence. So from the looks of
> it the \r is getting stripped out.
>
>   Funny story as i understand it, \r and \n both have very
> specific meanings to old printers in the old days. \r for
> carriage-Return, and \n for New-line. DOS may have used it, but
> \r more-or-less has no use for newlines and printers today.

It used to matter for terminals as well. With respect to those ancient time,
what Windows does with line endings with \r\n is the most correct, but at
this point, it's just a pointless extra character. AFAIK, no other OS
expects \r\n now. Everything that's *nix-based uses only \n. Unfortunately,
web formats such as http still use \r\n though, because they're based on the
original Internet Message Fomat standard (e-mail really), and it's old
enough that it mattered when it was written.

LOL. As I understand it, the old Macs before Mac OS X actually just used \r,
so twent years ago, depending on your OS, you had to deal with \n, \r, or
\r\n for line endings. Yuck.

>   Curious when using writeln, all newlines seem to have \r
> sequences added. So i suppose it's one of those things that i
> never needed to think about really.

Only if you're on Windows. It's what printf and friends do there too (and
IIRC, writeln still uses printf underneath the hood). C and UNIX pretty much
came into being together, and thus both use \n as the line ending - though
given when they were created, I expect that the distinction between \n and
\r\n still mattered on UNIX systems occasionally. I don't know though. Now
though, no *nix system is going to be doing anything with \r for line
endings.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list