From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8d5bda3619cce0f8 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!news.motzarella.org!motzarella.org!news.motzarella.org!not-for-mail From: Keith Thompson Newsgroups: comp.lang.ada Subject: Re: C getchar() functionality in Ada Date: Tue, 17 Feb 2009 09:31:40 -0800 Organization: A noiseless patient Spider Message-ID: References: <4999ce31$0$90266$14726298@news.sunsite.dk> <499a64e6$0$90264$14726298@news.sunsite.dk> <87prhhe9wl.fsf@nbi.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.eternal-september.org U2FsdGVkX18bCysxWbiHy6M6oHugGDBNM9oRm5Vw4cqyrwWxIjBFcSBq8o6SvU6NB8P73wvlOoiS9Hxu6AqyCjL3L16WEHOzV7WO2Z5sQerGCKJ795bmceep+p8zyme6Y6+m9krmJhE= X-Complaints-To: Please send complaints to abuse@motzarella.org with full headers NNTP-Posting-Date: Tue, 17 Feb 2009 17:31:43 +0000 (UTC) X-Auth-Sender: U2FsdGVkX19+hO8JyFoLYWZvS7URWfeD Cancel-Lock: sha1:4y/CxLeM//3smZr2N9c5sTqrjSI= sha1:VIuKF5xGyPFRgmCMZTxzXXNtXoI= User-Agent: Gnus/5.101 (Gnus v5.10.10) Emacs/21.3 (gnu/linux) Xref: g2news1.google.com comp.lang.ada:3675 Date: 2009-02-17T09:31:40-08:00 List-Id: Jacob Sparre Andersen 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 Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"