[comp.lang.modula2] M2 to C translation

X903@DMAFHT1.BITNET (Marc Wachowitz) (06/10/91)

On Sat, 8 Jun 91 13:37:17 GMT Ian Moor said:
>
>In article <1991Jun7.114900.7574@hubcap.clemson.edu> untch@hubcap.clemson.edu
>        (Roland Untch) writes:
>
>  >> There is a problem generating C for things that have no close equivalents,
>  >> such as nested procedures, something like
>  >>     (. . . example deleted . . .)
>  >> cannot easily be mapped to C. Gardens Point seems to produce incorrect C
>  >> for something like this.
Might be that there's a bug in Gard Point M2, but your "problem" can be
solved trivially:
  Emit a declaration (not definition, see below) - i.e. a prototype for
  standard C - of the outer procedure before writing out the code for
  inner procedures. Package all variables of the outer procedure that
  are used by nested procedures in a variable (of an appropriately
  declared struct type) and pass the address of this variable when
  calling nested procedures. Similar for more nesting levels; it's
  the usual implementation technique for nested procedures, except
  that struct type declarations and field selectors are used instead
  of translator-calculated offsets.
>
>   >    Do you know for a fact that Garden's Point Modula-2 produces
>   >incorrect C?
>
>More details: this was the SPARC version of Garden's Point, which
>we had for evaluation from their UK agent  RTA before easter. The C output
>from a program like the example I quoted caused the C compiler  to complain
>about an illegal redeclaration of one the procedures. The procedure was
>called before definition in the C.
The illegal redeclaration might be a bug in GP-M2 or in the C compiler
(some kinds of redeclarations are allowed, otheres are not; some C
compilers have problems here).
There's nothing wrong with calling a procedure before definition, you
only need a declaration (and even this may be left implicit in some
cases). In C terminology, a "declaration" is the interface definition
(prototype in standard C), whereas the "definition" provides the full
code of the function.

Marc Wachowitz
X903@DMAFHT1.BITNET