comp.lang.ada
 help / color / mirror / Atom feed
* Header-only Ada libraries...
@ 2018-05-31 11:14 Alejandro R. Mosteo
  2018-05-31 12:18 ` joakimds
  2018-05-31 13:35 ` Jeffrey R. Carter
  0 siblings, 2 replies; 12+ messages in thread
From: Alejandro R. Mosteo @ 2018-05-31 11:14 UTC (permalink / raw)


A while ago I commented on how I unexpectedly found myself writing more 
and more expression functions... today I realized that this tiny project 
to interact with C subprograms is header-only:

https://github.com/mosteo/cstrings/tree/master/src

What it does isn't important, but I couldn't but think of the trend in 
the C++ world to go for header-only libraries.

https://en.wikipedia.org/wiki/Header-only

Anyway, just a curiosity... and something to worry about? ;)

Alex.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Header-only Ada libraries...
  2018-05-31 11:14 Header-only Ada libraries Alejandro R. Mosteo
@ 2018-05-31 12:18 ` joakimds
  2018-05-31 12:38   ` Egil H H
                     ` (2 more replies)
  2018-05-31 13:35 ` Jeffrey R. Carter
  1 sibling, 3 replies; 12+ messages in thread
From: joakimds @ 2018-05-31 12:18 UTC (permalink / raw)


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 
> and more expression functions... today I realized that this tiny project 
> to interact with C subprograms is header-only:
> 
> https://github.com/mosteo/cstrings/tree/master/src
> 
> What it does isn't important, but I couldn't but think of the trend in 
> the C++ world to go for header-only libraries.
> 
> https://en.wikipedia.org/wiki/Header-only
> 
> Anyway, just a curiosity... and something to worry about? ;)
> 
> Alex.

