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=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a24:455c:: with SMTP id y89-v6mr2886666ita.0.1527769082576; Thu, 31 May 2018 05:18:02 -0700 (PDT) X-Received: by 2002:a9d:51d1:: with SMTP id d17-v6mr277913oth.12.1527769082201; Thu, 31 May 2018 05:18:02 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.uzoreto.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!u74-v6no795054itb.0!news-out.google.com!f20-v6ni560itd.0!nntp.google.com!u74-v6no795046itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 31 May 2018 05:18:01 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=136.163.203.5; posting-account=HFCrOQoAAABZD_f-UUbYHm3lJDIrh-UX NNTP-Posting-Host: 136.163.203.5 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Header-only Ada libraries... From: joakimds@kth.se Injection-Date: Thu, 31 May 2018 12:18:02 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:52805 Date: 2018-05-31T05:18:01-07:00 List-Id: Den torsdag 31 maj 2018 kl. 13:14:13 UTC+2 skrev Alejandro R. Mosteo: > A while ago I commented on how I unexpectedly found myself writing more= =20 > and more expression functions... today I realized that this tiny project= =20 > to interact with C subprograms is header-only: >=20 > https://github.com/mosteo/cstrings/tree/master/src >=20 > What it does isn't important, but I couldn't but think of the trend in=20 > the C++ world to go for header-only libraries. >=20 > https://en.wikipedia.org/wiki/Header-only >=20 > Anyway, just a curiosity... and something to worry about? ;) >=20 > Alex. A trick that is GNAT specific that I use in the Ada binding to Wayland (htt= ps://github.com/joakim-strandberg/wayland_ada_binding) on Linux (and which = might work on other platforms too when using GNAT) is using the standard St= ring type where the input argument is char*. In the C code the function wl_= display_connect has the following signature: struct wl_display * wl_display_connect(const char *name); To import it into Ada: function wl_display_connect (Name : in C_String) return Display_Ptr with Convention =3D> C, Import =3D> True, External_Name =3D> "wl_display_connect"; where C_String is defined as: Nul : constant Character :=3D Character'Val (0); type C_String is new String with Dynamic_Predicate =3D> C_String'Length > 0 and then C_String (C_String'Last) =3D Nul; For convience I added the following conversion routines between standard St= ring types and C_String types in the Posix package: function "-" (Text : C_String) return String; -- Removes the last 'Nul' character and returns a normal String. function "+" (Text : String) return C_String; -- Appends a 'Nul' character to a standard String and returns a C_String. Not sure how well known this trick is so just mentioning it :)