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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.157.229 with SMTP id wp5mr24573456pab.35.1462207542585; Mon, 02 May 2016 09:45:42 -0700 (PDT) X-Received: by 10.182.102.73 with SMTP id fm9mr382707obb.9.1462207542533; Mon, 02 May 2016 09:45:42 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!sq19no1571412igc.0!news-out.google.com!uv8ni125igb.0!nntp.google.com!i5no1878625ige.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 2 May 2016 09:45:42 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=158.110.28.161; posting-account=9fwclgkAAAD6oQ5usUYhee1l39geVY99 NNTP-Posting-Host: 158.110.28.161 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <45cb9b19-b470-4649-843a-7b9f88411e6e@googlegroups.com> Subject: A suggestion about interfacing with C From: mockturtle Injection-Date: Mon, 02 May 2016 16:45:42 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:30335 Date: 2016-05-02T09:45:42-07:00 List-Id: Dear all, I need to interface with a C library (libnl, for using Netlink in Linux). = The library provides a "socket" represented by a struct nl_sock, but the us= er (the library user, that is, myself) sees only a pointer to nl_sock, sinc= e the library provides constructors, destructors and everything is needed t= o manipulate the socket. In a sense, the user can consider the pointer just= as an "opaque handler" rather than a pointer. (I must say that my first im= pression of the API is definitively positive).=20 In Ada I would like to provide a slightly thick package that hides the C ty= pe behind a, say, Netlink_Socket type that could be a record holding the po= inter to nl_sock. Note that since libnl uses said pointer as an opaque hand= le, I just need to store the "bitstring" representing its value, in order t= o pass it to the C library. I was wandering about the best way to implement the Ada "view" of the poin= ter to nl_sock. =20 * I could use Interfaces.C.Pointers, but it seems me an overkill since I do= not need to do pointer arithmetic. Moreover, I would need to define a rec= ord equivalento to struct nl_sock (although maybe in my case a null record = could suffice) * I could convert it in C to a char* and then using Interfaces.C.Strings. = (A bit dirty, but not too much...) * I could convert it to an integer... (no, definitively too dirty) * others?=20 What would you suggest? Keep in mind that the software will run on Linux only (Netlink is specific = to Linux, as long as I know) and at 99.99% only on x86 and similar. Thank you in advance for your help Riccardo