comp.lang.ada
 help / color / mirror / Atom feed
* Interfacing to C: API with macros
@ 2007-06-12 20:17 Maciej Sobczak
  2007-06-12 20:25 ` Lutz Donnerhacke
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Maciej Sobczak @ 2007-06-12 20:17 UTC (permalink / raw)


Yet Another Problem (YAP): consider a C function that is defined
together with some helper macros. Motivating example: select(2) system
call, with its FD_XXX helper macros.

(it is unspecified whether FD_XXX helpers are macros or functions, but
we can assume the worst)

There is no way to pragma Import(C, FD_SET) and the binary layout of
fd_set data structure is not specified, so we cannot fake it with Ada.

Again, the straightforward solution: thin wrapper in C, that itself is
simple enough to be easily imported by Ada code.

Again: is this THE solution?

Looks like in order to write any nontrivial system software the poor
Ada programmer has to start with an awful lots of wrappers - where is
maintainability and productivity when you need them? ;-)

--
Maciej Sobczak
http://www.msobczak.com/




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

* Re: Interfacing to C: API with macros
  2007-06-12 20:17 Interfacing to C: API with macros Maciej Sobczak
@ 2007-06-12 20:25 ` Lutz Donnerhacke
  2007-06-13  0:18 ` tmoran
  2007-06-13 14:06 ` Steve
  2 siblings, 0 replies; 4+ messages in thread
From: Lutz Donnerhacke @ 2007-06-12 20:25 UTC (permalink / raw)


* Maciej Sobczak wrote:
> Yet Another Problem (YAP): consider a C function that is defined
> together with some helper macros. Motivating example: select(2) system
> call, with its FD_XXX helper macros.

Have a look at the semantics of those macros, you will notice, that they are
a application level language in C hiding the expressivness holes of the
language.

Now you have a higher level language and you are expected to use it!

> There is no way to pragma Import(C, FD_SET) and the binary layout of
> fd_set data structure is not specified, so we cannot fake it with Ada.

We can! We know that fdset_t is a bitarray on all known systems. Therefore
  type fdset is Array (0..1023) of Boolean;
  pragma Pack(fdset);
and you are done.

> Looks like in order to write any nontrivial system software the poor
> Ada programmer has to start with an awful lots of wrappers - where is
> maintainability and productivity when you need them? ;-)

If you try to meet your counterpart at the most evil place, your programm
will look as ugly as the counterpart. Use the abstraction of your language!
Programm what they mean, not what they code.



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

* Interfacing to C: API with macros
  2007-06-12 20:17 Interfacing to C: API with macros Maciej Sobczak
  2007-06-12 20:25 ` Lutz Donnerhacke
@ 2007-06-13  0:18 ` tmoran
  2007-06-13 14:06 ` Steve
  2 siblings, 0 replies; 4+ messages in thread
From: tmoran @ 2007-06-13  0:18 UTC (permalink / raw)


> Again, the straightforward solution: thin wrapper in C, that itself is
> simple enough to be easily imported by Ada code.
>
> Again: is this THE solution?
>
> Looks like in order to write any nontrivial system software the poor
> Ada programmer has to start with an awful lots of wrappers - where is
> maintainability and productivity when you need them? ;-)
   If you are interfacing to something that isn't documented, then you
will indeed have to experimentally determine the interface, or make
a wrapper from unknown to known interface spec.
   Usually the interface is documented (though too often erroneously),
though you may have to look carefully to see, for instance, what some
bit-field packing macro is doing.  Once you know, you can write a
direct Ada interface.  Claw, for instance, uses a great number of Windows
API calls, and it uses no wrappers in C (though the whole point of Claw
is to give an Ada-flavor wrapper to the Windows API).  Many APIs
in the Windows world also have typelib descriptions that can be used
to automatically generate an Ada wrapper.



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

* Re: Interfacing to C: API with macros
  2007-06-12 20:17 Interfacing to C: API with macros Maciej Sobczak
  2007-06-12 20:25 ` Lutz Donnerhacke
  2007-06-13  0:18 ` tmoran
@ 2007-06-13 14:06 ` Steve
  2 siblings, 0 replies; 4+ messages in thread
From: Steve @ 2007-06-13 14:06 UTC (permalink / raw)


"Maciej Sobczak" <see.my.homepage@gmail.com> wrote in message 
news:1181679449.352274.217590@g37g2000prf.googlegroups.com...
[snip]
> Looks like in order to write any nontrivial system software the poor
> Ada programmer has to start with an awful lots of wrappers - where is
> maintainability and productivity when you need them? ;-)
>

Fortunately the Ada programmer gains enough efficiency in other areas to 
offset the time generating wrappers.  Some tools (ie: c2ada) are available 
for automatically generating wrappers, but do not in general do 100% of the 
job.

Regards,
Steve
(The Duck)


> --
> Maciej Sobczak
> http://www.msobczak.com/
> 





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

end of thread, other threads:[~2007-06-13 14:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-12 20:17 Interfacing to C: API with macros Maciej Sobczak
2007-06-12 20:25 ` Lutz Donnerhacke
2007-06-13  0:18 ` tmoran
2007-06-13 14:06 ` Steve

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