comp.lang.ada
 help / color / mirror / Atom feed
From: mockturtle <framefritti@gmail.com>
Subject: Re: Ada as glue ? logical approach ?
Date: Sun, 29 Jan 2012 01:46:32 -0800 (PST)
Date: 2012-01-29T01:46:32-08:00	[thread overview]
Message-ID: <33454168.606.1327830392053.JavaMail.geo-discussion-forums@vbuf18> (raw)
In-Reply-To: <9e698480-636a-419f-9b50-400b322de8d4@dp8g2000vbb.googlegroups.com>

On Sunday, January 29, 2012 5:53:21 AM UTC+1, Patrick wrote:
> Hi Everyone
> 
> I have been studying ada for sometime now but I have no experience
> coding with it.

<OT-remark class="old-guy-suggestion"> :-)
I +1 what Simon told you: start coding.  In my (humble) opinion, computer languages and human languages share at least one characteristic: if you really want to learn them, you must use them.  Studying the grammar is useful and it gives you an idea of the language, but if you want to master it you need to use it.
</OT-remark>

> 
>  It doesn't look like there are all the library bindings i want but I
> am wondering if this really matters.
> 
> Someone could write a full binding for a library but could someone
> also not just use the import pragma to "grab onto" the existing C
> library APIs?
> 

Let me see if I understand your question.  Let us consider, for example, the GNAT.Sockets library that refers to the socket C API and consider the procedure to connect a socket.  You are asking if you can do something like
 
    pragma Import(C, BSD_Connect, "connect");

and then calling BSD_Connect directly instead of writing a procedure GNAT.Sockets.Connect_Socket that in turn calls the connect() (imported with a pragma similar to the above one).

If this is your question, the answer is that, yes, you can, but the resulting code would not be very convenient to use.  For example, depending on the parameters of the C function, you need to convert from Ada parameter to C parameter (e.g., Ada String to C char*) and this would be quite unconvenient to do every time you need to call the function.  For me, I prefer to write a tiny procedure that takes normal Ada parameters and hides the conversions problem.  
Note also that sometimes conversion could be a little tricky, so you do not want to spread your code with tricky conversion stuff that could introduce bugs; it is better to have the tricky part only in one place, write it and debug it just once and forget about it.

The only reason that I see for "grabbing" the "naked" C API is when you are in a rush (e.g., you need the final version tomorrow) and you need to call the C API in just few places.  Of course, your mileage can vary.

> This would be a bit like ctypes in Python correct ? Are other list
> members writing their own 'as needed' partial bindings? 

Yes, me too.  As Simon told you, many bindings are just partial, no need to interface with the whole C library.  

> Is this a logical approach? -Patrick


Riccardo



  parent reply	other threads:[~2012-01-29  9:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-29  4:53 Ada as glue ? logical approach ? Patrick
2012-01-29  8:26 ` Simon Wright
2012-01-29  9:46 ` mockturtle [this message]
2012-01-29 13:10 ` Brian Drummond
2012-01-29 13:57   ` Patrick
2012-01-29 16:51     ` mockturtle
2012-01-30  0:26       ` Patrick
2012-02-01  2:19 ` BrianG
2012-02-01  4:07   ` Patrick
2012-02-01  6:05     ` tmoran
replies disabled

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