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.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no 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-31 11:25:02 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!logbridge.uoregon.edu!swen.emba.uvm.edu!att541!att542!ip.att.net!newsfeed3.global.lmco.com!svlnews.lmms.lmco.com!not-for-mail From: "Xenos" Newsgroups: comp.lang.ada Subject: Re: Importing C structs? Date: Thu, 31 Jul 2003 14:17:09 -0400 Organization: Lockheed Martin Corporation Message-ID: References: NNTP-Posting-Host: 158.187.68.119 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Xref: archiver1.google.com comp.lang.ada:41098 Date: 2003-07-31T14:17:09-04:00 List-Id: We do this sort of think all the time. Just create an Ada record that is properly rep. spec'd according to the way your C compiler does its structs. If the parameter is a pointer to a struct use either System.Address or an access type. Unfortunately, there is no portable way to do it. But you usually don't run into trouble unless your structs would have misaligned fields. The compiler avoids this by creating "holes." Some C compilers give you limited control of the packing, but again, its not portable. Bit fields are nasty because the compiler defined which bit is 0. For example, our Ada compiler says that the MSB is 0, where as our C compiler says that the LSB is, and both are for the same Big Endian machine. Regards, Rich "chris" wrote in message news:ddWVa.1313$Kx1.14581@newsfep4-glfd.server.ntli.net... > Freejack wrote: > > I'm finally starting to get an idea(at least I think I am.) on handling > > interfacing to C. > > Really? I don't think I'll ever get the hang of it. > > > Specifically, would I cast DBTYPE as a seperate record type, and then > > provide a seperate function to translate each item into the type expected > > by the C struct? Or can import the DBTYPE struct whole hog into my Ada > > specification? > > 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 >