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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d71460587da14d5b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-30 14:26:26 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi_feed4!attbi.com!rwcrnsc52.ops.asp.att.net.POSTED!not-for-mail From: Freejack Subject: Re: Importing C structs? Newsgroups: comp.lang.ada Message-ID: References: User-Agent: Pan/0.11.4 (Unix) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Comment-To: "chris" NNTP-Posting-Host: 12.245.85.50 X-Complaints-To: abuse@comcast.net X-Trace: rwcrnsc52.ops.asp.att.net 1059600386 12.245.85.50 (Wed, 30 Jul 2003 21:26:26 GMT) NNTP-Posting-Date: Wed, 30 Jul 2003 21:26:26 GMT Organization: Comcast Online Date: Wed, 30 Jul 2003 21:26:26 GMT Xref: archiver1.google.com comp.lang.ada:41046 Date: 2003-07-30T21:26:26+00:00 List-Id: On Wed, 30 Jul 2003 16:52:49 -0400, chris wrote: > Make an Ada record corresponding to that type. Map it's fields to > things from interfaces.c and other records. Then use > > pragma Convention(C, DBType); > > I think! > > This is from my ongoing work on a libjpeg binding... > > type Jpeg_Error_Mgr is record > Error_Exit : Error_Exit_Handler; Emit_Message : > Emit_Message_Handler; Output_Message : > Output_Message_Handler; Format_Message : > Format_Message_Handler; Reset_Error_Mgr : > Reset_Error_Handler; Msg_Code : C.Int; Msg_Parm > : System.Address; Trace_Level : C.Int; > Num_Warnings : C.Long; > Jpeg_Message_Table : Jpeg_Message_TableT; Last_Jpeg_Message : > C.Int; > Addon_Message_Table : Jpeg_Message_TableT; First_Addon_Message : > C.Int; > Last_Addon_Message : C.Int; > end record; > > pragma Convention (C, Jpeg_Error_Mgr); > HTH, > Chris I've been toying with the idea of creating a generic procedure for these types of situations. I dont know if Ada will let me get away with it though. i.e. with Interfaces.C; with Interfaces.C....blah blah blah; generic type foo is new private(<>); type bar is new private(<>); package dooh_dah is package Some_C renames Interfaces.C.blah; private function cast_to_C(foo : in Ada_Type) return Is_Success; -- etc..etc..etc... end dooh_dah; Now, I realize that the Interfaces library provides a limited set of functions and procedures for performing some of the operations I'm talking about here. But as far as I know everything has to be set up explicitly. I'm hoping theres a way to have the compiler do an automatic cast (or export) to a C function depending the execution context. But that type of programming is a little ways down the road. I dont have a need for this yet, but maybe later. Freejack.