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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2e1cd42feeec2424 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!newscon06.news.prodigy.com!prodigy.net!news-FFM2.ecrc.net!newsfeed.vmunix.org!npeer.de.kpn-eurorings.net!border2.nntp.ams.giganews.com!nntp.giganews.com!lightspeed.eweka.nl!feeder.news-service.com!post.news-service.com!news1.surfino.com!not-for-mail Message-ID: <6907976.QsGR0pgVzX@linux1.krischik.com> From: Martin Krischik Subject: Re: Interfacing to C Newsgroups: comp.lang.ada Reply-To: martin@krischik.com Date: Tue, 08 Feb 2005 20:27:06 +0100 References: <1107886078.800063.121210@f14g2000cwb.googlegroups.com> Organization: None User-Agent: KNode/0.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@surfino.com NNTP-Posting-Host: 83.169.148.166 (83.169.148.166) NNTP-Posting-Date: Tue, 08 Feb 2005 21:00:09 +0100 X-Trace: 7f2ea42091a49f60c310316335 Xref: g2news1.google.com comp.lang.ada:8197 Date: 2005-02-08T20:27:06+01:00 List-Id: Garry wrote: > I'm just starting in ADA. Can anyone explain why I have to define a > dummy procedure in my hsdbg package to get my code to work? Because you misunderstood something. Of corse you don't need DUMMY. > Error without dummy procedure: > hsdbg.ads:4:09: package "HSDBG" does not allow a body > hsdbg.ads:4:09: remove incorrect body in file "hsdbg.adb" > gnatmake: "hsdbg.ads" compilation error > error: "hsdbg.adb" must be recompiled ("hsdbg.ads" has been modified) > gnatlink: Failed to open binder output > > Code follows: > /* Start of marktime.c */ > #include > > void marktime(char str[255]) > { > printf("marktime: str='%s'\n",str); > } > /* End of marktime.c */ > > > > -- Start of hsdbg.ads > -- > with Interfaces.C; > with Interfaces.C.Strings; > > package HSDBG is > -- Dummy procedure? > type DUMB is digits 5 range 0.0 .. 1.0E10; > procedure DUMMY (B : DUMB); As Georg pointed out you need: pragma Elaborate_Body; or prehaps: procedure marktime(Variable : String); that would export the Ada version of marktime(Variable : String); > -- End Dummy procedure > procedure marktime(Variable : Interfaces.C.Strings.chars_ptr); > pragma Import(C, marktime, "marktime"); > end HSDBG; > -- End of hsdbg.ads > > > > -- Start of hsdbg.adb > -- > with Ada.Text_IO; use Ada.Text_IO; > with Interfaces.C.Strings; use Interfaces.C.Strings; > -- > -- Define package body > -- > package body HSDBG is > -- > -- > -- dummy procedure? > procedure DUMMY(B : DUMB) is > begin > put("In Dummy"); > end DUMMY; > -- end dummy procedure > > procedure marktime(Variable : String) is > > procedure marktime(Variable : chars_ptr); > pragma Import(C, marktime, "marktime"); Well you don't need to repeat the C declarartion here. You should decide for one and delete the other. Which one is design decision - you have to take that yourself > Variable_In_C_Format : chars_ptr := New_String(Variable); > > > begin > marktime(Variable_In_C_Format); > Free(Variable_In_C_Format); > end marktime; > > > end HSDBG; > -- End of hsdbg.adb > > > > > -- Start of tst.adb > with Ada.Text_IO; use Ada.Text_IO; > with Interfaces.C.Strings; use Interfaces.C.Strings; > with hsdbg; use hsdbg; > > procedure tst is > > C_Format : chars_ptr := New_String("This is a string in ADA that is > written by the marktime C procedure"); > > begin > Put_Line ("test started"); > marktime(C_Format); > > end tst; > -- End of tst.adb Well it look all very confusing here. It looks like you have two test codes and two C binding. One by which the pragma Import shows in the body of hsdbg - one where is shows in the spec of hsdbg. One where you test with a test procedure one where you test with a package body. In both cases both designs are possible and have distict advantages and disadvantges. If you have a tutor then talk with him/her and then make a decision. Martin -- mailto://krischik@users.sourceforge.net Ada programming at: http://ada.krischik.com