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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d1533431e7e9d2eb X-Google-Attributes: gid103376,public From: "Marin D. Condic" Subject: Re: Nontrivial examples of C interface with Ada Date: 2000/05/24 Message-ID: <392CC733.13BDDC84@quadruscorp.com>#1/1 X-Deja-AN: 627003048 Content-Transfer-Encoding: 7bit References: <9ckmisoo8k0dh1gcajhdgqtqjqc3bjmb25@4ax.com> <8ghbqc$ram$1@nnrp1.deja.com> Organization: Quadrus Corporation X-Sender: "Marin D. Condic" (Unverified) X-Server-Date: 25 May 2000 03:28:29 GMT Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-05-25T03:28:29+00:00 List-Id: Ted Dennison wrote: > "Semi-thick" is my term for my own favorite style for bindings. A > "semi-thick" binding is one that abstracts away typical stupid C > artifacts like pointer interfaces, return error codes, and > null-termiated strings. That way the interface "feels" like Ada. But it > doesn't abstract things so much that the C docs for the routine can't be > used for the Ada bindings. > That's about the depth I'd like to see bindings done. Get rid of pointers to everything, use normal Ada strings, enumeration types for return codes, etc. Of course you quite often run into cases where the normal C way to do things is with a function and you have to make it into a procedure in order to have it make proper sense in Ada, so you always have little compromises to make. However, you at least want to attempt to make it close to the original routine, only doing your best to make it more Ada-ish. One problem area I have found is with the use in C of error codes & flags. The usual C method is to declare a long list of constants - sometimes where the specific bits in the constants have particular meanings (intended to be or'ed together). You would prefer enumerated types, but there is often no clear grouping of the return codes. Sometimes a constant is used for one type of thing and sometimes for another (as in sometimes its a return status and sometimes its a parameter). When the codes are used in the manner of flags (or'ed together) you don't always have a good mapping onto an Ada method which doesn't simply degenerate to an ugly C-ism. Maybe it would be useful to develop a set of guidelines as to how to do these sorts of translations? I certainly end up stumped sometimes as to what is the best choice and some consistent guidelines would be handy. MDC -- ====================================================================== Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/ Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m Visit my web site at: http://www.mcondic.com/ "I'd trade it all for just a little more" -- Charles Montgomery Burns, [4F10] ======================================================================