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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,56e5e06428166864 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!e21g2000yqe.googlegroups.com!not-for-mail From: Stoik Newsgroups: comp.lang.ada Subject: Re: problems with interfacing c Date: Mon, 31 Jan 2011 13:46:10 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <8b6a5b24-5ab0-4d38-9be8-86911aba7fcf@k22g2000yqh.googlegroups.com> <13d5wy5ni51xh$.xnhoi3uhm9ql.dlg@40tude.net> <85c958cc-8cd3-46be-b14d-3519ff207d87@b8g2000vbi.googlegroups.com> <1dfd4mpvmtkt2.aqwiaoz63qli$.dlg@40tude.net> NNTP-Posting-Host: 212.191.65.1 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1296510370 22404 127.0.0.1 (31 Jan 2011 21:46:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 31 Jan 2011 21:46:10 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: e21g2000yqe.googlegroups.com; posting-host=212.191.65.1; posting-account=fc1UmgoAAADREbhuD8e4smj7nsEdRFz9 User-Agent: G2/1.0 X-HTTP-Via: 1.1 proxy.math.uni.lodz.pl:8080 (squid/2.7.STABLE4) X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:17789 Date: 2011-01-31T13:46:10-08:00 List-Id: On Jan 28, 10:44=A0am, "Dmitry A. Kazakov" wrote: > On Thu, 27 Jan 2011 16:39:50 -0800 (PST), Stoik wrote: > > The other question is - how to use the C bindings properly in such a > > case? > > You should probably use _read, because fread needs a file descriptor rath= er > than just number. > > =A0 =A0with Interfaces.C; =A0use Interfaces.C; > =A0 =A0with System; =A0 =A0 =A0 =A0use System; > ... > =A0 =A0function Read (FD : int; Buffer : Address; Count : size_t) return = int; > =A0 =A0pragma Import (C, Read, "_read"); > ... > > Now actual reading: > > =A0 =A0Buffer : String (1..100_000); > =A0 =A0Bytes =A0: int; > begin > =A0 =A0Bytes :=3D Read (0, Buffer'Address, Buffer'Length); > > Buffer (1..Integer (Bytes)) is the data read, empty when error. Here I > assume that Character =3D char, so it might be non-portable, but who care= s in > these meaningless contests? > > -- > Regards, > Dmitry A. Kazakovhttp://www.dmitry-kazakov.de Thanks for all the tips. The word "contest" that I used is possibly misleading, and the whole thing is not as stupid as it seems. This is one of the sites where problems are checked automatically by the computer, with no human intervention. The upper limit of the input file is given, but the name is not, so one has to use the standard input. Obviously, reading everything in one chunk is not really needed for hard problems, but may be substantially quicker for easier ones. I am especially grateful for the help with interfacing c (even if it does not make much sense :)) because I would like to learn why things do not work as expected. Regards, Stanislaw Goldstein