comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst-u@mib.org>
Subject: Re: C getchar() functionality in Ada
Date: Tue, 17 Feb 2009 09:31:40 -0800
Date: 2009-02-17T09:31:40-08:00	[thread overview]
Message-ID: <ln3aedx94z.fsf@nuthaus.mib.org> (raw)
In-Reply-To: 87prhhe9wl.fsf@nbi.dk

Jacob Sparre Andersen <sparre@nbi.dk> writes:
> Thomas Locke wrote:
>> Am I right in assuming that Ada handles itself uniformly across all
>> supported platforms?
>
> Ada.Text_IO can be expected to operate uniformly on text files which
> conform to the conventions of the individual platforms.
>
> (I think the answer to your question is yes.)

And the same is true for C I/O in text mode.

For example, as has already been mentioned, on Windows the end-of-line
marker is a two-character sequence CR LF.  If you're using a C
implementation on a Windows system, and you're reading a text file
using a file opened in text mode, getchar() will consume both
characters and return a single '\n' character.  ('\n' is C's new-line
character; it's typically an ASCII LF, but the C language doesn't
specify that.)

If you open the same file in binary mode, you'll get the raw character
values CR and LF (probably '\r' and '\n', respectively).

Ada uses separate packages (Text_IO and Sequential_IO) for text and
binary input.  C uses a single interface for both, but a file can be
opened either in text mode or in binary mode, determined by the second
argument passed to fopen().  On Unix-like systems, there's no real
difference between text and binary modes, since the end-of-line marker
is a single LF ('\n').  On other systems, there might not even be an
end-of-line marker; a text file might be stored as a sequence of
fixed-length records.  C's I/O system, like Ada's is designed to deal
with such things.

-- 
Keith Thompson (The_Other_Keith) kst@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"



  reply	other threads:[~2009-02-17 17:31 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-16 20:36 C getchar() functionality in Ada Thomas Locke
2009-02-16 21:43 ` Jeffrey R. Carter
2009-02-17  7:23   ` Thomas Locke
2009-02-17  8:16     ` Niklas Holsti
2009-02-17 13:01       ` Georg Bauhaus
2009-02-17 22:03         ` Thomas Locke
2009-03-03  8:57         ` David Thompson
2009-02-17 20:48     ` Jeffrey R. Carter
2009-02-17 21:59       ` Thomas Locke
2009-02-16 23:46 ` Adam Beneschan
2009-02-17  7:19   ` Thomas Locke
2009-02-17  8:37     ` Jacob Sparre Andersen
2009-02-17 17:31       ` Keith Thompson [this message]
2009-02-17 14:57     ` Hibou57 (Yannick Duchêne)
2009-02-17 14:55   ` Hibou57 (Yannick Duchêne)
2009-02-17 10:37 ` m.collado
2009-02-17 22:07   ` Thomas Locke
2009-02-17 16:40 ` Jean-Pierre Rosen
2009-02-17 19:46   ` Thomas Locke
2009-02-17 20:24     ` Hyman Rosen
2009-02-17 23:44       ` Robert A Duff
2009-02-18  5:44         ` anon
2009-02-18  0:39       ` Adam Beneschan
2009-02-18  7:43     ` Jean-Pierre Rosen
2009-02-18 11:42       ` christoph.grein
2009-02-17 20:38   ` Jeffrey R. Carter
2009-02-18  7:46     ` Jean-Pierre Rosen
2009-02-18 10:41       ` christoph.grein
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox