Re: Re-Marketing Ada (was "With and use")

From: Lutz Donnerhacke (lutz_at_iks-jena.de)
Date: 11/20/03


Date: Thu, 20 Nov 2003 12:19:02 +0000 (UTC)


* Warren Gay wrote:
> What thinbind would be required to do, is to preprocess the header
> file somewhat differently than the C's preprocessor. Instead of

This destroys most of the original C API in a unusable way.

> Obviously any macros that provide C programmer conveniences, would
> be a challenge (like putchar()). It should be possible
> to infer inline Ada functions from them. I suppose one could apply the
> following C test :
>
> Case 1 : with or without macro arguments
> Does the code fragment represent a complete compilable
> C statement/block? If so, is there an implied return value?
> Define an inline procedure/function with
> or without arguments matching the name.

Hard work. Especially when considering marco expansion down to the plain
syscall (Linux).

> Case 2 : the defined macro components appear to not represent
> a complete statement, nor block of code. Just drop the
> code fragment, because it has already been used
> earlier for macro expansion and is no longer required.

Almost all API constants are marcos. A major part of structures are of compiler
option dependant design. Several structures are different in the man page
and in the implementation. Several macros are used to transform the API
conforming code into the real structure. This can't be ignored.

> #1 is also complicated by "do you expand macro functions?", or
> do you "translate them into Ada inline functions?" I think you would
> need to need to do both (a hints file could control this (see next)).

Thin binding to C is expected as a function/procedure and some
types/constants which can be combined like described in the C API man pages.

So you have to start from the man page and fill in the blanks by designing
the Ada types(!) and calls like expected. Then you have to find out how
these API-types are really defined and used. In a good number of cases you
need quite a different type than described in the man page. C does not know
about variant records and therefore collects a lot of things via unions and
some paragraphs of English text. This has to transformed to an approbriate
Ada type.

> But I think C code can be handled in a well defined way.

I tend to disagree. BTDT.



Relevant Pages

  • Re: For the AdaOS folks
    ... API that says create/delete an integer? ... >>as an Ada binding, I can do another registry query and get the ... libraries can strengthen the typing of the Ada interface. ...
    (comp.lang.ada)
  • Re: [announcement] SYSAPI and SYSSVC for Windows
    ... > using work-arounds in API is the worst thing I can imagine. ... > by a language, it is would be a great ... Ada has its own concept. ... should support the development of BeOS. ...
    (comp.lang.ada)
  • Re: Interfacing to C and types visible to Ada
    ... Imagine a C API that uses the int type to express something that does ... need to expose somehow the type to regular Ada code. ... subtype with a name based on that description. ... I'm not sure I understand this "domainless" business. ...
    (comp.lang.ada)
  • Re: For the AdaOS folks
    ... >> the second step is to provide API to query that names from an application. ... > And how do your identify your GNAT object? ... Ada run-time is another issue. ... It is not like Ada access type, because handle is not a pointer. ...
    (comp.lang.ada)
  • Re: Conditional compilation in Ada?
    ... > some kind of conditional preprocessing, ... Depends on the Ada compiler you use. ... Well in AdaCL long ago I used "GNAT PREPROCESS" - however once I learned the ...
    (comp.lang.ada)