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-Thread: 103376,a3446063322b22cb X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!feed.news.tiscali.de!uninett.no!ntnu.no!randhol From: randhol@bacchus.pvv.ntnu.no (Preben Randhol) Newsgroups: comp.lang.ada Subject: Re: Thick vs. Thin bindings Date: Wed, 1 Dec 2004 17:14:20 +0000 (UTC) Organization: Norwegian university of science and technology Message-ID: References: <41a746a0@x-privat.org> NNTP-Posting-Host: bacchus.pvv.ntnu.no X-Trace: orkan.itea.ntnu.no 1101921260 15856 129.241.210.178 (1 Dec 2004 17:14:20 GMT) X-Complaints-To: usenet@itea.ntnu.no NNTP-Posting-Date: Wed, 1 Dec 2004 17:14:20 +0000 (UTC) User-Agent: slrn/0.9.6.2 (FreeBSD) Xref: g2news1.google.com comp.lang.ada:6695 Date: 2004-12-01T17:14:20+00:00 List-Id: In article <41a746a0@x-privat.org>, Jeff Houck wrote: >As I continue to evaluate Ada in the role of a game dev language, I've >run across references to "thick" and "thin" bindings and I'm a bit >confused. >My initial design goals are to keep the number of external dependancies >to a minimum with most of the support code written in Ada. I would like >the code interfaces to be as simple as possible to implement for a >designer. I believe this would necessitate a "thick" binding. Is that >correct? Would anyone like to elaborate on the pros and cons of these >two binding methodologies? Further reading material? Tutorials? Thx! One way of thinking is: Thin binding (if it is a C library) then you use only Integer type for more or less everything. Or you use C char arrays in stead of Ada strings etc... Thick binding you add more layer to the binding so that you can use the powers of Ada when you use your library. I mean you don't need to convert from a Integer type to your type for height/speed/distance for example... Thin binding is faster to make and then you can make it more thick if you like, but this involves API changes... Even thicker binding is if you can do standard operations in one procedure call in stead of 10 function/procedure calls. I think I would have done a one-to-one binding to a C library as long as this makes sense and used Ada types so you do any necessary conversion in the binding. Here is an example for GtkAda: function Get_Resizable (Window : access Gtk_Window_Record) return Boolean is function Internal (Window : System.Address) return Gboolean; pragma Import (C, Internal, "gtk_window_get_resizable"); begin return Internal (Get_Object (Window)) /= 0; end Get_Resizable; The C library returns a type Gboolean (which in fact is basically an int) as you can see, but the binding returns an Ada boolean. This means that the user of the library can use Ada's Boolean types without having to convert the Gboolean/integer to boolean after every call to the function. This is perhaps a very thin thick binding, but it should give you an idea. Another thing to remember is that if the original library uses a function it sometimes is better (ex. when returning more than one value) to use a procedure in Ada due to that you cannot have in out variables in functions. Preben