comp.lang.ada
 help / color / mirror / Atom feed
From: neff@Shasta.STANFORD.EDU (Randy Neff)
Subject: Compiling Ada into C
Date: 5 Feb 88 22:24:27 GMT	[thread overview]
Message-ID: <2460@Shasta.STANFORD.EDU> (raw)

Why do people want to compile Ada into C?   Because it would appear to a
naive person that this would be a lot less work than compiling into 
assembly language or binary relocatable format.  When, in fact, the C language
features (deficiencies) actually get in the way.

So here is a short list of the some of the problems that appear when compiling
to C, even assuming that you have a fully semanticized abstract syntax tree 
available.

1.  You have to design, write, and validate a runtime tasking
system.   This requires complete understanding of LRM ch 9, the language
maintance committee notes, the implementers' guide, and the folklore.

2.  C does not support nested routines.  The name space is broken into
'local' and 'global' plus included files.   Ada has a very nested name
space.   Fully qualified names will be too long for most C compilers.
Ada has overloaded names, C doesn't.   What to do and still be able to use
a symbolic debugger?   C names are case sensitive.

3.  C does not support nested routines.  Therefore it does not generate any
code to handle a 'display' in order to access objects on the stack that are
not local and not global.  The generated C code must explicitly manage a
display on the stack in the procedure frame for intermediate addressing.

4.  Exceptions and exception handlers are defined in Ada.  The generated
C code must explicitly manage the visiblity of exception handlers on the stack.
It would be nice if the default exception handler could report the 
call stack with line numbers from the point of the exception being raised.
In any case, the debugger should know about exceptions and be able to
catch any at the point of raise, even when there are explicit handlers.

5.  C arrays are not Ada arrays: no bounds information is stored.  Generated
code must explicitly index and check bounds on all array actions.   Also
for strings.   C strings are terminated by ASCII.NUL.  No C library routines 
that use string parameters can be used directly.

6.  All of the LRM required checking must be explicitly generated:  bounds
for ranges and arrays;  null pointer dereferencing;  using fields in a
discriminent (variant) record;  checking that a package has been initialized;
checking assignment sizes;  etc.   C is an unchecked (unsafe) language.

7.  The semantics of parameter passing are different:  C is call by value
(requiring explicit passing of addresses to pointers for out parameters);
Ada is copy in and copy out for scalar parameters, and either copy in and out
or reference for arrays, records, or task types.

8.  Do even the simple arithmetic and boolean operators have the same meaning?
Maybe, maybe not.  Ada permits the redefinition of operators for the standard
types.   With representation and length clauses and pragma PACKED, it is 
possible to generate Ada types that have no corresponding C types.

9.  A lot of the power of C comes from the library of routines rather than
the language.   Most of the routines don't match Ada semantics and are
unusable.

             reply	other threads:[~1988-02-05 22:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1988-02-05 22:24 Randy Neff [this message]
1988-02-13  2:03 ` Compiling Ada into C Barnacle Wes
1988-02-18 22:57   ` Dave Mack
replies disabled

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