comp.lang.ada
 help / color / mirror / Atom feed
From: fjh@cs.mu.oz.au (Fergus Henderson)
Subject: Re: Compiling, binding, and linking an Ada prog. interfaced with C
Date: 1998/08/02
Date: 1998-08-02T00:00:00+00:00	[thread overview]
Message-ID: <6q28po$42j$1@mulga.cs.mu.OZ.AU> (raw)
In-Reply-To: dewar.901945701@merv

dewar@merv.cs.nyu.edu (Robert Dewar) writes:

><< > This is one respect in which Ada's otherwise excellent C interface
> > features are not quite as good as those of Mercury or ISE Eiffel,
> > which both allow you to import C macros without having to write a
> > separate C file containing glue code.
>>>
>
>Obviously "importing" C macros in full generality would mean inporting
>the full syntax and semantics of C into the parent language, not something
>that is remotely feasible at the language definition level if you ask me.

On the contrary, it is quite feasible.

Those syntax and semantics can be imported "by reference",
so there's no significant increase in the complexity of
the language or the length of the language standard.
It can be implemented without requiring the Ada compiler to
understand or even parse C syntax.

>Sure a given implementation may be able to rig something up (e.g. if it
>translates into C anyway).

As it happens, both ISE Eiffel and Mercury translate to C.  That's
probably what prompted us to invent the feature in the first place.
But the feature can be implemented quite easily even in an implementation
that does not normally translate to C.

For example, something that we plan for a future release of Mercury is an
interface to C++ macros.  Our compiler does not compile to C++ and nor
do we plan to make it do so.  Rather, we'll just get it to spit out
a few C++ code fragments for the `pragma import("C++ macro", ...)'
declarations, if any, and pass them to a C++ compiler,
while for the remainder of the Mercury module being compiled we will
generate C code as usual.

Yes, this implementation technique for interfacing with C (or C++) macros
will only work if you have a C (resp. C++) compiler around.  That is
not a drawback, since if you need to interface with C (resp. C++)
macros you're going to need that anyway, regardless of whether your
Ada (or Eiffel, or Mercury) compiler generates the interfacing stubs
automatically or whether you have to write them by hand.
And generally when doing inter-language interfacing you do have
compiler for both languages available anyhow.

--
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3        |     -- the last words of T. S. Garp.




  reply	other threads:[~1998-08-02  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-07-27  0:00 Re:Compiling, binding, and linking an Ada prog. interfaced with C You4818
1998-07-28  0:00 ` Compiling, " Dr Richard A. O'Keefe
1998-07-29  0:00   ` Fergus Henderson
1998-07-30  0:00     ` Robert I. Eachus
1998-08-01  0:00       ` Robert Dewar
1998-08-02  0:00         ` Fergus Henderson [this message]
1998-08-04  0:00           ` Robert Dewar
1998-08-04  0:00             ` Fergus Henderson
1998-08-03  0:00         ` David Coote
1998-08-03  0:00           ` tedennison
1998-08-02  0:00       ` Fergus Henderson
     [not found] ` <6pi57h$k1h$1@nnrp1.dejanews.com>
1998-07-28  0:00   ` Ronald Ali
replies disabled

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