"Dmitry A. Kazakov" <
mai...@dmitry-kazakov.de> writes:
> On Wed, 22 Oct 2014 07:36:32 -0700 (PDT), Maciej Sobczak wrote:
>>> '\n' is not
ASCII.CR, it is ASCII.LF, by the way. And on some
>>> nonstandard platforms, the C compiler translates '\n' into a sequence of
>>> two characters,
ASCII.CR & ASCII.LF.
>>
>> What are those nonstandard platforms where the C compiler translates a
>> single character '\n' into a sequence of two characters?
>
> Maybe I/O library was meant? E.g. when opening file in text mode with fopen
> LF will be translated into CR-LF on Windows, or into the physical record
> end on VMS.
Yes. Specifically, that mapping occurs when writing to an output stream
in text mode. The reverse translation happens when reading from an
input stream in text mode.
>> In particular, what happens in the following statement:
>>
>> const char c = '\n';
That sets c to the value of '\n', which is a single byte. It typically
has the value 10, which is the ASCII code of the LF character (but C
doesn't specify ASCII, so it could be something else).
> Considering some crazy platform where char is 2-bytes long, one could say
> that C compiler would translate '\n' and all other characters into two
> "proper" characters.
In C, the type char is exactly one byte. That's the definition of the
word "byte" in C. The constant CHAR_BIT specifies the number of bits in
a byte; it's required to be at least 8 (and is usually exactly 8).
--
Keith Thompson (The_Other_Keith)
ks...@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"