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.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6ec0e822a8924768 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-10-18 07:35:58 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!swiss.ans.net!solaris.cc.vt.edu!news.mathworks.com!news.duke.edu!eff!blanket.mitre.org!linus.mitre.org!linus!mbunix!emery From: emery@goldfinger.mitre.org (David Emery) Newsgroups: comp.lang.ada Subject: Re: C-Ada Import of struct's -- Help Date: 18 Oct 94 09:58:16 Organization: The Mitre Corp., Bedford, MA. Message-ID: References: <9410181020.AA08716@eurocontrol.de> NNTP-Posting-Host: goldfinger.mitre.org In-reply-to: Bob Wells #402's message of Tue, 18 Oct 1994 11:20:30 +0100 Date: 1994-10-18T09:58:16+00:00 List-Id: I'm sorry, but Bob Wells' techniques are not very reliable/portable, and will fail on many Ada compilers. Bob makes the significant mistake of assuming that an Ada access type has any relation to an address. This is not a valid assumption on some Ada compilers. Even when an access type is an address, it doesn't necessarily point to the right thing. By Definition in C, a "char *" representing a string is the address of the first element of the string. There's no guarantee that an Ada access type points to the first element of the string. In fact, there is significant existing practice where the access type points to a 'descriptor', which contains the address of the first element of the string. The same reasoning holds true, even more so, for the other array type. Also, don't forget that a C string must be null-terminated. Ada provides no such guarantee for its strings. In my (long and painful) experience interfacing Ada and C, I've found that the right approach is to bend over backwards and provide C with the exact thing it asks for (e.g. the address of the first element of a string is represented in Ada by STR(STR'FIRST)'ADDRESS). Fortunately, we can use the features of Ada to hide this ugliness within a package body, protecting the innocence of the programmer using the package... dave -- --The preceeding opinions do not necessarily reflect the opinions of --The MITRE Corporation or its sponsors. -- "A good plan violently executed -NOW- is better than a perfect plan -- next week" George Patton -- "Any damn fool can write a plan. It's the execution that gets you -- all screwed up" James Hollingsworth -------------------------------------------------------------------------