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-31 12:17:41 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Importing C structs? Date: 31 Jul 2003 20:16:21 +0100 Organization: Pushface Sender: simon@smaug.pushface.org Message-ID: References: NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1059679060 28218 62.49.19.209 (31 Jul 2003 19:17:40 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Thu, 31 Jul 2003 19:17:40 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 Xref: archiver1.google.com comp.lang.ada:41100 Date: 2003-07-31T20:16:21+01:00 List-Id: "Xenos" writes: > 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. I'm pretty sure GNAT will do the Right Thing here (ie pass the address of the record parameter). I suppose there might be problems with very small arrays on architectures where these are passed in registers? but since the Ada and C compilers have the same backend you are quite likely to be lucky. pragma Convention (C, ) means "do what the C compiler expects", after all. The trouble with rep clauses where the C side has none, or hasn't used them, is that you only need to move to a different architecture (PowerPC vs i86) for it all to go out of the window. If you are sending the packets over a network, of course, it's more difficult. > 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. With GNAT there's -gnatR which tells you what the representation actually is.