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: g2news2.google.com!news3.google.com!goblin2!goblin.stu.neva.ru!news.net.uni-c.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail Date: Tue, 17 Feb 2009 23:03:20 +0100 From: Thomas Locke User-Agent: Thunderbird 2.0.0.19 (X11/20081209) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: C getchar() functionality in Ada References: <4999ce31$0$90266$14726298@news.sunsite.dk> <%5lml.519385$TT4.153916@attbi_s22> <499a6607$0$90276$14726298@news.sunsite.dk> <499a71f2$0$14834$4f793bc4@news.tdc.fi> <499ab51b$0$30223$9b4e6d93@newsspool1.arcor-online.net> In-Reply-To: <499ab51b$0$30223$9b4e6d93@newsspool1.arcor-online.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <499b3428$0$90271$14726298@news.sunsite.dk> Organization: SunSITE.dk - Supporting Open source NNTP-Posting-Host: 83.91.213.86 X-Trace: news.sunsite.dk DXC=>kfkI79:AM>1@QH[VaTAe9YSB=nbEKnk;ebg1>^?UCA:]KcSoP8OK@8@kCUDmHHZ?5:WTk`c[X5;?B:[6GKGT2_l\0 X-Complaints-To: staff@sunsite.dk Xref: g2news2.google.com comp.lang.ada:4655 Date: 2009-02-17T23:03:20+01:00 List-Id: Georg Bauhaus wrote: > We can write the same program in Ada, of course. :-) > Only, the Ada version is likely written without > resorting to the C's idiomatic > "statement-used-as-expression-in-the-loop-conditional". > > with Interfaces.C; > > procedure C_1 is > > use Interfaces.C; > > function getchar return int; > function putchar(item: int) return int; > > pragma Import(C, getchar); > pragma Import(C, putchar); > > EOF: constant int := -1; -- see > c, not_checked: int; > > begin > loop > c := getchar; > exit when C = EOF; > not_checked := putchar(c); > end loop; > end C_1; Thank you for this very nice example Georg! I've experimented a bit on it, and the result is this: ----- with Ada.Text_IO; use Ada.Text_IO; procedure Ito is function getchar return Integer; pragma Import (C, getchar); EOF : constant Integer := -1; C : Integer; begin loop C := getchar; exit when C = EOF; Put (Character'Val (C)); end loop; end Ito; ----- Basically I've just tried to get rid of the C putchar function, and instead use plain Put. Would the above be considered absolutely horrible, or? /Thomas