A trick that is GNAT specific that I use in the Ada binding to Wayland (https://github.com/joakim-strandberg/wayland_ada_binding) on Linux (and which might work on other platforms too when using GNAT) is using the standard String 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    => C,
           Import        => True,
           External_Name => "wl_display_connect";

where C_String is defined as:

Nul : constant Character := Character'Val (0);
type C_String is new String with
  Dynamic_Predicate => C_String'Length > 0
  and then C_String (C_String'Last) = Nul;

For convience I added the following conversion routines between standard String 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 :)


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Header-only Ada libraries...
  2018-05-31 12:18 ` joakimds
@ 2018-05-31 12:38   ` Egil H H
  2018-05-31 13:58     ` joakimds
  2018-05-31 12:55   ` Luke A. Guest
  2018-05-31 13:34   ` Jeffrey R. Carter
  2 siblings, 1 reply; 12+ messages in thread
From: Egil H H @ 2018-05-31 12:38 UTC (permalink / raw)


On Thursday, May 31, 2018 at 2:18:03 PM UTC+2, joak...@kth.se wrote:
> 
> Not sure how well known this trick is so just mentioning it :)

Pretty well known, as it is an Implementation Advice in the RM, and not just for String, but for all arrays and record types.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Header-only Ada libraries...
  2018-05-31 12:18 ` joakimds
  2018-05-31 12:38   ` Egil H H
@ 2018-05-31 12:55   ` Luke A. Guest
  2018-05-31 13:34   ` Jeffrey R. Carter
  2 siblings, 0 replies; 12+ messages in thread
From: Luke A. Guest @ 2018-05-31 12:55 UTC (permalink / raw)



> type C_String is new String with
>   Dynamic_Predicate => C_String'Length > 0
>   and then C_String (C_String'Last) = Nul;
> 
> For convience I added the following conversion routines between standard
> String 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 :)
> 

Ok, that’s pretty cool. Not seen that before.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Header-only Ada libraries...
  2018-05-31 12:18 ` joakimds
  2018-05-31 12:38   ` Egil H H
  2018-05-31 12:55   ` Luke A. Guest
@ 2018-05-31 13:34   ` Jeffrey R. Carter
  2 siblings, 0 replies; 12+ messages in thread
From: Jeffrey R. Carter @ 2018-05-31 13:34 UTC (permalink / raw)


On 05/31/2018 02:18 PM, joakimds@kth.se wrote:
> 
> A trick that is GNAT specific that I use in the Ada binding to Wayland (https://github.com/joakim-strandberg/wayland_ada_binding) on Linux (and which might work on other platforms too when using GNAT) is using the standard String type where the input argument is char*. In the C code the function wl_display_connect has the following signature:

I don't think it's GNAT specific. This is implementation advice in ARM B.3. But 
I would recommend using the types in Interfaces.C whenever possible when 
interfacing with C. In this case, that would be Interfaces.C.char_array.

When there is no suitable type in Interfaces.C, I recommend only using types 
that have been declared with convention C.

-- 
Jeff Carter
"If a sperm is wasted, God gets quite irate."
Monty Python's the Meaning of Life
56

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Header-only Ada libraries...
  2018-05-31 11:14 Header-only Ada libraries Alejandro R. Mosteo
  2018-05-31 12:18 ` joakimds
@ 2018-05-31 13:35 ` Jeffrey R. Carter
  2018-05-31 21:04   ` Robert A Duff
  2018-06-05 12:31   ` Alejandro R. Mosteo
  1 sibling, 2 replies; 12+ messages in thread
From: Jeffrey R. Carter @ 2018-05-31 13:35 UTC (permalink / raw)


On 05/31/2018 01:14 PM, Alejandro R. Mosteo wrote:
> A while ago I commented on how I unexpectedly found myself writing more and more 
> expression functions... today I realized that this tiny project to interact with 
> C subprograms is header-only:
> 
> https://github.com/mosteo/cstrings/tree/master/src

Not a header in sight. Not surprising, since Ada doesn't have headers.

-- 
Jeff Carter
"If a sperm is wasted, God gets quite irate."
Monty Python's the Meaning of Life
56


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Header-only Ada libraries...
  2018-05-31 12:38   ` Egil H H
@ 2018-05-31 13:58     ` joakimds
  0 siblings, 0 replies; 12+ messages in thread
From: joakimds @ 2018-05-31 13:58 UTC (permalink / raw)


Den torsdag 31 maj 2018 kl. 14:38:48 UTC+2 skrev Egil H H:
> On Thursday, May 31, 2018 at 2:18:03 PM UTC+2, joak...@kth.se wrote:
> > 
> > Not sure how well known this trick is so just mentioning it :)
> 
> Pretty well known, as it is an Implementation Advice in the RM, and not just for String, but for all arrays and record types.

Didn't know that. I saw a presentation once by AdaCore where it was mentioned and I thought it was cool so I remembered it.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Header-only Ada libraries...
  2018-05-31 13:35 ` Jeffrey R. Carter
@ 2018-05-31 21:04   ` Robert A Duff
  2018-05-31 22:53     ` Randy Brukardt
  2018-06-01  9:15     ` Jeffrey R. Carter
  2018-06-05 12:31   ` Alejandro R. Mosteo
  1 sibling, 2 replies; 12+ messages in thread
From: Robert A Duff @ 2018-05-31 21:04 UTC (permalink / raw)


"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:

> Not a header in sight. Not surprising, since Ada doesn't have headers.

That's like saying, "French people don't eat cheese."

Of course, they have something called "fromage", but that's got
nothing to do with the matter.

- Bob


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Header-only Ada libraries...
  2018-05-31 21:04   ` Robert A Duff
@ 2018-05-31 22:53     ` Randy Brukardt
  2018-06-01  9:15     ` Jeffrey R. Carter
  1 sibling, 0 replies; 12+ messages in thread
From: Randy Brukardt @ 2018-05-31 22:53 UTC (permalink / raw)


"Robert A Duff" <bobduff@TheWorld.com> wrote in message 
news:wcc36y7edvg.fsf@TheWorld.com...
> "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:
>
>> Not a header in sight. Not surprising, since Ada doesn't have headers.
>
> That's like saying, "French people don't eat cheese."
>
> Of course, they have something called "fromage", but that's got
> nothing to do with the matter.

I tend to agree with Jeff on this one: Ada has packages, which are a named, 
checked, compilation unit. C headers are just untamed (and unnamed, other 
than the source name) conglomerations of code that could literally contain 
anything - any checking or restrictions comes from the implementation. 
They're rather different things, even if often used for the same purpose.

                                                        Randy.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Header-only Ada libraries...
  2018-05-31 21:04   ` Robert A Duff
  2018-05-31 22:53     ` Randy Brukardt
@ 2018-06-01  9:15     ` Jeffrey R. Carter
  2018-06-01 10:00       ` Dmitry A. Kazakov
  1 sibling, 1 reply; 12+ messages in thread
From: Jeffrey R. Carter @ 2018-06-01  9:15 UTC (permalink / raw)


On 05/31/2018 11:04 PM, Robert A Duff wrote:
> "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:
> 
>> Not a header in sight. Not surprising, since Ada doesn't have headers.
> 
> That's like saying, "French people don't eat cheese."

No, the OP's use of "header" is like using the word "cheese" to mean yogurt. 
There are similarities, but they're not the same thing.

The differences between package specifications and C header files are far more 
significant than any similarities. Some of the worst Ada I've seen treated pkg 
specs the way most C people treat header files: as inconveniences they have to 
create to keep the compiler happy. Thinking about any part of Ada in C terms is 
a recipe for disaster.

-- 
Jeff Carter
"I didn't squawk about the steak, dear. I
merely said I didn't see that old horse
that used to be tethered outside here."
Never Give a Sucker an Even Break
103


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Header-only Ada libraries...
  2018-06-01  9:15     ` Jeffrey R. Carter
@ 2018-06-01 10:00       ` Dmitry A. Kazakov
  0 siblings, 0 replies; 12+ messages in thread
From: Dmitry A. Kazakov @ 2018-06-01 10:00 UTC (permalink / raw)


On 2018-06-01 11:15 AM, Jeffrey R. Carter wrote:
> On 05/31/2018 11:04 PM, Robert A Duff wrote:
>> "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:
>>
>>> Not a header in sight. Not surprising, since Ada doesn't have headers.
>>
>> That's like saying, "French people don't eat cheese."
> 
> No, the OP's use of "header" is like using the word "cheese" to mean 
> yogurt. There are similarities, but they're not the same thing.
> 
> The differences between package specifications and C header files are 
> far more significant than any similarities. Some of the worst Ada I've 
> seen treated pkg specs the way most C people treat header files: as 
> inconveniences they have to create to keep the compiler happy. Thinking 
> about any part of Ada in C terms is a recipe for disaster.

That reminds me a C code review I once made. It had all code placed in 
header files! (:-))

Considering recent Ada additions to have statements expressions to be 
placed in package specifications ... not yogurt, but Camembert already.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Header-only Ada libraries...
  2018-05-31 13:35 ` Jeffrey R. Carter
  2018-05-31 21:04   ` Robert A Duff
@ 2018-06-05 12:31   ` Alejandro R. Mosteo
  1 sibling, 0 replies; 12+ messages in thread
From: Alejandro R. Mosteo @ 2018-06-05 12:31 UTC (permalink / raw)


On 31/05/2018 15:35, Jeffrey R. Carter wrote:
> On 05/31/2018 01:14 PM, Alejandro R. Mosteo wrote:
>> A while ago I commented on how I unexpectedly found myself writing more 
>> and more expression functions... today I realized that this tiny 
>> project to interact with C subprograms is header-only:
>>
>> https://github.com/mosteo/cstrings/tree/master/src
> 
> Not a header in sight. Not surprising, since Ada doesn't have headers.

Being aware of the difference, it's part of the point that you can do now 
things in Ada specification files that weren't possible previously... and 
that already make some people wary.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-06-05 12:31 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-31 11:14 Header-only Ada libraries Alejandro R. Mosteo
2018-05-31 12:18 ` joakimds
2018-05-31 12:38   ` Egil H H
2018-05-31 13:58     ` joakimds
2018-05-31 12:55   ` Luke A. Guest
2018-05-31 13:34   ` Jeffrey R. Carter
2018-05-31 13:35 ` Jeffrey R. Carter
2018-05-31 21:04   ` Robert A Duff
2018-05-31 22:53     ` Randy Brukardt
2018-06-01  9:15     ` Jeffrey R. Carter
2018-06-01 10:00       ` Dmitry A. Kazakov
2018-06-05 12:31   ` Alejandro R. Mosteo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox