From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!decwrl!labrea!Shasta!neff From: neff@Shasta.STANFORD.EDU (Randy Neff) Newsgroups: comp.lang.ada Subject: Compiling Ada into C Message-ID: <2460@Shasta.STANFORD.EDU> Date: 5 Feb 88 22:24:27 GMT Reply-To: neff@Shasta.UUCP (Randy Neff) Distribution: na Organization: Stanford University List-Id: 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.