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=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2e1cd42feeec2424 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news3.google.com!news1.google.com!proxad.net!freenix!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: =?iso-8859-1?q?Bj=F6rn_Lundin?= Newsgroups: comp.lang.ada Subject: Re: Interfacing to C Date: Tue, 8 Feb 2005 21:50:09 +0100 Organization: Cuivre, Argent, Or Message-ID: References: <1107886078.800063.121210@f14g2000cwb.googlegroups.com> NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: melchior.cuivre.fr.eu.org 1107895879 66238 212.85.156.195 (8 Feb 2005 20:51:19 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Tue, 8 Feb 2005 20:51:19 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: User-Agent: KMail/1.7.2 In-Reply-To: <1107886078.800063.121210@f14g2000cwb.googlegroups.com> Content-Disposition: inline X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:8199 Date: 2005-02-08T21:50:09+01:00 tisdag 08 februari 2005 19:07 skrev Garry: > 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? My guess is that you don't know what you want. Your code slightly rewritte= n=20 perhaps make sense? I took the liberty to separate your marktime procedures in a 'thin' (c-clos= e)=20 and a thick (ada -close) version =2D--------- bnl@della2 slask]$ cat *.ad[bs] *.c /* Start of marktime.c */ #include void marktime(char str[255]) { printf("marktime: str=3D'%s'\n",str); } =2D- Start of hsdbg.ads with Interfaces.C; with Interfaces.C.Strings; package HSDBG is procedure Marktime_Thin(Variable : Interfaces.C.Strings.chars_ptr); procedure Marktime_Thick(Variable : String); private pragma Import(C, Marktime_Thin, "marktime"); end HSDBG; =2D- Start of hsdbg.adb with Ada.Text_IO; use Ada.Text_IO; with Interfaces.C.Strings; use Interfaces.C.Strings; package body HSDBG is procedure Marktime_Thick(Variable : String) is Variable_In_C_Format : Chars_ptr :=3D New_String(Variable); begin Marktime_Thin(Variable_In_C_Format); Free(Variable_In_C_Format); end Marktime_Thick; end HSDBG; =2D- End of hsdbg.adb =2D- 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 :=3D New_String("This is a string in Ada that is writ= ten=20 bythe marktime(C) procedure"); Ada_Format : String :=3D "This is a string in Ada that is written by the=20 marktime(Ada) procedure"; begin Put_Line ("test started"); Marktime_Thin(C_Format); Marktime_Thick(Ada_Format); end Tst; [bnl@della2 slask]$ =20 =2D--------- compile and link and testrun gives: [bnl@della2 slask]$ gcc -c marktime.c [bnl@della2 slask]$ gnatmake tst -largs marktime.o gnatbind -x tst.ali gnatlink tst.ali marktime.o [bnl@della2 slask]$ ./tst test started marktime: str=3D'This is a string in Ada that is written by the marktime(C)= =20 procedure' marktime: str=3D'This is a string in Ada that is written by the marktime(Ad= a)=20 procedure' [bnl@della2 slask]$=20 So you don't need a dummy procedure.=20 /Bj=F6rn