public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/modula-2] PR-104065 Modula-2 front end changes to build with CXX.
@ 2022-01-22  0:30 Gaius Mulley
  0 siblings, 0 replies; only message in thread
From: Gaius Mulley @ 2022-01-22  0:30 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:51bc4b8156739a23669bbd475ce7d850ce49d8c8

commit 51bc4b8156739a23669bbd475ce7d850ce49d8c8
Author: Gaius Mulley <gaius.mulley@southwales.ac.uk>
Date:   Sat Jan 22 00:30:08 2022 +0000

    PR-104065 Modula-2 front end changes to build with CXX.
    
    gcc/m2/ChangeLog:
    
            * mc-boot-ch/Gabort.c: (New file).
            * Make-lang.in: Use $(CXX) rather than $(CC).  Use $(CC) rather
            than $(HOSTCC) when compiling mcflex.c.  Invoke $(M2LINK) with
            --langc++ rather than --g++.  (MCC_ARGS) changed to use
            --olang=c++.  (m2/ppg$(exeext)) link with Gabort.o and make
            dependant upon Gabort.o.  (m2/pg$(exeext)) link with Gabort.o
            and make dependant upon Gabort.o.  (m2/pge$(exeext)) link with
            Gabort.o and make dependant upon Gabort.o.  (gm2-check-examples)
            Removed.
            * gm2-ici/m2linemap.c: Introduce extern C for complete source
            file.
            * gm2-libs-ch/README: Reformatted.
            * gm2-libs-ch/RTcodummy.c: Introduce extern C for complete source
            file.
            * gm2-libs-ch/RTintdummy.c: Introduce extern C for complete source
            file.
            * gm2-libs-ch/Selective.c: Introduce extern C for complete source
            file.
            * gm2-libs-ch/SysExceptions.c: Introduce extern C for complete
            source file.
            * gm2-libs-ch/UnixArgs.c: Introduce extern C for complete source
            file.
            * gm2-libs-ch/UnixArgs.c: Introduce extern C for complete source
            file.
            * gm2-libs-ch/cgetopt.c: Introduce extern C for complete source
            file.
            * gm2-libs-ch/choosetemp.c: Introduce extern C for complete source
            file.
            * gm2-libs-ch/dtoa.c: Introduce extern C for complete source
            file.
            * gm2-libs-ch/errno.c: Introduce extern C for complete source
            file.
            * gm2-libs-ch/host.c: Introduce extern C for complete source
            file.
            * gm2-libs-ch/ldtoa.c: Introduce extern C for complete source
            file.
            * gm2-libs-ch/termios.c: Introduce extern C for complete source
            file.
            * gm2-libs-ch/tools.c: Reformatted source.
            * gm2-libs-ch/wrapc.c: Introduce extern C for complete source
            file.
            * gm2-libs-ch/xlibc.c: Introduce extern C for complete source
            file.
            * mc-boot-ch/GBuiltins.c: Introduce extern C for complete source
            file.
            * mc-boot-ch/GRTco.c: Introduce extern C for complete source
            file.
            * mc-boot-ch/GSYSTEM.c: Introduce extern C for complete source
            file.
            * mc-boot-ch/GSelective.c: Introduce extern C for complete source
            file.
            * mc-boot-ch/GSysExceptions.c: Introduce extern C for complete
            source file.
            * mc-boot-ch/GUnixArgs.c: Introduce extern C for complete source
            file.
            * mc-boot-ch/Gdtoa.c: Introduce extern C for complete source
            file.
            * mc-boot-ch/Gerrno.c: Introduce extern C for complete source
            file.
            * mc-boot-ch/Gldtoa.c: Introduce extern C for complete source
            file.
            * mc-boot-ch/Glibc.c: Introduce extern C for complete source
            file.
            * mc-boot-ch/Gmcrts.c: Removed fancy_abort. Introduce extern C for
            complete source file.
            * mc-boot-ch/Gtermios.c: Introduce extern C for complete source
            file.
            * mc-boot-ch/Gwrapc.c: Introduce extern C for complete source
            file.
            * mc-boot/GASCII.c: Rebuilt.
            * mc-boot/GASCII.h: Rebuilt.
            * mc-boot/GArgs.c: Rebuilt.
            * mc-boot/GArgs.h: Rebuilt.
            * mc-boot/GAssertion.c: Rebuilt.
            * mc-boot/GAssertion.h: Rebuilt.
            * mc-boot/GBreak.c: Rebuilt.
            * mc-boot/GBreak.h: Rebuilt.
            * mc-boot/GCOROUTINES.h: Rebuilt.
            * mc-boot/GCmdArgs.c: Rebuilt.
            * mc-boot/GCmdArgs.h: Rebuilt.
            * mc-boot/GDebug.c: Rebuilt.
            * mc-boot/GDebug.h: Rebuilt.
            * mc-boot/GDynamicStrings.c: Rebuilt.
            * mc-boot/GDynamicStrings.h: Rebuilt.
            * mc-boot/GEnvironment.c: Rebuilt.
            * mc-boot/GEnvironment.h: Rebuilt.
            * mc-boot/GFIO.c: Rebuilt.
            * mc-boot/GFIO.h: Rebuilt.
            * mc-boot/GFormatStrings.c Rebuilt.:
            * mc-boot/GFormatStrings.h: Rebuilt.
            * mc-boot/GFpuIO.c: Rebuilt.
            * mc-boot/GFpuIO.h: Rebuilt.
            * mc-boot/GIO.c: Rebuilt.
            * mc-boot/GIO.h: Rebuilt.
            * mc-boot/GIndexing.c: Rebuilt.
            * mc-boot/GIndexing.h: Rebuilt.
            * mc-boot/GM2EXCEPTION.c: Rebuilt.
            * mc-boot/GM2EXCEPTION.h: Rebuilt.
            * mc-boot/GM2RTS.c: Rebuilt.
            * mc-boot/GM2RTS.h: Rebuilt.
            * mc-boot/GMemUtils.c: Rebuilt.
            * mc-boot/GMemUtils.h: Rebuilt.
            * mc-boot/GNumberIO.c: Rebuilt.
            * mc-boot/GNumberIO.h: Rebuilt.
            * mc-boot/GPushBackInput.c: Rebuilt.
            * mc-boot/GPushBackInput.h: Rebuilt.
            * mc-boot/GRTExceptions.c: Rebuilt.
            * mc-boot/GRTExceptions.h: Rebuilt.
            * mc-boot/GRTco.h: Rebuilt.
            * mc-boot/GRTint.c: Rebuilt.
            * mc-boot/GRTint.h: Rebuilt.
            * mc-boot/GSArgs.c: Rebuilt.
            * mc-boot/GSArgs.h: Rebuilt.
            * mc-boot/GSFIO.c: Rebuilt.
            * mc-boot/GSFIO.h: Rebuilt.
            * mc-boot/GSYSTEM.h: Rebuilt.
            * mc-boot/GSelective.h: Rebuilt.
            * mc-boot/GStdIO.c: Rebuilt.
            * mc-boot/GStdIO.h: Rebuilt.
            * mc-boot/GStorage.c: Rebuilt.
            * mc-boot/GStorage.h: Rebuilt.
            * mc-boot/GStrCase.c: Rebuilt.
            * mc-boot/GStrCase.h: Rebuilt.
            * mc-boot/GStrIO.c: Rebuilt.
            * mc-boot/GStrIO.h: Rebuilt.
            * mc-boot/GStrLib.c: Rebuilt.
            * mc-boot/GStrLib.h: Rebuilt.
            * mc-boot/GStringConvert.c: Rebuilt.
            * mc-boot/GStringConvert.h: Rebuilt.
            * mc-boot/GSysExceptions.h: Rebuilt.
            * mc-boot/GSysStorage.c: Rebuilt.
            * mc-boot/GSysStorage.h: Rebuilt.
            * mc-boot/GTimeString.c: Rebuilt.
            * mc-boot/GTimeString.h: Rebuilt.
            * mc-boot/GUnixArgs.h: Rebuilt.
            * mc-boot/Galists.c: Rebuilt.
            * mc-boot/Galists.h: Rebuilt.
            * mc-boot/Gdecl.c: Rebuilt.
            * mc-boot/Gdecl.h: Rebuilt.
            * mc-boot/Gdtoa.h: Rebuilt.
            * mc-boot/Gerrno.h: Rebuilt.
            * mc-boot/Gkeyc.c: Rebuilt.
            * mc-boot/Gkeyc.h: Rebuilt.
            * mc-boot/Gldtoa.h: Rebuilt.
            * mc-boot/Glibc.h: Rebuilt.
            * mc-boot/Glibm.h: Rebuilt.
            * mc-boot/Glists.c: Rebuilt.
            * mc-boot/Glists.h: Rebuilt.
            * mc-boot/GmcComment.c: Rebuilt.
            * mc-boot/GmcComment.h: Rebuilt.
            * mc-boot/GmcComp.c: Rebuilt.
            * mc-boot/GmcComp.h: Rebuilt.
            * mc-boot/GmcDebug.c: Rebuilt.
            * mc-boot/GmcDebug.h: Rebuilt.
            * mc-boot/GmcError.c: Rebuilt.
            * mc-boot/GmcError.h: Rebuilt.
            * mc-boot/GmcFileName.c: Rebuilt.
            * mc-boot/GmcFileName.h: Rebuilt.
            * mc-boot/GmcLexBuf.c: Rebuilt.
            * mc-boot/GmcLexBuf.h: Rebuilt.
            * mc-boot/GmcMetaError.c: Rebuilt.
            * mc-boot/GmcMetaError.h: Rebuilt.
            * mc-boot/GmcOptions.c: Rebuilt.
            * mc-boot/GmcOptions.h: Rebuilt.
            * mc-boot/GmcPreprocess.c: Rebuilt.
            * mc-boot/GmcPreprocess.h: Rebuilt.
            * mc-boot/GmcPretty.c: Rebuilt.
            * mc-boot/GmcPretty.h: Rebuilt.
            * mc-boot/GmcPrintf.c: Rebuilt.
            * mc-boot/GmcPrintf.h: Rebuilt.
            * mc-boot/GmcQuiet.c: Rebuilt.
            * mc-boot/GmcQuiet.h: Rebuilt.
            * mc-boot/GmcReserved.c: Rebuilt.
            * mc-boot/GmcReserved.h: Rebuilt.
            * mc-boot/GmcSearch.c: Rebuilt.
            * mc-boot/GmcSearch.h: Rebuilt.
            * mc-boot/GmcStack.c: Rebuilt.
            * mc-boot/GmcStack.h: Rebuilt.
            * mc-boot/GmcStream.c: Rebuilt.
            * mc-boot/GmcStream.h: Rebuilt.
            * mc-boot/Gmcflex.h: Rebuilt.
            * mc-boot/Gmcp1.c: Rebuilt.
            * mc-boot/Gmcp1.h: Rebuilt.
            * mc-boot/Gmcp2.c: Rebuilt.
            * mc-boot/Gmcp2.h: Rebuilt.
            * mc-boot/Gmcp3.c: Rebuilt.
            * mc-boot/Gmcp3.h: Rebuilt.
            * mc-boot/Gmcp4.c: Rebuilt.
            * mc-boot/Gmcp4.h: Rebuilt.
            * mc-boot/Gmcp5.c: Rebuilt.
            * mc-boot/Gmcp5.h: Rebuilt.
            * mc-boot/GnameKey.c: Rebuilt.
            * mc-boot/GnameKey.h: Rebuilt.
            * mc-boot/GsymbolKey.c: Rebuilt.
            * mc-boot/GsymbolKey.h: Rebuilt.
            * mc-boot/Gtermios.h: Rebuilt.
            * mc-boot/Gtop.c: Rebuilt.
            * mc-boot/Gvarargs.c: Rebuilt.
            * mc-boot/Gvarargs.h: Rebuilt.
            * mc-boot/Gwlists.c: Rebuilt.
            * mc-boot/Gwlists.h: Rebuilt.
            * mc-boot/Gwrapc.h: Rebuilt.
            * mc/decl.mod: (returnT) scope field added.  (makeReturn)
            initialize scope field.  (doReturnC) check scope field and
            generate error if expression exists and no return type specified.
            Call doExprCastC to cast the return expression.
            (outDefC) Call keyc.genConfigSystem before entering extern C
            block.  (outImpC) Call keyc.genConfigSystem prior to keyc.genDefs.
            (outModuleC) Call keyc.genConfigSystem prior to keyc.genDefs.
            * mc/keyc.def: (genConfigSystem) exported.
            * mc/varargs.mod: (copy) Rewritten pointer arithmetic to allow for
            Modula-2 and translated C++ versions to compile cleanly.
            * tools-src/mklink.c: Replace option --gcc with --langc.  Replace
            option --g++ with --langc++.
    
    Signed-off-by: Gaius Mulley <gaius.mulley@southwales.ac.uk>

Diff:
---
 gcc/m2/Make-lang.in                |  166 +-
 gcc/m2/gm2-ici/m2linemap.c         |    8 +
 gcc/m2/gm2-libs-ch/README          |    6 +-
 gcc/m2/gm2-libs-ch/RTcodummy.c     |   10 +
 gcc/m2/gm2-libs-ch/RTintdummy.c    |    7 +
 gcc/m2/gm2-libs-ch/Selective.c     |   19 +-
 gcc/m2/gm2-libs-ch/SysExceptions.c |   21 +-
 gcc/m2/gm2-libs-ch/UnixArgs.c      |    8 +
 gcc/m2/gm2-libs-ch/cgetopt.c       |   10 +
 gcc/m2/gm2-libs-ch/choosetemp.c    |    7 +
 gcc/m2/gm2-libs-ch/dtoa.c          |   13 +-
 gcc/m2/gm2-libs-ch/errno.c         |    8 +
 gcc/m2/gm2-libs-ch/host.c          |    8 +
 gcc/m2/gm2-libs-ch/ldtoa.c         |   12 +-
 gcc/m2/gm2-libs-ch/termios.c       |    8 +
 gcc/m2/gm2-libs-ch/tools.c         |    3 +-
 gcc/m2/gm2-libs-ch/wrapc.c         |   10 +-
 gcc/m2/gm2-libs-ch/xlibc.c         |    8 +
 gcc/m2/mc-boot-ch/GBuiltins.c      |    9 +
 gcc/m2/mc-boot-ch/GRTco.c          |   17 +
 gcc/m2/mc-boot-ch/GSYSTEM.c        |    8 +
 gcc/m2/mc-boot-ch/GSelective.c     |   34 +
 gcc/m2/mc-boot-ch/GSysExceptions.c |   10 +
 gcc/m2/mc-boot-ch/GUnixArgs.c      |    9 +
 gcc/m2/mc-boot-ch/Gabort.c         |   30 +
 gcc/m2/mc-boot-ch/Gdtoa.c          |   16 +-
 gcc/m2/mc-boot-ch/Gerrno.c         |    8 +
 gcc/m2/mc-boot-ch/Gldtoa.c         |   12 +-
 gcc/m2/mc-boot-ch/Glibc.c          |   33 +-
 gcc/m2/mc-boot-ch/Gmcrts.c         |   15 +-
 gcc/m2/mc-boot-ch/Gtermios.c       |   90 +-
 gcc/m2/mc-boot-ch/Gwrapc.c         |    6 +-
 gcc/m2/mc-boot/GASCII.c            |    4 +-
 gcc/m2/mc-boot/GASCII.h            |    4 +-
 gcc/m2/mc-boot/GArgs.c             |   28 +-
 gcc/m2/mc-boot/GArgs.h             |    4 +-
 gcc/m2/mc-boot/GAssertion.c        |   10 +-
 gcc/m2/mc-boot/GAssertion.h        |    4 +-
 gcc/m2/mc-boot/GBreak.c            |    4 +-
 gcc/m2/mc-boot/GBreak.h            |    4 +-
 gcc/m2/mc-boot/GCOROUTINES.h       |    4 +-
 gcc/m2/mc-boot/GCmdArgs.c          |   54 +-
 gcc/m2/mc-boot/GCmdArgs.h          |    8 +-
 gcc/m2/mc-boot/GDebug.c            |   26 +-
 gcc/m2/mc-boot/GDebug.h            |    8 +-
 gcc/m2/mc-boot/GDynamicStrings.c   |  562 ++--
 gcc/m2/mc-boot/GDynamicStrings.h   |   20 +-
 gcc/m2/mc-boot/GEnvironment.c      |   16 +-
 gcc/m2/mc-boot/GEnvironment.h      |    6 +-
 gcc/m2/mc-boot/GFIO.c              |  610 ++--
 gcc/m2/mc-boot/GFIO.h              |   14 +-
 gcc/m2/mc-boot/GFormatStrings.c    |  208 +-
 gcc/m2/mc-boot/GFormatStrings.h    |   12 +-
 gcc/m2/mc-boot/GFpuIO.c            |   86 +-
 gcc/m2/mc-boot/GFpuIO.h            |   10 +-
 gcc/m2/mc-boot/GIO.c               |  140 +-
 gcc/m2/mc-boot/GIO.h               |    4 +-
 gcc/m2/mc-boot/GIndexing.c         |  106 +-
 gcc/m2/mc-boot/GIndexing.h         |    6 +-
 gcc/m2/mc-boot/GM2EXCEPTION.c      |   20 +-
 gcc/m2/mc-boot/GM2EXCEPTION.h      |    4 +-
 gcc/m2/mc-boot/GM2RTS.c            |  180 +-
 gcc/m2/mc-boot/GM2RTS.h            |   10 +-
 gcc/m2/mc-boot/GMemUtils.c         |   52 +-
 gcc/m2/mc-boot/GMemUtils.h         |    4 +-
 gcc/m2/mc-boot/GNumberIO.c         |  234 +-
 gcc/m2/mc-boot/GNumberIO.h         |   20 +-
 gcc/m2/mc-boot/GPushBackInput.c    |  124 +-
 gcc/m2/mc-boot/GPushBackInput.h    |   12 +-
 gcc/m2/mc-boot/GRTExceptions.c     |  168 +-
 gcc/m2/mc-boot/GRTExceptions.h     |    4 +-
 gcc/m2/mc-boot/GRTco.h             |    4 +-
 gcc/m2/mc-boot/GRTint.c            |  190 +-
 gcc/m2/mc-boot/GRTint.h            |    4 +-
 gcc/m2/mc-boot/GSArgs.c            |   18 +-
 gcc/m2/mc-boot/GSArgs.h            |    4 +-
 gcc/m2/mc-boot/GSFIO.c             |   42 +-
 gcc/m2/mc-boot/GSFIO.h             |    4 +-
 gcc/m2/mc-boot/GSYSTEM.h           |    4 +-
 gcc/m2/mc-boot/GSelective.h        |    4 +-
 gcc/m2/mc-boot/GStdIO.c            |   40 +-
 gcc/m2/mc-boot/GStdIO.h            |    4 +-
 gcc/m2/mc-boot/GStorage.c          |   22 +-
 gcc/m2/mc-boot/GStorage.h          |    4 +-
 gcc/m2/mc-boot/GStrCase.c          |   32 +-
 gcc/m2/mc-boot/GStrCase.h          |    8 +-
 gcc/m2/mc-boot/GStrIO.c            |   22 +-
 gcc/m2/mc-boot/GStrIO.h            |    6 +-
 gcc/m2/mc-boot/GStrLib.c           |   70 +-
 gcc/m2/mc-boot/GStrLib.h           |   18 +-
 gcc/m2/mc-boot/GStringConvert.c    |  534 +--
 gcc/m2/mc-boot/GStringConvert.h    |    4 +-
 gcc/m2/mc-boot/GSysExceptions.h    |    4 +-
 gcc/m2/mc-boot/GSysStorage.c       |   72 +-
 gcc/m2/mc-boot/GSysStorage.h       |    4 +-
 gcc/m2/mc-boot/GTimeString.c       |   16 +-
 gcc/m2/mc-boot/GTimeString.h       |    4 +-
 gcc/m2/mc-boot/GUnixArgs.h         |    4 +-
 gcc/m2/mc-boot/Galists.c           |   84 +-
 gcc/m2/mc-boot/Galists.h           |    6 +-
 gcc/m2/mc-boot/Gdecl.c             | 6527 ++++++++++++++++++------------------
 gcc/m2/mc-boot/Gdecl.h             |    8 +-
 gcc/m2/mc-boot/Gdtoa.h             |    4 +-
 gcc/m2/mc-boot/Gerrno.h            |    4 +-
 gcc/m2/mc-boot/Gkeyc.c             |  444 +--
 gcc/m2/mc-boot/Gkeyc.h             |   13 +-
 gcc/m2/mc-boot/Gldtoa.h            |    4 +-
 gcc/m2/mc-boot/Glibc.h             |    8 +-
 gcc/m2/mc-boot/Glibm.h             |    4 +-
 gcc/m2/mc-boot/Glists.c            |   84 +-
 gcc/m2/mc-boot/Glists.h            |    6 +-
 gcc/m2/mc-boot/GmcComment.c        |   98 +-
 gcc/m2/mc-boot/GmcComment.h        |    6 +-
 gcc/m2/mc-boot/GmcComp.c           |  100 +-
 gcc/m2/mc-boot/GmcComp.h           |    6 +-
 gcc/m2/mc-boot/GmcDebug.c          |   16 +-
 gcc/m2/mc-boot/GmcDebug.h          |    8 +-
 gcc/m2/mc-boot/GmcError.c          |  314 +-
 gcc/m2/mc-boot/GmcError.h          |   30 +-
 gcc/m2/mc-boot/GmcFileName.c       |   36 +-
 gcc/m2/mc-boot/GmcFileName.h       |    6 +-
 gcc/m2/mc-boot/GmcLexBuf.c         |  458 +--
 gcc/m2/mc-boot/GmcLexBuf.h         |    6 +-
 gcc/m2/mc-boot/GmcMetaError.c      |  400 +--
 gcc/m2/mc-boot/GmcMetaError.h      |   54 +-
 gcc/m2/mc-boot/GmcOptions.c        |  344 +-
 gcc/m2/mc-boot/GmcOptions.h        |    6 +-
 gcc/m2/mc-boot/GmcPreprocess.c     |   34 +-
 gcc/m2/mc-boot/GmcPreprocess.h     |    6 +-
 gcc/m2/mc-boot/GmcPretty.c         |  104 +-
 gcc/m2/mc-boot/GmcPretty.h         |    8 +-
 gcc/m2/mc-boot/GmcPrintf.c         |  170 +-
 gcc/m2/mc-boot/GmcPrintf.h         |   26 +-
 gcc/m2/mc-boot/GmcQuiet.c          |   34 +-
 gcc/m2/mc-boot/GmcQuiet.h          |   16 +-
 gcc/m2/mc-boot/GmcReserved.c       |    4 +-
 gcc/m2/mc-boot/GmcReserved.h       |    6 +-
 gcc/m2/mc-boot/GmcSearch.c         |  116 +-
 gcc/m2/mc-boot/GmcSearch.h         |    6 +-
 gcc/m2/mc-boot/GmcStack.c          |   48 +-
 gcc/m2/mc-boot/GmcStack.h          |    6 +-
 gcc/m2/mc-boot/GmcStream.c         |   44 +-
 gcc/m2/mc-boot/GmcStream.h         |    6 +-
 gcc/m2/mc-boot/Gmcflex.h           |    6 +-
 gcc/m2/mc-boot/Gmcp1.c             | 1110 +++---
 gcc/m2/mc-boot/Gmcp1.h             |    6 +-
 gcc/m2/mc-boot/Gmcp2.c             | 1148 +++----
 gcc/m2/mc-boot/Gmcp2.h             |    6 +-
 gcc/m2/mc-boot/Gmcp3.c             | 1218 +++----
 gcc/m2/mc-boot/Gmcp3.h             |    6 +-
 gcc/m2/mc-boot/Gmcp4.c             | 1178 +++----
 gcc/m2/mc-boot/Gmcp4.h             |    6 +-
 gcc/m2/mc-boot/Gmcp5.c             | 1346 ++++----
 gcc/m2/mc-boot/Gmcp5.h             |    6 +-
 gcc/m2/mc-boot/GnameKey.c          |  100 +-
 gcc/m2/mc-boot/GnameKey.h          |   10 +-
 gcc/m2/mc-boot/GsymbolKey.c        |   58 +-
 gcc/m2/mc-boot/GsymbolKey.h        |    6 +-
 gcc/m2/mc-boot/Gtermios.h          |    4 +-
 gcc/m2/mc-boot/Gtop.c              |    6 +-
 gcc/m2/mc-boot/Gvarargs.c          |  184 +-
 gcc/m2/mc-boot/Gvarargs.h          |   14 +-
 gcc/m2/mc-boot/Gwlists.c           |   88 +-
 gcc/m2/mc-boot/Gwlists.h           |    6 +-
 gcc/m2/mc-boot/Gwrapc.h            |    4 +-
 gcc/m2/mc/decl.mod                 |   23 +-
 gcc/m2/mc/keyc.def                 |    8 +
 gcc/m2/mc/keyc.mod                 |   15 +-
 gcc/m2/mc/varargs.mod              |    8 +-
 gcc/m2/tools-src/mklink.c          |   18 +-
 170 files changed, 10661 insertions(+), 10210 deletions(-)

diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index c8240748400..5036c538085 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -28,11 +28,9 @@ GM2_TARGET_INSTALL_NAME = $(target_noncanonical)-$(shell echo gm2|sed '$(program
 # Actual names to use when installing a cross-compiler.
 GM2_CROSS_NAME = `echo gm2|sed '$(program_transform_cross_name)'`
 
-CPLUS = g++
 GM2_1 = ./gm2 -B./stage1/m2 -g -fm2-g
 XGCC = ./xgcc -B./
 GM2_2 = ./gm2 -B./stage2/m2 -g -fm2-g
-HOSTCC = gcc
 CFLAGS=-g   ## remove this
 LDLAGS=-g   ## remove this
 
@@ -933,35 +931,35 @@ m2/gm2-libs-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs/%.def $(MCDEPS)
 	$(MC) -o=$@ $(srcdir)/m2/gm2-libs/$*.def
 
 m2/gm2-libs-boot/RTcodummy.o: $(srcdir)/m2/gm2-libs-ch/RTcodummy.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -c -DIN_GCC $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
+	$(CXX) -c -DIN_GCC $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/RTintdummy.o: $(srcdir)/m2/gm2-libs-ch/RTintdummy.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -c -DIN_GCC $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
+	$(CXX) -c -DIN_GCC $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/wrapc.o: $(srcdir)/m2/gm2-libs-ch/wrapc.c m2/gm2-libs-boot/$(SRC_PREFIX)wrapc.h m2/gm2-libs/gm2-libs-host.h
-	$(CC) -c -DHAVE_CONFIG_H $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
+	$(CXX) -c -DHAVE_CONFIG_H $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/UnixArgs.o: $(srcdir)/m2/gm2-libs-ch/UnixArgs.c m2/gm2-libs-boot/$(SRC_PREFIX)UnixArgs.h m2/gm2-libs/gm2-libs-host.h
-	$(CC) -c -DIN_GCC $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
+	$(CXX) -c -DIN_GCC $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/choosetemp.o: m2/gm2-libs-ch/choosetemp.c m2/gm2-libiberty/Gchoosetemp.h m2/gm2-libs/gm2-libs-host.h
-	$(CC) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot -Im2/gm2-libiberty -I$(srcdir)/m2/gm2-libiberty/ $(INCLUDES) $< -o $@
+	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot -Im2/gm2-libiberty -I$(srcdir)/m2/gm2-libiberty/ $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/errno.o: $(srcdir)/m2/gm2-libs-ch/errno.c m2/gm2-libs-boot/$(SRC_PREFIX)errno.h m2/gm2-libs/gm2-libs-host.h
-	$(CC) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
+	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/dtoa.o: $(srcdir)/m2/gm2-libs-ch/dtoa.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
+	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/ldtoa.o: $(srcdir)/m2/gm2-libs-ch/ldtoa.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
+	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/termios.o: $(srcdir)/m2/gm2-libs-ch/termios.c m2/gm2-libs-boot/$(SRC_PREFIX)termios.h m2/gm2-libs/gm2-libs-host.h
-	$(CC) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
+	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/SysExceptions.o: $(srcdir)/m2/gm2-libs-ch/SysExceptions.c \
                                   m2/gm2-libs-boot/$(SRC_PREFIX)SysExceptions.h m2/gm2-libs/gm2-libs-host.h
-	$(CC) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
+	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/SysStorage.o: $(srcdir)/m2/gm2-libs/SysStorage.mod $(MCDEPS) $(BUILD-BOOT-H)
 	$(MC) -o=m2/gm2-libs-boot/SysStorage.c $(srcdir)/m2/gm2-libs/SysStorage.mod
@@ -1081,10 +1079,10 @@ m2/gm2-ici/m2flex.o: m2/gm2-compiler/m2flex.c $(BUILD-BOOT-H) $(TIMEVAR_H)
           -Im2 -Im2/gm2-compiler-boot -Im2/gm2-libs-boot $< -o $@
 
 m2/gm2-ici-boot/m2linemap.o: $(srcdir)/m2/gm2-ici/m2linemap.c $(BUILD-BOOT-H) $(TIMEVAR_H)
-	$(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@
+	$(CXX) -c $(CFLAGS) $(INCLUDES) $< -o $@
 
 m2/gm2-ici/m2linemap.o: $(srcdir)/m2/gm2-ici/m2linemap.c $(BUILD-BOOT-H) $(TIMEVAR_H)
-	$(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@
+	$(CXX) -c $(CFLAGS) $(INCLUDES) $< -o $@
 
 m2/gm2-compiler-boot/m2flex.o: m2/gm2-compiler/m2flex.c $(BUILD-BOOT-H) $(TIMEVAR_H) \
         $(BUILD-LIBS-BOOT-H)  m2/gm2-compiler-boot/$(SRC_PREFIX)NameKey.h \
@@ -1180,7 +1178,7 @@ m2/gm2-compiler/M2Version.mod:
 	sh $(srcdir)/m2/tools-src/makeversion -m $(srcdir) m2/gm2-compiler
 
 m2/gm2-libs-iso/%.o: $(srcdir)/m2/gm2-libs-iso/%.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -DBUILD_GM2_LIBS_TARGET -DBUILD_GM2_LIBS -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
+	$(CXX) -DBUILD_GM2_LIBS_TARGET -DBUILD_GM2_LIBS -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-iso/%.o: $(srcdir)/m2/gm2-libs-iso/%.mod
 	$(GM2_1) $(GM2_ISO_FLAGS) -c -B./ -Im2/gm2-libs-iso:$(srcdir)/m2/gm2-libs-iso -I$(srcdir)/m2/gm2-libs $< -o $@
@@ -1393,7 +1391,7 @@ m2/boot-bin/mc-devel$(exeext): $(objdir)/m2/gm2-auto/mcp1.mod \
                                 $(objdir)/m2/gm2-auto/mcp4.mod \
                                 $(objdir)/m2/gm2-auto/mcp5.mod \
                                 mcflex.c
-	$(HOSTCC) -I$(srcdir)/m2/mc -c -g mcflex.c
+	$(CC) -I$(srcdir)/m2/mc -c -g mcflex.c
 	$(BOOTGM2) $(MCOPTIONS) -I$(GM2PATH) $(srcdir)/m2/mc/decl.mod
 	$(BOOTGM2) $(MCOPTIONS) -I$(GM2PATH) $(srcdir)/m2/mc/mcStream.mod
 	$(BOOTGM2) $(MCOPTIONS) -I$(GM2PATH) $(srcdir)/m2/mc/mcPretty.mod
@@ -1524,7 +1522,7 @@ MC-BOOT-C = $(MC-MODS:%.mod=%.c) $(MC-AUTO-MODS:%.mod=%.c)
 
 MC-INTERFACE-C = libc.c mcrts.c UnixArgs.c Selective.c termios.c \
                  SysExceptions.c ldtoa.c dtoa.c wrapc.c \
-                 SYSTEM.c errno.c
+                 SYSTEM.c errno.c abort.c
 
 BUILD-MC-BOOT-H =  $(MC-LIB-DEFS:%.def=m2/mc-boot-gen/$(SRC_PREFIX)%.h) \
                    $(MC-DEFS:%.def=m2/mc-boot-gen/$(SRC_PREFIX)%.h)
@@ -1555,7 +1553,9 @@ $(objdir)/m2/mc-boot-gen:
 mc-autogen: mc-clean mc-devel \
             $(BUILD-MC-BOOT-H) $(BUILD-MC-BOOT-C) \
             $(BUILD-MC-BOOT-AUTO-C)
-	for i in m2/mc-boot-gen/*.c ; do $(HOSTCC) -g -c -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/mc-boot-gen/ $$i -o m2/mc-boot-gen/$(shell basename $$i .c).o ; done
+	for i in m2/mc-boot-gen/*.c ; do \
+           echo $(CXX) -g -c -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/mc-boot-gen/ $$i -o m2/mc-boot-gen/`basename $$i .c`.o ; \
+                $(CXX) -g -c -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/mc-boot-gen/ $$i -o m2/mc-boot-gen/`basename $$i .c`.o ; done
 	@echo -n "built "
 	@cd m2/mc-boot-gen ; ls *.o | wc -l
 	@echo -n "out of "
@@ -1564,7 +1564,7 @@ mc-autogen: mc-clean mc-devel \
 
 # EXTENDED_OPAQUE = --extended-opaque
 EXTENDED_OPAQUE =
-MC_OPTIONS = $(MC_COPYRIGHT) --gcc-config-system
+MC_OPTIONS = $(MC_COPYRIGHT) --gcc-config-system --olang=c++
 
 m2/mc-boot-gen/$(SRC_PREFIX)%.h: $(srcdir)/m2/mc/%.def
 	./mc $(MC_OPTIONS) -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso $(EXTENDED_OPAQUE) --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
@@ -1588,10 +1588,10 @@ m2/mc-boot-gen/$(SRC_PREFIX)%.c: m2/gm2-auto/%.mod
 	./mc $(MC_OPTIONS) -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso $(EXTENDED_OPAQUE) --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
 
 m2/mc-boot/$(SRC_PREFIX)%.o: m2/mc-boot/$(SRC_PREFIX)%.c
-	$(HOSTCC) -g -c -I. -I$(srcdir)/m2/mc-boot-ch -I$(srcdir)/../include -I$(srcdir) $< -o $@
+	$(CXX) -g -c -I. -I$(srcdir)/m2/mc-boot-ch -I$(srcdir)/../include -I$(srcdir) $< -o $@
 
 m2/mc-boot-ch/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.c m2/gm2-libs/gm2-libs-host.h
-	$(HOSTCC) -DHAVE_CONFIG_H -g -c -I. -Im2/gm2-libs -I$(srcdir)/../include -I$(srcdir) -Im2/gm2-libs $< -o $@
+	$(CXX) -DHAVE_CONFIG_H -g -c -I. -Im2/gm2-libs -I$(srcdir)/../include -I$(srcdir) -Im2/gm2-libs $< -o $@
 
 # mc-bootstrap compiles mc using the C version previously generated by mc-autogen.
 # These autogenerated files will be checked into git by the maintainer.
@@ -1603,9 +1603,9 @@ m2/boot-bin/mc$(exeext): $(BUILD-MC-BOOT-O) $(BUILD-MC-INTERFACE-O) m2/mc-boot/m
          $(BUILD-MC-INTERFACE-O) m2/mc-boot/main.o mcflex.o m2/gm2-libs-boot/RTcodummy.o -lm
 
 m2/mc-boot/main.o: $(M2LINK) $(srcdir)/m2/init/mcinit
-	unset CC ; $(M2LINK) -s --gcc --exit --name mainmcinit.c $(srcdir)/m2/init/mcinit
+	unset CC ; $(M2LINK) -s --langc++ --exit --name mainmcinit.c $(srcdir)/m2/init/mcinit
 	mv mainmcinit.c m2/mc-boot/main.c
-	$(HOSTCC) -g -c -I. -I$(srcdir)/../include -I$(srcdir) m2/mc-boot/main.c -o $@
+	$(CXX) -g -c -I. -I$(srcdir)/../include -I$(srcdir) m2/mc-boot/main.c -o $@
 
 # The rules which build objects in the gm2-compiler-paranoid gm2-libs-paranoid directories.
 
@@ -1646,18 +1646,18 @@ m2/gm2-compiler-paranoid/PCBuild.o: $(objdir)/m2/gm2-compiler-paranoid/PCBuild.m
 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
 
 m2/gm2-libs-paranoid/host.o: $(srcdir)/m2/gm2-libs-ch/host.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -c $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $< -o $@
+	$(CXX) -c $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $< -o $@
 
 m2/gm2-libs-paranoid/wrapc.o: $(srcdir)/m2/gm2-libs-ch/wrapc.c m2/gm2-libs-boot/$(SRC_PREFIX)wrapc.h m2/gm2-libs/gm2-libs-host.h
-	$(CC) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
+	$(CXX) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-paranoid/UnixArgs.o: $(srcdir)/m2/gm2-libs-ch/UnixArgs.c \
                                   m2/gm2-libs-boot/$(SRC_PREFIX)UnixArgs.h
-	$(CC) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
+	$(CXX) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-paranoid/errno.o: $(srcdir)/m2/gm2-libs-ch/errno.c \
                                    m2/gm2-libs-boot/$(SRC_PREFIX)errno.h
-	$(CC) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
+	$(CXX) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-paranoid/Selective.o: $(srcdir)/m2/gm2-libs-ch/Selective.c \
                                    m2/gm2-libs-boot/$(SRC_PREFIX)Selective.h
@@ -1665,11 +1665,11 @@ m2/gm2-libs-paranoid/Selective.o: $(srcdir)/m2/gm2-libs-ch/Selective.c \
 
 m2/gm2-libs-paranoid/choosetemp.o: $(srcdir)/m2/gm2-libs-ch/choosetemp.c \
                                     m2/gm2-libiberty/$(SRC_PREFIX)choosetemp.h
-	$(CC) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot -Im2/gm2-libiberty $(INCLUDES) $< -o $@
+	$(CXX) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot -Im2/gm2-libiberty $(INCLUDES) $< -o $@
 
 m2/gm2-libs-paranoid/SysExceptions.o: $(srcdir)/m2/gm2-libs-ch/SysExceptions.c \
                                   m2/gm2-libs-boot/$(SRC_PREFIX)SysExceptions.h
-	$(CC) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
+	$(CXX) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-compiler-paranoid/m2flex.o: m2/gm2-compiler/m2flex.c $(TIMEVAR_H)
 	$(COMPILER) -c $(GM2_O_S3) -g $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
@@ -1678,17 +1678,17 @@ m2/gm2-compiler-paranoid/m2flex.o: m2/gm2-compiler/m2flex.c $(TIMEVAR_H)
 m2/gm2-libs-paranoid/dtoa.o: $(srcdir)/m2/gm2-libs-ch/dtoa.c \
                               m2/gm2-libs-boot/$(SRC_PREFIX)dtoa.h \
                               m2/gm2-libs/gm2-libs-host.h
-	$(CC) -c $(GM2_O_S3) $(CFLAGS) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
+	$(CXX) -c $(GM2_O_S3) $(CFLAGS) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
 
 m2/gm2-libs-paranoid/ldtoa.o: $(srcdir)/m2/gm2-libs-ch/ldtoa.c \
                                m2/gm2-libs-boot/$(SRC_PREFIX)ldtoa.h \
                                m2/gm2-libs/gm2-libs-host.h
-	$(CC) -c $(GM2_O_S3) $(CFLAGS) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
+	$(CXX) -c $(GM2_O_S3) $(CFLAGS) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
 
 m2/gm2-libs-paranoid/termios.o: $(srcdir)/m2/gm2-libs-ch/termios.c \
                                m2/gm2-libs-boot/$(SRC_PREFIX)termios.h \
                                m2/gm2-libs/gm2-libs-host.h
-	$(CC) -c $(GM2_O_S3) $(CFLAGS) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
+	$(CXX) -c $(GM2_O_S3) $(CFLAGS) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
 
 
 # The rules which build the paranoid version of gm2.
@@ -1740,7 +1740,7 @@ stage1/m2/gm2l$(exeext): \
      m2/gm2-libs-boot/libgm2.a m2/gm2-compiler-boot/gm2l.o \
      m2/gm2-ici/m2flex.o  \
      $(GCC_COLOR) $(GM2_LIBS_BOOT) $(MC_LIBS) $(LIBS)
-	unset CC ; $(M2LINK) -s --g++ --exit --name gm2l_init.c $(srcdir)/m2/init/gm2linit
+	unset CC ; $(M2LINK) -s --langc++ --exit --name gm2l_init.c $(srcdir)/m2/init/gm2linit
 	mv gm2l_init.c m2/gm2-compiler-boot/gm2l_init.c
 	$(COMPILER) -c -g m2/gm2-compiler-boot/gm2l_init.c -o m2/gm2-compiler-boot/gm2l_init.o
 	$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
@@ -1757,7 +1757,7 @@ stage1/m2/gm2lcc$(exeext): \
      m2/gm2-ici-boot/m2linemap.o \
      m2/gm2-libs-boot/libgm2.a m2/gm2-compiler-boot/gm2lcc.o \
      $(GCC_COLOR) $(GM2_LIBS_BOOT) $(MC_LIBS) $(LIBS)
-	unset CC ; $(M2LINK) -s --g++ --exit --name gm2lcc_init.c $(srcdir)/m2/init/gm2lccinit
+	unset CC ; $(M2LINK) -s --langc++ --exit --name gm2lcc_init.c $(srcdir)/m2/init/gm2lccinit
 	mv gm2lcc_init.c m2/gm2-compiler-boot/gm2lcc_init.c
 	$(COMPILER) -c -g m2/gm2-compiler-boot/gm2lcc_init.c -o m2/gm2-compiler-boot/gm2lcc_init.o
 	$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
@@ -1774,7 +1774,7 @@ stage1/m2/gm2lgen$(exeext): \
      m2/gm2-ici-boot/m2linemap.o \
      m2/gm2-libs-boot/libgm2.a m2/gm2-compiler-boot/gm2lgen.o \
      $(GCC_COLOR) $(GM2_LIBS_BOOT) $(MC_LIBS) $(LIBS)
-	unset CC ; $(M2LINK) -s --g++ --exit --name gm2lgen_init.c $(srcdir)/m2/init/gm2lgeninit
+	unset CC ; $(M2LINK) -s --langc++ --exit --name gm2lgen_init.c $(srcdir)/m2/init/gm2lgeninit
 	mv gm2lgen_init.c m2/gm2-compiler-boot/gm2lgen_init.c
 	$(COMPILER) -c -g m2/gm2-compiler-boot/gm2lgen_init.c -o m2/gm2-compiler-boot/gm2lgen_init.o
 	$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
@@ -1791,7 +1791,7 @@ stage1/m2/gm2lorder$(exeext): \
      m2/gm2-ici/m2flex.o \
      m2/gm2-ici-boot/m2linemap.o \
      $(GCC_COLOR) $(GM2_LIBS_BOOT) $(MC_LIBS) $(LIBS)
-	unset CC ; $(M2LINK) -s --g++ --exit --name gm2lorder_init.c $(srcdir)/m2/init/gm2lorderinit
+	unset CC ; $(M2LINK) -s --langc++ --exit --name gm2lorder_init.c $(srcdir)/m2/init/gm2lorderinit
 	mv gm2lorder_init.c m2/gm2-compiler-boot/gm2lorder_init.c
 	$(COMPILER) -c -g m2/gm2-compiler-boot/gm2lorder_init.c -o m2/gm2-compiler-boot/gm2lorder_init.o
 	$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
@@ -1808,7 +1808,7 @@ stage1/m2/gm2m$(exeext): \
      m2/gm2-ici/m2flex.o \
      m2/gm2-ici-boot/m2linemap.o \
      $(GCC_COLOR) $(GM2_LIBS_BOOT) $(MC_LIBS) $(LIBS)
-	unset CC ; $(M2LINK) -s --g++ --exit --name gm2m_init.c $(srcdir)/m2/init/gm2minit
+	unset CC ; $(M2LINK) -s --langc++ --exit --name gm2m_init.c $(srcdir)/m2/init/gm2minit
 	mv gm2m_init.c m2/gm2-compiler-boot/gm2m_init.c
 	$(COMPILER) -c -g m2/gm2-compiler-boot/gm2m_init.c -o m2/gm2-compiler-boot/gm2m_init.o
 	$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
@@ -1832,7 +1832,7 @@ stage2/m2/gm2m$(exeext): $(GM2_LIBS) $(GM2_LINK_TOOLS_BOOT) \
      m2/gm2-compiler/gm2m.o m2/gm2-ici/m2flex.o \
      m2/gm2-libiberty/xlibc.o m2/gm2-gcc/m2color.o \
      diagnostic-color.o m2/gm2-libiberty/tool.o
-	unset CC ; $(M2LINK) -s --g++ --exit --name mod_init.c $(srcdir)/m2/init/gm2minit
+	unset CC ; $(M2LINK) -s --langc++ --exit --name mod_init.c $(srcdir)/m2/init/gm2minit
 	mv mod_init.c m2/gm2-compiler/gm2m_init.c
 	$(COMPILER) -c -g m2/gm2-compiler/gm2m_init.c -o m2/gm2-compiler/gm2m_init.o
 	$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
@@ -1896,7 +1896,7 @@ BUILD-PPG-O = $(PPG-INTERFACE-C:%.c=m2/gm2-ppg-boot/$(SRC_PREFIX)%.o) \
               $(PPG-LIB-MODS:%.mod=m2/gm2-ppg-boot/$(SRC_PREFIX)%.o) \
               $(PPG-SRC:%.mod=m2/gm2-ppg-boot/$(SRC_PREFIX)%.o)
 
-MCC_ARGS= --olang=c \
+MCC_ARGS= --olang=c++ \
  --quiet \
  --h-file-prefix=$(SRC_PREFIX) \
  -I$(srcdir)/m2/gm2-libs \
@@ -1914,27 +1914,27 @@ m2/gm2-ppg-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs/%.def $(MCDEPS)
 	$(MCC) -o=$@ $(srcdir)/m2/gm2-libs/$*.def
 
 m2/gm2-ppg-boot/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
 
 m2/gm2-ppg-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-libs/%.mod $(MCDEPS) $(BUILD-BOOT-H)
 	$(MCC) -o=m2/gm2-ppg-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-libs/$*.mod
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) \
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) \
               -Im2/gm2-ppg-boot -I$(srcdir)/m2/mc-boot \
               -I$(srcdir)/m2/mc-boot-ch -g -c m2/gm2-ppg-boot/$(SRC_PREFIX)$*.c -o $@
 
 m2/gm2-ppg-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-compiler/%.mod $(MCDEPS) $(BUILD-BOOT-H)
 	$(MCC) -o=m2/gm2-ppg-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-compiler/$*.mod
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) \
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) \
               -Im2/mc-boot -Im2/gm2-compiler-boot -Im2/gm2-libs-boot \
               -I$(srcdir)/m2/mc-boot-ch -g -c m2/gm2-ppg-boot/$(SRC_PREFIX)$*.c -o $@
 
-m2/ppg$(exeext): m2/boot-bin/mc $(BUILD-PPG-O) $(BUILD-MC-INTERFACE-O) m2/gm2-ppg-boot/main.o m2/gm2-libs-boot/RTcodummy.o
-	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ $(BUILD-PPG-O) m2/gm2-ppg-boot/main.o m2/gm2-libs-boot/RTcodummy.o -lm
+m2/ppg$(exeext): m2/boot-bin/mc $(BUILD-PPG-O) $(BUILD-MC-INTERFACE-O) m2/gm2-ppg-boot/main.o m2/gm2-libs-boot/RTcodummy.o m2/mc-boot-ch/$(SRC_PREFIX)abort.o
+	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ $(BUILD-PPG-O) m2/gm2-ppg-boot/main.o m2/gm2-libs-boot/RTcodummy.o m2/mc-boot-ch/$(SRC_PREFIX)abort.o -lm
 
 m2/gm2-ppg-boot/main.o: $(M2LINK) $(srcdir)/m2/init/mcinit
-	unset CC ; $(M2LINK) -s --gcc --exit --name mainppginit.c $(srcdir)/m2/init/ppginit
+	unset CC ; $(M2LINK) -s --langc++ --exit --name mainppginit.c $(srcdir)/m2/init/ppginit
 	mv mainppginit.c m2/gm2-ppg-boot/main.c
-	$(CC) -g -c -o $@ m2/gm2-ppg-boot/main.c
+	$(CXX) -g -c -o $@ m2/gm2-ppg-boot/main.c
 
 m2/gm2-auto:
 	test -d $@ || mkdir -p $@
@@ -1953,36 +1953,38 @@ m2/gm2-pg-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs/%.def $(MCDEPS)
 	$(MCC) -o=$@ $(srcdir)/m2/gm2-libs/$*.def
 
 m2/gm2-pg-boot/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
 
 m2/gm2-pg-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-libs/%.mod $(MCDEPS) $(BUILD-BOOT-H)
 	$(MCC) -o=m2/gm2-pg-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-libs/$*.mod
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/gm2-pg-boot	-I$(srcdir)/m2/mc-boot -I$(srcdir)/m2/mc-boot-ch \
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/gm2-pg-boot	-I$(srcdir)/m2/mc-boot -I$(srcdir)/m2/mc-boot-ch \
               -g -c m2/gm2-pg-boot/$(SRC_PREFIX)$*.c -o $@
 
 m2/gm2-pg-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-compiler/%.mod $(MCDEPS) $(BUILD-BOOT-H)
 	$(MCC) -o=m2/gm2-pg-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-compiler/$*.mod
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/mc-boot -Im2/gm2-compiler-boot -Im2/gm2-libs-boot \
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/mc-boot -Im2/gm2-compiler-boot -Im2/gm2-libs-boot \
               -I$(srcdir)/m2/mc-boot-ch -g -c m2/gm2-pg-boot/$(SRC_PREFIX)$*.c -o $@
 
 m2/gm2-pg-boot/$(SRC_PREFIX)pg.o:  m2/gm2-auto/pg.mod $(MCDEPS) $(BUILD-BOOT-H)
 	$(MCC) -o=m2/gm2-pg-boot/$(SRC_PREFIX)pg.c m2/gm2-auto/pg.mod
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/mc-boot -Im2/gm2-compiler-boot -Im2/gm2-libs-boot \
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/mc-boot -Im2/gm2-compiler-boot -Im2/gm2-libs-boot \
               -I$(srcdir)/m2/mc-boot-ch -g -c m2/gm2-pg-boot/$(SRC_PREFIX)pg.c -o $@
 
 m2/pg$(exeext): m2/boot-bin/mc \
     $(BUILD-PG-O) $(GM2-PPG-MODS:%.mod=m2/gm2-pg-boot/%.o) \
-    $(BUILD-MC-INTERFACE-O) m2/gm2-pg-boot/main.o m2/gm2-libs-boot/RTcodummy.o
+    $(BUILD-MC-INTERFACE-O) m2/gm2-pg-boot/main.o m2/gm2-libs-boot/RTcodummy.o \
+    m2/mc-boot-ch/$(SRC_PREFIX)abort.o
 	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ $(BUILD-PG-O) \
-         m2/gm2-pg-boot/main.o m2/gm2-libs-boot/RTcodummy.o -lm
+         m2/gm2-pg-boot/main.o m2/gm2-libs-boot/RTcodummy.o \
+         m2/mc-boot-ch/$(SRC_PREFIX)abort.o -lm
 
 m2/gm2-auto/pginit:
 	sed -e 's/ppg/pg/' < $(srcdir)/m2/init/ppginit > $@
 
 m2/gm2-pg-boot/main.o: m2/gm2-auto/pginit $(M2LINK)
-	unset CC ; $(M2LINK) -s --gcc --exit --name mainpginit.c m2/gm2-auto/pginit
+	unset CC ; $(M2LINK) -s --langc++ --exit --name mainpginit.c m2/gm2-auto/pginit
 	mv mainpginit.c m2/gm2-pg-boot/main.c
-	$(CC) -g -c -o $@ m2/gm2-pg-boot/main.c
+	$(CXX) -g -c -o $@ m2/gm2-pg-boot/main.c
 
 m2/pg-e$(exeext): m2/pg$(exeext)
 	$(CP) m2/pg$(exeext) m2/pg-e$(exeext)
@@ -2017,61 +2019,63 @@ m2/gm2-pge-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs/%.def $(MCDEPS)
 	$(MCC) -o=$@ $(srcdir)/m2/gm2-libs/$*.def
 
 m2/gm2-pge-boot/$(SRC_PREFIX)libc.o: $(srcdir)/m2/mc-boot-ch/Glibc.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)mcrts.o:  $(srcdir)/m2/mc-boot-ch/Gmcrts.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)UnixArgs.o:  $(srcdir)/m2/mc-boot-ch/GUnixArgs.c
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -g -c $< -o $@
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)Selective.o:  $(srcdir)/m2/mc-boot-ch/GSelective.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)termios.o:  $(srcdir)/m2/mc-boot-ch/Gtermios.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)SysExceptions.o:  $(srcdir)/m2/mc-boot-ch/GSysExceptions.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)ldtoa.o:  $(srcdir)/m2/mc-boot-ch/Gldtoa.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)dtoa.o:  $(srcdir)/m2/mc-boot-ch/Gdtoa.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)wrapc.o:  $(srcdir)/m2/mc-boot-ch/Gwrapc.c m2/gm2-libs/gm2-libs-host.h
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)SYSTEM.o:  $(srcdir)/m2/mc-boot-ch/GSYSTEM.c
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -g -c $< -o $@
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)errno.o:  $(srcdir)/m2/mc-boot-ch/Gerrno.c
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -g -c $< -o $@
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-libs/%.mod $(MCDEPS) $(BUILD-BOOT-H)
 	$(MCC) -o=m2/gm2-pge-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-libs/$*.mod
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/gm2-pge-boot -I$(srcdir)/m2/mc-boot \
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/gm2-pge-boot -I$(srcdir)/m2/mc-boot \
               -I$(srcdir)/m2/mc-boot-ch \
               -g -c m2/gm2-pge-boot/$(SRC_PREFIX)$*.c -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-compiler/%.mod $(MCDEPS) $(BUILD-BOOT-H)
 	$(MCC) -o=m2/gm2-pge-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-compiler/$*.mod
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/mc-boot -Im2/gm2-compiler-boot \
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/mc-boot -Im2/gm2-compiler-boot \
               -Im2/gm2-libs-boot \
               -I$(srcdir)/m2/mc-boot-ch -g -c m2/gm2-pge-boot/$(SRC_PREFIX)$*.c -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)pge.o:  m2/gm2-auto/pge.mod $(MCDEPS) $(BUILD-BOOT-H)
 	$(MCC) -o=m2/gm2-pge-boot/$(SRC_PREFIX)pge.c m2/gm2-auto/pge.mod
-	$(CC) -I. -I$(srcdir)/../include -I$(srcdir) \
+	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) \
               -Im2/mc-boot -Im2/gm2-compiler-boot -Im2/gm2-libs-boot \
               -I$(srcdir)/m2/mc-boot-ch -g -c m2/gm2-pge-boot/$(SRC_PREFIX)pge.c -o $@
 
 m2/pge$(exeext): m2/boot-bin/mc \
     $(BUILD-PGE-O) $(GM2-PPG-MODS:%.mod=m2/gm2-pge-boot/%.o) \
-    $(BUILD-MC-INTERFACE-O) m2/gm2-pge-boot/main.o m2/gm2-libs-boot/RTcodummy.o
+    $(BUILD-MC-INTERFACE-O) m2/gm2-pge-boot/main.o m2/gm2-libs-boot/RTcodummy.o \
+    m2/mc-boot-ch/$(SRC_PREFIX)abort.o
 	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ $(BUILD-PGE-O) \
-         m2/gm2-pge-boot/main.o m2/gm2-libs-boot/RTcodummy.o -lm
+         m2/gm2-pge-boot/main.o m2/gm2-libs-boot/RTcodummy.o \
+         m2/mc-boot-ch/$(SRC_PREFIX)abort.o -lm
 	sh $(srcdir)/m2/tools-src/buildpg $(srcdir)/m2/gm2-compiler/ppg.mod t > m2/gm2-auto/t.bnf
 	./m2/pge$(exeext) m2/gm2-auto/t.bnf -o m2/gm2-auto/t1.mod
 	./m2/pg$(exeext) m2/gm2-auto/t.bnf -o m2/gm2-auto/t2.mod
@@ -2086,9 +2090,9 @@ m2/gm2-auto/pgeinit:
 	sed -e 's/ppg/pge/' < $(srcdir)/m2/init/ppginit > $@
 
 m2/gm2-pge-boot/main.o: m2/gm2-auto/pgeinit $(M2LINK)
-	unset CC ; $(M2LINK) -s --gcc --exit --name mainpgeinit.c m2/gm2-auto/pgeinit
+	unset CC ; $(M2LINK) -s --langc++ --exit --name mainpgeinit.c m2/gm2-auto/pgeinit
 	mv mainpgeinit.c m2/gm2-pge-boot/main.c
-	$(CC) -g -c -o $@ m2/gm2-pge-boot/main.c
+	$(CXX) -g -c -o $@ m2/gm2-pge-boot/main.c
 
 $(objdir)/m2/gm2-compiler-paranoid/P0SyntaxCheck.mod: $(srcdir)/m2/bnf/m2.bnf m2/pge$(exeext)
 	./m2/pge$(exeext) -k -l $< -o $@
@@ -2277,24 +2281,6 @@ check-gm2-local: $(GM2TESTSUITEDIR)/site.exp
 	    export TCL_LIBRARY ; fi ; \
 	$(RUNTEST) --tool gm2 --directory testsuite/m2/pim/pass)
 
-gm2-check-examples: force
-	allok="yes" ; \
-        for i in examples/hello examples/gravity/ \
-                 examples/cplusplus/cppcatchm2 examples/cplusplus/m2catchcpp \
-                 examples/callingC examples/iso/socket examples/swig/exceptions \
-                 examples/swig/tiny examples/swig/strlib \
-                 examples/cpp examples/map examples/ncurses ; do \
-          ( testdir=`pwd` ; cd m2/$${i} ; if make clean pre-install >& $${testdir}/log ; \
-                           then echo "passed m2/$${i}" ; \
-                           else echo "failed m2/$${i}" ; allok="no" ; \
-                           fi ) ; \
-        done ; \
-        if [ "$${allok}" == "yes" ] ; then \
-            echo "all examples passed" ; \
-        else \
-            echo "some example(s) failed" ; \
-        fi
-
 gm2.maintainer-reconfigure: force
 	autoconf $(srcdir)/m2/gm2-libs/config-host.in > $(srcdir)/m2/gm2-libs/config-host
 	( cd $(srcdir)/m2/gm2-libs ; autoheader config-host.in )
diff --git a/gcc/m2/gm2-ici/m2linemap.c b/gcc/m2/gm2-ici/m2linemap.c
index 7b2a96afad0..e2af672f73e 100644
--- a/gcc/m2/gm2-ici/m2linemap.c
+++ b/gcc/m2/gm2-ici/m2linemap.c
@@ -22,9 +22,17 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 void
 m2linemap_GetLocationBinary (void)
 {
   fprintf (stderr, "GetLocationBinary should not be called\n");
   exit (1);
 }
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/m2/gm2-libs-ch/README b/gcc/m2/gm2-libs-ch/README
index 498b75c1b9d..a783aa7eb6c 100644
--- a/gcc/m2/gm2-libs-ch/README
+++ b/gcc/m2/gm2-libs-ch/README
@@ -1,3 +1,3 @@
-This directory contains a small number of C files which provide an interface
-between the host operating system and the Modula-2 library source found in
-gm2-libs and gm2-libs-iso.
\ No newline at end of file
+This directory contains a small number of C files which provide an
+interface between the host operating system and the Modula-2 library
+source found in gm2-libs and gm2-libs-iso.
\ No newline at end of file
diff --git a/gcc/m2/gm2-libs-ch/RTcodummy.c b/gcc/m2/gm2-libs-ch/RTcodummy.c
index 57f71f0c552..63738c403ab 100644
--- a/gcc/m2/gm2-libs-ch/RTcodummy.c
+++ b/gcc/m2/gm2-libs-ch/RTcodummy.c
@@ -24,6 +24,10 @@ a copy of the GCC Runtime Library Exception along with this program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 
 void
 RTco_wait (__attribute__ ((unused)) int sid)
@@ -96,6 +100,7 @@ RTco_select (__attribute__ ((unused)) int p1,
 	     __attribute__ ((unused)) void *p4,
 	     __attribute__ ((unused)) void *p5)
 {
+  return 0;
 }
 
 
@@ -126,3 +131,8 @@ _M2_RTco_finish (void)
 {
 }
 #endif
+
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/m2/gm2-libs-ch/RTintdummy.c b/gcc/m2/gm2-libs-ch/RTintdummy.c
index 67c3e0c8ef1..6e718cb7302 100644
--- a/gcc/m2/gm2-libs-ch/RTintdummy.c
+++ b/gcc/m2/gm2-libs-ch/RTintdummy.c
@@ -24,6 +24,9 @@ a copy of the GCC Runtime Library Exception along with this program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 void
 RTint_Init (void)
@@ -41,3 +44,7 @@ _M2_RTint_finish (void)
 {
 }
 #endif
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/m2/gm2-libs-ch/Selective.c b/gcc/m2/gm2-libs-ch/Selective.c
index b66c760c407..6ed0009dedc 100644
--- a/gcc/m2/gm2-libs-ch/Selective.c
+++ b/gcc/m2/gm2-libs-ch/Selective.c
@@ -30,6 +30,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #include "gm2-libs-host.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #if defined(HAVE_SELECT)
 # define FDSET_T fd_set
 #else
@@ -227,5 +231,16 @@ char Selective_ReadCharRaw (int fd)
 }
 
 
-void _M2_Selective_init () {}
-void _M2_Selective_finish () {}
+void
+_M2_Selective_init ()
+{
+}
+
+void
+_M2_Selective_finish ()
+{
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/m2/gm2-libs-ch/SysExceptions.c b/gcc/m2/gm2-libs-ch/SysExceptions.c
index 3cee14265be..b21f129a29e 100644
--- a/gcc/m2/gm2-libs-ch/SysExceptions.c
+++ b/gcc/m2/gm2-libs-ch/SysExceptions.c
@@ -33,6 +33,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include <signal.h>
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #if 0
 /* Signals.  */
 #define SIGHUP 1       /* Hangup (POSIX).  */
@@ -225,18 +229,15 @@ SysExceptions_InitExceptionHandlers (void *indexf, void *range, void *casef,
 
 /* GNU Modula-2 linking fodder.  */
 
-#ifdef __cplusplus
-extern "C"
-#endif
-    void
-    _M2_SysExceptions_init (void)
+void
+_M2_SysExceptions_init (void)
 {
 }
 
-#ifdef __cplusplus
-extern "C"
-#endif
-    void
-    _M2_SysExceptions_finish (void)
+void
+_M2_SysExceptions_finish (void)
 {
 }
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/m2/gm2-libs-ch/UnixArgs.c b/gcc/m2/gm2-libs-ch/UnixArgs.c
index 22bc51437a6..137df05a252 100644
--- a/gcc/m2/gm2-libs-ch/UnixArgs.c
+++ b/gcc/m2/gm2-libs-ch/UnixArgs.c
@@ -24,6 +24,10 @@ a copy of the GCC Runtime Library Exception along with this program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 int UnixArgs_ArgC;
 char **UnixArgs_ArgV;
 
@@ -38,3 +42,7 @@ void
 _M2_UnixArgs_finish (int argc, char *argv[])
 {
 }
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/m2/gm2-libs-ch/cgetopt.c b/gcc/m2/gm2-libs-ch/cgetopt.c
index 681bd4f9f3e..b59d666706b 100644
--- a/gcc/m2/gm2-libs-ch/cgetopt.c
+++ b/gcc/m2/gm2-libs-ch/cgetopt.c
@@ -28,6 +28,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "system.h"
 #include "ansi-decl.h"
 
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
 char *cgetopt_optarg;
 int cgetopt_optind;
 int cgetopt_opterr;
@@ -151,3 +157,7 @@ void
 _M2_cgetopt_finish (void)
 {
 }
+
+#   ifdef __cplusplus
+}
+#   endif
diff --git a/gcc/m2/gm2-libs-ch/choosetemp.c b/gcc/m2/gm2-libs-ch/choosetemp.c
index 15c4987bd92..24b2582e68e 100644
--- a/gcc/m2/gm2-libs-ch/choosetemp.c
+++ b/gcc/m2/gm2-libs-ch/choosetemp.c
@@ -29,6 +29,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "libiberty.h"
 #include "Gchoosetemp.h"
 
+#   ifdef __cplusplus
+extern "C" {
+#   endif
+
 /* Return a temporary file name (as a string) or NIL if unable to
 create one.  */
 
@@ -49,3 +53,6 @@ void
 _M2_choosetemp_finish (void)
 {
 }
+#   ifdef __cplusplus
+}
+#   endif
diff --git a/gcc/m2/gm2-libs-ch/dtoa.c b/gcc/m2/gm2-libs-ch/dtoa.c
index 17d25a9a2e6..193aed9a42c 100644
--- a/gcc/m2/gm2-libs-ch/dtoa.c
+++ b/gcc/m2/gm2-libs-ch/dtoa.c
@@ -30,6 +30,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #include "gm2-libs-host.h"
 
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define MAX_FP_DIGITS 500
 
 typedef enum Mode { maxsignicant, decimaldigits } Mode;
@@ -146,14 +151,14 @@ dtoa_dtoa (double d, int mode, int ndigits, int *decpt, int *sign)
 
     case maxsignicant:
       ndigits += 20; /* enough for exponent.  */
-      p = malloc (ndigits);
+      p = (char *) malloc (ndigits);
       snprintf (format, 50, "%s%d%s", "%.", ndigits - 20, "E");
       snprintf (p, ndigits, format, d);
       *sign = dtoa_calcsign (p, ndigits);
       *decpt = dtoa_calcmaxsig (p, ndigits);
       return p;
     case decimaldigits:
-      p = malloc (MAX_FP_DIGITS + 20);
+      p = (char *) malloc (MAX_FP_DIGITS + 20);
       snprintf (format, 50, "%s%d%s", "%.", MAX_FP_DIGITS, "E");
       snprintf (p, MAX_FP_DIGITS + 20, format, d);
       *sign = dtoa_calcsign (p, MAX_FP_DIGITS + 20);
@@ -170,7 +175,11 @@ void
 _M2_dtoa_init (void)
 {
 }
+
 void
 _M2_dtoa_finish (void)
 {
 }
+#   ifdef __cplusplus
+}
+#   endif
diff --git a/gcc/m2/gm2-libs-ch/errno.c b/gcc/m2/gm2-libs-ch/errno.c
index 18e993d6668..fb8002e5111 100644
--- a/gcc/m2/gm2-libs-ch/errno.c
+++ b/gcc/m2/gm2-libs-ch/errno.c
@@ -30,6 +30,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #include "gm2-libs-host.h"
 
+#   ifdef __cplusplus
+extern "C" {
+#   endif
+
 int
 errno_geterrno (void)
 {
@@ -49,3 +53,7 @@ void
 _M2_errno_finish (void)
 {
 }
+
+#   ifdef __cplusplus
+}
+#   endif
diff --git a/gcc/m2/gm2-libs-ch/host.c b/gcc/m2/gm2-libs-ch/host.c
index 357785299c1..9d691d8e478 100644
--- a/gcc/m2/gm2-libs-ch/host.c
+++ b/gcc/m2/gm2-libs-ch/host.c
@@ -31,6 +31,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #include "gm2-libs-host.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #if !defined(HAVE_EXP10)
 double
 exp10 (double x)
@@ -54,3 +58,7 @@ exp10l (long double x)
   return expl (x * M_LN10);
 }
 #endif
+
+#   ifdef __cplusplus
+}
+#   endif
diff --git a/gcc/m2/gm2-libs-ch/ldtoa.c b/gcc/m2/gm2-libs-ch/ldtoa.c
index 10b312784f9..6209f1bc260 100644
--- a/gcc/m2/gm2-libs-ch/ldtoa.c
+++ b/gcc/m2/gm2-libs-ch/ldtoa.c
@@ -30,6 +30,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #include "gm2-libs-host.h"
 
+#   ifdef __cplusplus
+extern "C" {
+#   endif
 
 #define MAX_FP_DIGITS 500
 
@@ -76,14 +79,14 @@ ldtoa_ldtoa (long double d, int mode, int ndigits, int *decpt, int *sign)
 
     case maxsignicant:
       ndigits += 20; /* enough for exponent.  */
-      p = malloc (ndigits);
+      p = (char *) malloc (ndigits);
       snprintf (format, 50, "%s%d%s", "%.", ndigits - 20, "LE");
       snprintf (p, ndigits, format, d);
       *sign = dtoa_calcsign (p, ndigits);
       *decpt = dtoa_calcmaxsig (p, ndigits);
       return p;
     case decimaldigits:
-      p = malloc (MAX_FP_DIGITS + 20);
+      p = (char *) malloc (MAX_FP_DIGITS + 20);
       snprintf (format, 50, "%s%d%s", "%.", MAX_FP_DIGITS, "LE");
       snprintf (p, MAX_FP_DIGITS + 20, format, d);
       *sign = dtoa_calcsign (p, MAX_FP_DIGITS + 20);
@@ -100,7 +103,12 @@ void
 _M2_ldtoa_init (void)
 {
 }
+
 void
 _M2_ldtoa_finish (void)
 {
 }
+
+#   ifdef __cplusplus
+}
+#   endif
diff --git a/gcc/m2/gm2-libs-ch/termios.c b/gcc/m2/gm2-libs-ch/termios.c
index 4559c8a95bd..73d9e11a9b4 100644
--- a/gcc/m2/gm2-libs-ch/termios.c
+++ b/gcc/m2/gm2-libs-ch/termios.c
@@ -40,6 +40,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #define EXPORT(X) termios##_##X
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef enum {
   vintr,
   vquit,
@@ -1926,3 +1930,7 @@ void
 _M2_termios_finish (void)
 {
 }
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/m2/gm2-libs-ch/tools.c b/gcc/m2/gm2-libs-ch/tools.c
index 5f00b3c47ae..da9fad47141 100644
--- a/gcc/m2/gm2-libs-ch/tools.c
+++ b/gcc/m2/gm2-libs-ch/tools.c
@@ -28,7 +28,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "system.h"
 #include "ansidecl.h"
 
-void fancy_abort(char const*, int, char const*)
+void
+fancy_abort (char const*, int, char const*)
 {
   fprintf (stderr, "fancy_abort called\n");
   exit (1);
diff --git a/gcc/m2/gm2-libs-ch/wrapc.c b/gcc/m2/gm2-libs-ch/wrapc.c
index 3efe1e48b9f..37d327fc7d2 100644
--- a/gcc/m2/gm2-libs-ch/wrapc.c
+++ b/gcc/m2/gm2-libs-ch/wrapc.c
@@ -31,6 +31,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #include "gm2-libs-host.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 /* strtime - returns the address of a string which describes the
 local time.  */
@@ -39,7 +42,7 @@ char *
 wrapc_strtime (void)
 {
 #if defined(HAVE_CTIME)
-  time_t clock = time ((void *)0);
+  time_t clock = time ((time_t *)0);
   char *string = ctime (&clock);
 
   string[24] = (char)0;
@@ -228,7 +231,12 @@ void
 _M2_wrapc_init ()
 {
 }
+
 void
 _M2_wrapc_finish ()
 {
 }
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/m2/gm2-libs-ch/xlibc.c b/gcc/m2/gm2-libs-ch/xlibc.c
index bf1f26f6fea..5d6c7482aef 100644
--- a/gcc/m2/gm2-libs-ch/xlibc.c
+++ b/gcc/m2/gm2-libs-ch/xlibc.c
@@ -28,6 +28,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "system.h"
 #include "ansidecl.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 char *
 xstrdup (char *src)
 {
@@ -38,3 +42,7 @@ xstrdup (char *src)
   strcpy (dst, src);
   return dst;
 }
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/m2/mc-boot-ch/GBuiltins.c b/gcc/m2/mc-boot-ch/GBuiltins.c
index a74737a5ce2..826fa1003e9 100644
--- a/gcc/m2/mc-boot-ch/GBuiltins.c
+++ b/gcc/m2/mc-boot-ch/GBuiltins.c
@@ -19,8 +19,16 @@ You should have received a copy of the GNU General Public License
 along with GNU Modula-2; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+#else
+#define EXTERN
+#endif
+
+
 /* init module constructor.  */
 
+EXTERN
 void
 _M2_Builtins_init (void)
 {
@@ -28,6 +36,7 @@ _M2_Builtins_init (void)
 
 /* finish module deconstructor.  */
 
+EXTERN
 void
 _M2_Builtins_finish (void)
 {
diff --git a/gcc/m2/mc-boot-ch/GRTco.c b/gcc/m2/mc-boot-ch/GRTco.c
index 96a19ca44ad..f960885d359 100644
--- a/gcc/m2/mc-boot-ch/GRTco.c
+++ b/gcc/m2/mc-boot-ch/GRTco.c
@@ -24,19 +24,27 @@ a copy of the GCC Runtime Library Exception along with this program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+#else
+#define EXTERN
+#endif
 
+EXTERN
 void
 RTco_wait (__attribute__ ((unused)) int sid)
 {
 }
 
 
+EXTERN
 void
 RTco_signal (__attribute__ ((unused)) int sid)
 {
 }
 
 
+EXTERN
 int
 RTco_init (void)
 {
@@ -44,6 +52,7 @@ RTco_init (void)
 }
 
 
+EXTERN
 int
 RTco_initSemaphore (__attribute__ ((unused)) int value)
 {
@@ -53,6 +62,7 @@ RTco_initSemaphore (__attribute__ ((unused)) int value)
 
 /* signalThread signal the semaphore associated with thread tid.  */
 
+EXTERN
 void
 RTco_signalThread (__attribute__ ((unused)) int tid)
 {
@@ -61,12 +71,14 @@ RTco_signalThread (__attribute__ ((unused)) int tid)
 
 /* waitThread wait on the semaphore associated with thread tid.  */
 
+EXTERN
 void
 RTco_waitThread (__attribute__ ((unused)) int tid)
 {
 }
 
 
+EXTERN
 int
 RTco_currentThread (void)
 {
@@ -74,6 +86,7 @@ RTco_currentThread (void)
 }
 
 
+EXTERN
 int
 RTco_initThread (__attribute__ ((unused)) void (*proc)(void),
 		 __attribute__ ((unused)) unsigned int stackSize)
@@ -82,12 +95,14 @@ RTco_initThread (__attribute__ ((unused)) void (*proc)(void),
 }
 
 
+EXTERN
 void
 RTco_transfer (__attribute__ ((unused)) int *p1, __attribute__ ((unused)) int p2)
 {
 }
 
 
+EXTERN
 int
 RTco_select (__attribute__ ((unused)) int p1,
 	     __attribute__ ((unused)) void *p2,
@@ -98,11 +113,13 @@ RTco_select (__attribute__ ((unused)) int p1,
 }
 
 
+EXTERN
 void
 _M2_RTco_init (void)
 {
 }
 
+EXTERN
 void
 _M2_RTco_finish (void)
 {
diff --git a/gcc/m2/mc-boot-ch/GSYSTEM.c b/gcc/m2/mc-boot-ch/GSYSTEM.c
index 4f6a7fbc3e2..a2855ac605c 100644
--- a/gcc/m2/mc-boot-ch/GSYSTEM.c
+++ b/gcc/m2/mc-boot-ch/GSYSTEM.c
@@ -19,11 +19,19 @@ You should have received a copy of the GNU General Public License
 along with GNU Modula-2; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+#else
+#define EXTERN
+#endif
+
+EXTERN
 void
 _M2_SYSTEM_init (int argc, char *p)
 {
 }
 
+EXTERN
 void
 _M2_SYSTEM_finish (int argc, char *p)
 {
diff --git a/gcc/m2/mc-boot-ch/GSelective.c b/gcc/m2/mc-boot-ch/GSelective.c
index 1f34952090f..17be47c129d 100644
--- a/gcc/m2/mc-boot-ch/GSelective.c
+++ b/gcc/m2/mc-boot-ch/GSelective.c
@@ -27,10 +27,17 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 
 #include "gm2-libs-host.h"
 
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+#else
+#define EXTERN
+#endif
+
 /* PROCEDURE Select (nooffds: CARDINAL; readfds, writefds, exceptfds:
 SetOfFd; timeout: Timeval) : INTEGER ; */
 
 #if defined(HAVE_SELECT)
+EXTERN
 int
 Selective_Select (int nooffds, fd_set *readfds, fd_set *writefds,
                   fd_set *exceptfds, struct timeval *timeout)
@@ -38,6 +45,7 @@ Selective_Select (int nooffds, fd_set *readfds, fd_set *writefds,
   return select (nooffds, readfds, writefds, exceptfds, timeout);
 }
 #else
+EXTERN
 int
 Selective_Select (int nooffds, void *readfds, void *writefds, void *exceptfds,
                   void *timeout)
@@ -49,6 +57,7 @@ Selective_Select (int nooffds, void *readfds, void *writefds, void *exceptfds,
 /* PROCEDURE InitTime (sec, usec) : Timeval ; */
 
 #if defined(HAVE_SELECT)
+EXTERN
 struct timeval *
 Selective_InitTime (unsigned int sec, unsigned int usec)
 {
@@ -59,6 +68,7 @@ Selective_InitTime (unsigned int sec, unsigned int usec)
   return t;
 }
 
+EXTERN
 void
 Selective_GetTime (struct timeval *t, unsigned int *sec, unsigned int *usec)
 {
@@ -66,6 +76,7 @@ Selective_GetTime (struct timeval *t, unsigned int *sec, unsigned int *usec)
   *usec = (unsigned int)t->tv_usec;
 }
 
+EXTERN
 void
 Selective_SetTime (struct timeval *t, unsigned int sec, unsigned int usec)
 {
@@ -75,6 +86,7 @@ Selective_SetTime (struct timeval *t, unsigned int sec, unsigned int usec)
 
 /* PROCEDURE KillTime (t: Timeval) : Timeval ; */
 
+EXTERN
 struct timeval *
 Selective_KillTime (struct timeval *t)
 {
@@ -84,6 +96,7 @@ Selective_KillTime (struct timeval *t)
 
 /* PROCEDURE InitSet () : SetOfFd ; */
 
+EXTERN
 fd_set *
 Selective_InitSet (void)
 {
@@ -94,6 +107,7 @@ Selective_InitSet (void)
 
 /* PROCEDURE KillSet (s: SetOfFd) : SetOfFd ; */
 
+EXTERN
 fd_set *
 Selective_KillSet (fd_set *s)
 {
@@ -103,6 +117,7 @@ Selective_KillSet (fd_set *s)
 
 /* PROCEDURE FdZero (s: SetOfFd) ; */
 
+EXTERN
 void
 Selective_FdZero (fd_set *s)
 {
@@ -111,6 +126,7 @@ Selective_FdZero (fd_set *s)
 
 /* PROCEDURE Fd_Set (fd: INTEGER; SetOfFd) ; */
 
+EXTERN
 void
 Selective_FdSet (int fd, fd_set *s)
 {
@@ -119,6 +135,7 @@ Selective_FdSet (int fd, fd_set *s)
 
 /* PROCEDURE FdClr (fd: INTEGER; SetOfFd) ; */
 
+EXTERN
 void
 Selective_FdClr (int fd, fd_set *s)
 {
@@ -127,6 +144,7 @@ Selective_FdClr (int fd, fd_set *s)
 
 /* PROCEDURE FdIsSet (fd: INTEGER; SetOfFd) : BOOLEAN ; */
 
+EXTERN
 int
 Selective_FdIsSet (int fd, fd_set *s)
 {
@@ -137,6 +155,7 @@ Selective_FdIsSet (int fd, fd_set *s)
 current system time in seconds and microseconds.  It returns zero
 (see man 3p gettimeofday) */
 
+EXTERN
 int
 Selective_GetTimeOfDay (struct timeval *t)
 {
@@ -144,55 +163,65 @@ Selective_GetTimeOfDay (struct timeval *t)
 }
 #else
 
+EXTERN
 void *
 Selective_InitTime (unsigned int sec, unsigned int usec)
 {
   return NULL;
 }
 
+EXTERN
 void *
 Selective_KillTime (void *t)
 {
   return NULL;
 }
 
+EXTERN
 void
 Selective_GetTime (struct timeval *t, unsigned int *sec, unsigned int *usec)
 {
 }
 
+EXTERN
 void
 Selective_SetTime (struct timeval *t, unsigned int sec, unsigned int usec)
 {
 }
 
+EXTERN
 fd_set *
 Selective_InitSet (void)
 {
   return NULL;
 }
 
+EXTERN
 void
 Selective_FdZero (void *s)
 {
 }
 
+EXTERN
 void
 Selective_FdSet (int fd, void *s)
 {
 }
 
+EXTERN
 void
 Selective_FdClr (int fd, void *s)
 {
 }
 
+EXTERN
 int
 Selective_FdIsSet (int fd, void *s)
 {
   return 0;
 }
 
+EXTERN
 int
 Selective_GetTimeOfDay (struct timeval *t)
 {
@@ -202,6 +231,7 @@ Selective_GetTimeOfDay (struct timeval *t)
 
 /* PROCEDURE MaxFdsPlusOne (a, b: File) : File ; */
 
+EXTERN
 int
 Selective_MaxFdsPlusOne (int a, int b)
 {
@@ -213,6 +243,7 @@ Selective_MaxFdsPlusOne (int a, int b)
 
 /* PROCEDURE WriteCharRaw (fd: INTEGER; ch: CHAR) ; */
 
+EXTERN
 void
 Selective_WriteCharRaw (int fd, char ch)
 {
@@ -221,6 +252,7 @@ Selective_WriteCharRaw (int fd, char ch)
 
 /* PROCEDURE ReadCharRaw (fd: INTEGER) : CHAR ; */
 
+EXTERN
 char
 Selective_ReadCharRaw (int fd)
 {
@@ -230,11 +262,13 @@ Selective_ReadCharRaw (int fd)
   return ch;
 }
 
+EXTERN
 void
 _M2_Selective_init ()
 {
 }
 
+EXTERN
 void
 _M2_Selective_finish ()
 {
diff --git a/gcc/m2/mc-boot-ch/GSysExceptions.c b/gcc/m2/mc-boot-ch/GSysExceptions.c
index 302f44a1556..c7c285c2d27 100644
--- a/gcc/m2/mc-boot-ch/GSysExceptions.c
+++ b/gcc/m2/mc-boot-ch/GSysExceptions.c
@@ -24,6 +24,12 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 
 #include "gm2-libs-host.h"
 
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+#else
+#define EXTERN
+#endif
+
 #if 0
 /* Signals.  */
 #define SIGHUP 1       /* Hangup (POSIX).  */
@@ -151,6 +157,7 @@ sigfpeDespatcher (int signum, siginfo_t *info, void *ucontext)
     }
 }
 
+EXTERN
 void
 SysExceptions_InitExceptionHandlers (
     void (*indexf) (void *), void (*range) (void *), void (*casef) (void *),
@@ -202,6 +209,7 @@ SysExceptions_InitExceptionHandlers (
 }
 
 #else
+EXTERN
 void
 SysExceptions_InitExceptionHandlers (void *indexf, void *range, void *casef,
                                      void *invalidloc, void *function,
@@ -216,11 +224,13 @@ SysExceptions_InitExceptionHandlers (void *indexf, void *range, void *casef,
 
 /* GNU Modula-2 linking fodder.  */
 
+EXTERN
 void
 _M2_SysExceptions_init (void)
 {
 }
 
+EXTERN
 void
 _M2_SysExceptions_finish (void)
 {
diff --git a/gcc/m2/mc-boot-ch/GUnixArgs.c b/gcc/m2/mc-boot-ch/GUnixArgs.c
index 5304900ec23..1f1304c8841 100644
--- a/gcc/m2/mc-boot-ch/GUnixArgs.c
+++ b/gcc/m2/mc-boot-ch/GUnixArgs.c
@@ -19,7 +19,12 @@ You should have received a copy of the GNU General Public License
 along with GNU Modula-2; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
 int UnixArgs_ArgC;
+
 char **UnixArgs_ArgV;
 
 void
@@ -33,3 +38,7 @@ void
 _M2_UnixArgs_finish (int argc, char *argv[])
 {
 }
+
+#if defined(__cplusplus)
+}
+#endif
diff --git a/gcc/m2/mc-boot-ch/Gabort.c b/gcc/m2/mc-boot-ch/Gabort.c
new file mode 100644
index 00000000000..5ebd94de3ac
--- /dev/null
+++ b/gcc/m2/mc-boot-ch/Gabort.c
@@ -0,0 +1,30 @@
+/* Gabort.c a GCC style abort function.
+
+Copyright (C) 2022 Free Software Foundation, Inc.
+Contributed by Gaius Mulley <gaius@glam.ac.uk>.
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GNU Modula-2 is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Modula-2; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include "system.h"
+
+void
+fancy_abort (const char *filename, int line, const char *func)
+{
+  fprintf (stderr, "%s:%d%s: aborting\n", filename, line, func);
+  exit (1);
+}
diff --git a/gcc/m2/mc-boot-ch/Gdtoa.c b/gcc/m2/mc-boot-ch/Gdtoa.c
index 0e3b4336d66..07ef6be7013 100644
--- a/gcc/m2/mc-boot-ch/Gdtoa.c
+++ b/gcc/m2/mc-boot-ch/Gdtoa.c
@@ -24,6 +24,11 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define MAX_FP_DIGITS 500
 
 typedef enum Mode { maxsignicant, decimaldigits } Mode;
@@ -117,6 +122,7 @@ dtoa_calcdecimal (char *p, int str_size, int ndigits)
   return x;
 }
 
+
 int
 dtoa_calcsign (char *p, int str_size)
 {
@@ -129,6 +135,7 @@ dtoa_calcsign (char *p, int str_size)
     return FALSE;
 }
 
+
 char *
 dtoa_dtoa (double d, int mode, int ndigits, int *decpt, int *sign)
 {
@@ -140,14 +147,14 @@ dtoa_dtoa (double d, int mode, int ndigits, int *decpt, int *sign)
 
     case maxsignicant:
       ndigits += 20; /* enough for exponent.  */
-      p = malloc (ndigits);
+      p = (char *) malloc (ndigits);
       snprintf (format, 50, "%s%d%s", "%.", ndigits - 20, "E");
       snprintf (p, ndigits, format, d);
       *sign = dtoa_calcsign (p, ndigits);
       *decpt = dtoa_calcmaxsig (p, ndigits);
       return p;
     case decimaldigits:
-      p = malloc (MAX_FP_DIGITS + 20);
+      p = (char *) malloc (MAX_FP_DIGITS + 20);
       snprintf (format, 50, "%s%d%s", "%.", MAX_FP_DIGITS, "E");
       snprintf (p, MAX_FP_DIGITS + 20, format, d);
       *sign = dtoa_calcsign (p, MAX_FP_DIGITS + 20);
@@ -165,8 +172,13 @@ void
 _M2_dtoa_init (void)
 {
 }
+
 void
 _M2_dtoa_finish (void)
 {
 }
 #endif
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/m2/mc-boot-ch/Gerrno.c b/gcc/m2/mc-boot-ch/Gerrno.c
index 99bdb8ec4cd..36e577704c5 100644
--- a/gcc/m2/mc-boot-ch/Gerrno.c
+++ b/gcc/m2/mc-boot-ch/Gerrno.c
@@ -23,6 +23,10 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 #include "system.h"
 #include "ansidecl.h"
 
+#   ifdef __cplusplus
+extern "C" {
+#   endif
+
 /* geterrno returns errno.  */
 
 int
@@ -44,3 +48,7 @@ void
 _M2_errno_finish (int argc, char *p)
 {
 }
+
+#   ifdef __cplusplus
+}
+#   endif
diff --git a/gcc/m2/mc-boot-ch/Gldtoa.c b/gcc/m2/mc-boot-ch/Gldtoa.c
index ce61308bbbf..84e6954af3f 100644
--- a/gcc/m2/mc-boot-ch/Gldtoa.c
+++ b/gcc/m2/mc-boot-ch/Gldtoa.c
@@ -24,6 +24,10 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 
 #include "gm2-libs-host.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define MAX_FP_DIGITS 500
 
 typedef enum Mode { maxsignicant, decimaldigits } Mode;
@@ -69,14 +73,14 @@ ldtoa_ldtoa (long double d, int mode, int ndigits, int *decpt, int *sign)
 
     case maxsignicant:
       ndigits += 20; /* enough for exponent.  */
-      p = malloc (ndigits);
+      p = (char *)malloc (ndigits);
       snprintf (format, 50, "%s%d%s", "%.", ndigits - 20, "LE");
       snprintf (p, ndigits, format, d);
       *sign = dtoa_calcsign (p, ndigits);
       *decpt = dtoa_calcmaxsig (p, ndigits);
       return p;
     case decimaldigits:
-      p = malloc (MAX_FP_DIGITS + 20);
+      p = (char *)malloc (MAX_FP_DIGITS + 20);
       snprintf (format, 50, "%s%d%s", "%.", MAX_FP_DIGITS, "LE");
       snprintf (p, MAX_FP_DIGITS + 20, format, d);
       *sign = dtoa_calcsign (p, MAX_FP_DIGITS + 20);
@@ -93,7 +97,11 @@ void
 _M2_ldtoa_init (void)
 {
 }
+
 void
 _M2_ldtoa_finish (void)
 {
 }
+#   ifdef __cplusplus
+}
+#   endif
diff --git a/gcc/m2/mc-boot-ch/Glibc.c b/gcc/m2/mc-boot-ch/Glibc.c
index b3530a6b175..c9b663d5d79 100644
--- a/gcc/m2/mc-boot-ch/Glibc.c
+++ b/gcc/m2/mc-boot-ch/Glibc.c
@@ -22,48 +22,62 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+#else
+#define EXTERN
+#endif
+
+EXTERN
 int
 libc_read (int fd, void *a, int nbytes)
 {
   return read (fd, a, nbytes);
 }
 
+EXTERN
 int
 libc_write (int fd, void *a, int nbytes)
 {
   return write (fd, a, nbytes);
 }
 
+EXTERN
 int
 libc_close (int fd)
 {
   return close (fd);
 }
 
+EXTERN
 int
 libc_exit (int code)
 {
   exit (code);
 }
 
-int
+EXTERN
+void
 libc_perror (char *s)
 {
   perror (s);
 }
 
+EXTERN
 int
 libc_abort ()
 {
   abort ();
 }
 
+EXTERN
 int
 libc_strlen (char *s)
 {
   return strlen (s);
 }
 
+EXTERN
 int
 libc_printf (char *_format, unsigned int _format_high, ...)
 {
@@ -101,102 +115,119 @@ libc_printf (char *_format, unsigned int _format_high, ...)
   return done;
 }
 
+EXTERN
 void *
 libc_malloc (unsigned int size)
 {
   return malloc (size);
 }
 
+EXTERN
 void
 libc_free (void *p)
 {
   free (p);
 }
 
+EXTERN
 char *
 libc_strcpy (char *dest, char *src)
 {
   return strcpy (dest, src);
 }
 
+EXTERN
 char *
 libc_strncpy (char *dest, char *src, int n)
 {
   return strncpy (dest, src, n);
 }
 
+EXTERN
 int
 libc_unlink (char *p)
 {
   return unlink (p);
 }
 
+EXTERN
 int
 libc_system (char *command)
 {
   return system (command);
 }
 
+EXTERN
 void *
 libc_memcpy (void *dest, void *src, int n)
 {
   return memcpy (dest, src, n);
 }
 
+EXTERN
 char *
 libc_getenv (char *name)
 {
   return getenv (name);
 }
 
+EXTERN
 int
 libc_creat (char *p, mode_t mode)
 {
   return creat (p, mode);
 }
 
+EXTERN
 int
 libc_open (char *p, int flags, mode_t mode)
 {
   return open (p, flags, mode);
 }
 
+EXTERN
 off_t
 libc_lseek (int fd, off_t offset, int whence)
 {
   return lseek (fd, offset, whence);
 }
 
+EXTERN
 void *
 libc_realloc (void *ptr, size_t size)
 {
   return realloc (ptr, size);
 }
 
+EXTERN
 void *
 libc_memset (void *s, int c, size_t n)
 {
   return memset (s, c, n);
 }
 
+EXTERN
 void *
 libc_memmove (void *dest, void *src, size_t n)
 {
   return memmove (dest, src, n);
 }
 
+EXTERN
 int
 libc_getpid (void)
 {
   return getpid ();
 }
 
+EXTERN
 unsigned int
 libc_sleep (unsigned int s)
 {
   return sleep (s);
 }
 
+EXTERN
 int
 libc_atexit (void (*function) (void))
 {
diff --git a/gcc/m2/mc-boot-ch/Gmcrts.c b/gcc/m2/mc-boot-ch/Gmcrts.c
index 6bd64bb6289..c965e596bfc 100644
--- a/gcc/m2/mc-boot-ch/Gmcrts.c
+++ b/gcc/m2/mc-boot-ch/Gmcrts.c
@@ -22,12 +22,9 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 
-void
-fancy_abort (const char *filename, int line, const char *func)
-{
-  fprintf (stderr, "%s:%d%s: aborting\n", filename, line, func);
-  exit (1);
-}
+#   ifdef __cplusplus
+extern "C" {
+#   endif
 
 void
 CaseException (const char *s, unsigned int high, unsigned int lineno)
@@ -46,8 +43,12 @@ ReturnException (const char *s, unsigned int high, unsigned int lineno)
   _exit (1);
 }
 
-void throw (int n)
+void _throw (int n)
 {
   fprintf (stderr, "throw called (%d)\n", n);
   _exit (1);
 }
+
+#   ifdef __cplusplus
+}
+#   endif
diff --git a/gcc/m2/mc-boot-ch/Gtermios.c b/gcc/m2/mc-boot-ch/Gtermios.c
index fd36e25457a..82975b3e98f 100644
--- a/gcc/m2/mc-boot-ch/Gtermios.c
+++ b/gcc/m2/mc-boot-ch/Gtermios.c
@@ -32,6 +32,11 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 #define _XOPEN_SOURCE
 #endif
 
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+#else
+#define EXTERN
+#endif
 
 #define EXPORT(X) termios##_##X
 
@@ -160,38 +165,39 @@ typedef enum {
 } Flag;
 
 /* prototypes.  */
-void *EXPORT (InitTermios) (void);
-void *EXPORT (KillTermios) (struct termios *p);
-int EXPORT (cfgetospeed) (struct termios *t);
-int EXPORT (cfgetispeed) (struct termios *t);
-int EXPORT (cfsetospeed) (struct termios *t, unsigned int b);
-int EXPORT (cfsetispeed) (struct termios *t, unsigned int b);
-int EXPORT (cfsetspeed) (struct termios *t, unsigned int b);
-int EXPORT (tcgetattr) (int fd, struct termios *t);
-int EXPORT (tcsetattr) (int fd, int option, struct termios *t);
-void EXPORT (cfmakeraw) (struct termios *t);
-int EXPORT (tcsendbreak) (int fd, int duration);
-int EXPORT (tcdrain) (int fd);
-int EXPORT (tcflushi) (int fd);
-int EXPORT (tcflusho) (int fd);
-int EXPORT (tcflushio) (int fd);
-int EXPORT (tcflowoni) (int fd);
-int EXPORT (tcflowoffi) (int fd);
-int EXPORT (tcflowono) (int fd);
-int EXPORT (tcflowoffo) (int fd);
-int EXPORT (GetFlag) (struct termios *t, Flag f, int *b);
-int EXPORT (SetFlag) (struct termios *t, Flag f, int b);
-int EXPORT (GetChar) (struct termios *t, ControlChar c, char *ch);
-int EXPORT (SetChar) (struct termios *t, ControlChar c, char ch);
-int EXPORT (tcsnow) (void);
-int EXPORT (tcsflush) (void);
-int EXPORT (tcsdrain) (void);
-int doSetUnset (unsigned int *bitset, unsigned int mask, int value);
-void _M2_termios_init (void);
-void _M2_termios_finish (void);
+EXTERN void *EXPORT (InitTermios) (void);
+EXTERN void *EXPORT (KillTermios) (struct termios *p);
+EXTERN int EXPORT (cfgetospeed) (struct termios *t);
+EXTERN int EXPORT (cfgetispeed) (struct termios *t);
+EXTERN int EXPORT (cfsetospeed) (struct termios *t, unsigned int b);
+EXTERN int EXPORT (cfsetispeed) (struct termios *t, unsigned int b);
+EXTERN int EXPORT (cfsetspeed) (struct termios *t, unsigned int b);
+EXTERN int EXPORT (tcgetattr) (int fd, struct termios *t);
+EXTERN int EXPORT (tcsetattr) (int fd, int option, struct termios *t);
+EXTERN void EXPORT (cfmakeraw) (struct termios *t);
+EXTERN int EXPORT (tcsendbreak) (int fd, int duration);
+EXTERN int EXPORT (tcdrain) (int fd);
+EXTERN int EXPORT (tcflushi) (int fd);
+EXTERN int EXPORT (tcflusho) (int fd);
+EXTERN int EXPORT (tcflushio) (int fd);
+EXTERN int EXPORT (tcflowoni) (int fd);
+EXTERN int EXPORT (tcflowoffi) (int fd);
+EXTERN int EXPORT (tcflowono) (int fd);
+EXTERN int EXPORT (tcflowoffo) (int fd);
+EXTERN int EXPORT (GetFlag) (struct termios *t, Flag f, int *b);
+EXTERN int EXPORT (SetFlag) (struct termios *t, Flag f, int b);
+EXTERN int EXPORT (GetChar) (struct termios *t, ControlChar c, char *ch);
+EXTERN int EXPORT (SetChar) (struct termios *t, ControlChar c, char ch);
+EXTERN int EXPORT (tcsnow) (void);
+EXTERN int EXPORT (tcsflush) (void);
+EXTERN int EXPORT (tcsdrain) (void);
+EXTERN int doSetUnset (unsigned int *bitset, unsigned int mask, int value);
+EXTERN void _M2_termios_init (void);
+EXTERN void _M2_termios_finish (void);
 
 /* InitTermios - new data structure.  */
 
+EXTERN
 void *EXPORT (InitTermios) (void)
 {
   struct termios *p = (struct termios *)malloc (sizeof (struct termios));
@@ -202,6 +208,7 @@ void *EXPORT (InitTermios) (void)
 
 /* KillTermios - delete data structure.  */
 
+EXTERN
 void *EXPORT (KillTermios) (struct termios *p)
 {
   free (p);
@@ -210,26 +217,32 @@ void *EXPORT (KillTermios) (struct termios *p)
 
 /* tcsnow - return the value of TCSANOW.  */
 
+EXTERN
 int EXPORT (tcsnow) (void) { return TCSANOW; }
 
 /* tcsdrain - return the value of TCSADRAIN.  */
 
+EXTERN
 int EXPORT (tcsdrain) (void) { return TCSADRAIN; }
 
 /* tcsflush - return the value of TCSAFLUSH.  */
 
+EXTERN
 int EXPORT (tcsflush) (void) { return TCSAFLUSH; }
 
 /* cfgetospeed - return output baud rate.  */
 
+EXTERN
 int EXPORT (cfgetospeed) (struct termios *t) { return cfgetospeed (t); }
 
 /* cfgetispeed - return input baud rate.  */
 
+EXTERN
 int EXPORT (cfgetispeed) (struct termios *t) { return cfgetispeed (t); }
 
 /* cfsetospeed - set output baud rate.  */
 
+EXTERN
 int EXPORT (cfsetospeed) (struct termios *t, unsigned int b)
 {
   return cfsetospeed (t, b);
@@ -237,6 +250,7 @@ int EXPORT (cfsetospeed) (struct termios *t, unsigned int b)
 
 /* cfsetispeed - set input baud rate.  */
 
+EXTERN
 int EXPORT (cfsetispeed) (struct termios *t, unsigned int b)
 {
   return cfsetispeed (t, b);
@@ -244,6 +258,7 @@ int EXPORT (cfsetispeed) (struct termios *t, unsigned int b)
 
 /* cfsetspeed - set input and output baud rate.  */
 
+EXTERN
 int EXPORT (cfsetspeed) (struct termios *t, unsigned int b)
 {
   int val = cfsetispeed (t, b);
@@ -255,6 +270,7 @@ int EXPORT (cfsetspeed) (struct termios *t, unsigned int b)
 
 /* tcgetattr - get state of, fd, into, t.  */
 
+EXTERN
 int EXPORT (tcgetattr) (int fd, struct termios *t)
 {
   return tcgetattr (fd, t);
@@ -262,6 +278,7 @@ int EXPORT (tcgetattr) (int fd, struct termios *t)
 
 /* tcsetattr - set state of, fd, to, t, using option.  */
 
+EXTERN
 int EXPORT (tcsetattr) (int fd, int option, struct termios *t)
 {
   return tcsetattr (fd, option, t);
@@ -269,6 +286,7 @@ int EXPORT (tcsetattr) (int fd, int option, struct termios *t)
 
 /* cfmakeraw - sets the terminal to raw mode.  */
 
+EXTERN
 void EXPORT (cfmakeraw) (struct termios *t)
 {
 #if defined(HAVE_CFMAKERAW)
@@ -278,6 +296,7 @@ void EXPORT (cfmakeraw) (struct termios *t)
 
 /* tcsendbreak - send zero bits for duration.  */
 
+EXTERN
 int EXPORT (tcsendbreak) (int fd, int duration)
 {
   return tcsendbreak (fd, duration);
@@ -285,10 +304,12 @@ int EXPORT (tcsendbreak) (int fd, int duration)
 
 /* tcdrain - waits for pending output to be written on, fd.  */
 
+EXTERN
 int EXPORT (tcdrain) (int fd) { return tcdrain (fd); }
 
 /* tcflushi - flush input.  */
 
+EXTERN
 int EXPORT (tcflushi) (int fd)
 {
 #if defined(TCIFLUSH)
@@ -300,6 +321,7 @@ int EXPORT (tcflushi) (int fd)
 
 /* tcflusho - flush output.  */
 
+EXTERN
 int EXPORT (tcflusho) (int fd)
 {
 #if defined(TCOFLUSH)
@@ -311,6 +333,7 @@ int EXPORT (tcflusho) (int fd)
 
 /* tcflushio - flush input and output.  */
 
+EXTERN
 int EXPORT (tcflushio) (int fd)
 {
 #if defined(TCIOFLUSH)
@@ -322,6 +345,7 @@ int EXPORT (tcflushio) (int fd)
 
 /* tcflowoni - restart input on, fd.  */
 
+EXTERN
 int EXPORT (tcflowoni) (int fd)
 {
 #if defined(TCION)
@@ -333,6 +357,7 @@ int EXPORT (tcflowoni) (int fd)
 
 /* tcflowoffi - stop input on, fd.  */
 
+EXTERN
 int EXPORT (tcflowoffi) (int fd)
 {
 #if defined(TCIOFF)
@@ -344,6 +369,7 @@ int EXPORT (tcflowoffi) (int fd)
 
 /* tcflowono - restart output on, fd.  */
 
+EXTERN
 int EXPORT (tcflowono) (int fd)
 {
 #if defined(TCOON)
@@ -355,6 +381,7 @@ int EXPORT (tcflowono) (int fd)
 
 /* tcflowoffo - stop output on, fd.  */
 
+EXTERN
 int EXPORT (tcflowoffo) (int fd)
 {
 #if defined(TCOOFF)
@@ -366,6 +393,7 @@ int EXPORT (tcflowoffo) (int fd)
 
 /* doSetUnset - applies mask or undoes mask depending upon value.  */
 
+EXTERN
 int
 doSetUnset (unsigned int *bitset, unsigned int mask, int value)
 {
@@ -379,6 +407,7 @@ doSetUnset (unsigned int *bitset, unsigned int mask, int value)
 /* GetFlag - sets a flag value from, t, in, b, and returns TRUE if,
    t, supports, f.  */
 
+EXTERN
 int EXPORT (GetFlag) (struct termios *t, Flag f, int *b)
 {
   switch (f)
@@ -1063,6 +1092,7 @@ int EXPORT (GetFlag) (struct termios *t, Flag f, int *b)
 /* SetFlag - sets a flag value in, t, to, b, and returns TRUE if this
    flag value is supported.  */
 
+EXTERN
 int EXPORT (SetFlag) (struct termios *t, Flag f, int b)
 {
   switch (f)
@@ -1651,6 +1681,7 @@ int EXPORT (SetFlag) (struct termios *t, Flag f, int b)
 /* GetChar - sets a CHAR, ch, value from, t, and returns TRUE if this
    value is supported.  */
 
+EXTERN
 int EXPORT (GetChar) (struct termios *t, ControlChar c, char *ch)
 {
   switch (c)
@@ -1783,6 +1814,7 @@ int EXPORT (GetChar) (struct termios *t, ControlChar c, char *ch)
 /* SetChar - sets a CHAR value in, t, and returns TRUE if, c, is
    supported.  */
 
+EXTERN
 int EXPORT (SetChar) (struct termios *t, ControlChar c, char ch)
 {
   switch (c)
diff --git a/gcc/m2/mc-boot-ch/Gwrapc.c b/gcc/m2/mc-boot-ch/Gwrapc.c
index b83a52b05c2..d98a5e41102 100644
--- a/gcc/m2/mc-boot-ch/Gwrapc.c
+++ b/gcc/m2/mc-boot-ch/Gwrapc.c
@@ -25,7 +25,7 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 
 #include "gm2-libs-host.h"
 
-#ifdef cplusplus
+#ifdef __cplusplus
 extern "C" {
 #endif
 
@@ -36,7 +36,7 @@ char *
 wrapc_strtime (void)
 {
 #if defined(HAVE_CTIME)
-  time_t clock = time ((void *)0);
+  time_t clock = time ((time_t *)0);
   char *string = ctime (&clock);
 
   string[24] = (char)0;
@@ -178,6 +178,6 @@ _M2_wrapc_finish ()
 {
 }
 
-#ifdef cplusplus
+#ifdef __cplusplus
 }
 #endif
diff --git a/gcc/m2/mc-boot/GASCII.c b/gcc/m2/mc-boot/GASCII.c
index a0bf5818e6c..1983d81bd98 100644
--- a/gcc/m2/mc-boot/GASCII.c
+++ b/gcc/m2/mc-boot/GASCII.c
@@ -77,10 +77,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #   define ASCII_del (char) 0177
 #   define ASCII_EOL ASCII_nl
 
-void _M2_ASCII_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_ASCII_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_ASCII_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_ASCII_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GASCII.h b/gcc/m2/mc-boot/GASCII.h
index a2d08308666..f3c943cd0f9 100644
--- a/gcc/m2/mc-boot/GASCII.h
+++ b/gcc/m2/mc-boot/GASCII.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_ASCII_H)
 #   define _ASCII_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GArgs.c b/gcc/m2/mc-boot/GArgs.c
index e7f9e15b4b3..60c535dc7b0 100644
--- a/gcc/m2/mc-boot/GArgs.c
+++ b/gcc/m2/mc-boot/GArgs.c
@@ -41,27 +41,29 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #   define MaxArgs 255
 #   define MaxString 4096
-typedef struct _T1_a _T1;
-
 typedef struct _T2_a _T2;
 
-struct _T1_a { _T2 * array[MaxArgs+1]; };
-struct _T2_a { char array[MaxString+1]; };
-static _T1 * Source;
+typedef _T2 *_T1;
+
+typedef struct _T3_a _T3;
+
+struct _T2_a { _T3 * array[MaxArgs+1]; };
+struct _T3_a { char array[MaxString+1]; };
+static _T1 Source;
 
 /*
    GetArg - returns the nth argument from the command line.
             The success of the operation is returned.
 */
 
-unsigned int Args_GetArg (char *a, unsigned int _a_high, unsigned int i);
+extern "C" unsigned int Args_GetArg (char *a, unsigned int _a_high, unsigned int i);
 
 /*
    Narg - returns the number of arguments available from
           command line.
 */
 
-unsigned int Args_Narg (void);
+extern "C" unsigned int Args_Narg (void);
 
 
 /*
@@ -69,16 +71,16 @@ unsigned int Args_Narg (void);
             The success of the operation is returned.
 */
 
-unsigned int Args_GetArg (char *a, unsigned int _a_high, unsigned int i)
+extern "C" unsigned int Args_GetArg (char *a, unsigned int _a_high, unsigned int i)
 {
   unsigned int High;
   unsigned int j;
 
-  j = 0;
+  j = static_cast<unsigned int> (0);
   High = _a_high;
   if (i < UnixArgs_ArgC)
     {
-      Source = UnixArgs_ArgV;
+      Source = static_cast<_T1> (UnixArgs_ArgV);
       while (((*(*Source).array[i]).array[j] != ASCII_nul) && (j < High))
         {
           a[j] = (*(*Source).array[i]).array[j];
@@ -100,17 +102,17 @@ unsigned int Args_GetArg (char *a, unsigned int _a_high, unsigned int i)
           command line.
 */
 
-unsigned int Args_Narg (void)
+extern "C" unsigned int Args_Narg (void)
 {
   return UnixArgs_ArgC;
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
 
-void _M2_Args_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_Args_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_Args_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_Args_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GArgs.h b/gcc/m2/mc-boot/GArgs.h
index a33afaeb7eb..1a15de29dc0 100644
--- a/gcc/m2/mc-boot/GArgs.h
+++ b/gcc/m2/mc-boot/GArgs.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_Args_H)
 #   define _Args_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GAssertion.c b/gcc/m2/mc-boot/GAssertion.c
index a321ad1e35c..6aaa9695db5 100644
--- a/gcc/m2/mc-boot/GAssertion.c
+++ b/gcc/m2/mc-boot/GAssertion.c
@@ -44,28 +44,28 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    Assert - tests the boolean Condition, if it fails then HALT is called.
 */
 
-void Assertion_Assert (unsigned int Condition);
+extern "C" void Assertion_Assert (unsigned int Condition);
 
 
 /*
    Assert - tests the boolean Condition, if it fails then HALT is called.
 */
 
-void Assertion_Assert (unsigned int Condition)
+extern "C" void Assertion_Assert (unsigned int Condition)
 {
   if (! Condition)
     {
-      StrIO_WriteString ((char *) "assert failed - halting system", 30);
+      StrIO_WriteString ((const char *) "assert failed - halting system", 30);
       StrIO_WriteLn ();
       M2RTS_HALT (-1);
       __builtin_unreachable ();
     }
 }
 
-void _M2_Assertion_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_Assertion_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_Assertion_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_Assertion_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GAssertion.h b/gcc/m2/mc-boot/GAssertion.h
index 3a8628e9ff9..bd8c53c6ca0 100644
--- a/gcc/m2/mc-boot/GAssertion.h
+++ b/gcc/m2/mc-boot/GAssertion.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_Assertion_H)
 #   define _Assertion_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GBreak.c b/gcc/m2/mc-boot/GBreak.c
index bc56ceea15b..9b800b3b2e1 100644
--- a/gcc/m2/mc-boot/GBreak.c
+++ b/gcc/m2/mc-boot/GBreak.c
@@ -38,10 +38,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 
 
-void _M2_Break_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_Break_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_Break_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_Break_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GBreak.h b/gcc/m2/mc-boot/GBreak.h
index 33aca881690..47a210d1005 100644
--- a/gcc/m2/mc-boot/GBreak.h
+++ b/gcc/m2/mc-boot/GBreak.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_Break_H)
 #   define _Break_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GCOROUTINES.h b/gcc/m2/mc-boot/GCOROUTINES.h
index 18e6b62f0ed..e2953d61dc2 100644
--- a/gcc/m2/mc-boot/GCOROUTINES.h
+++ b/gcc/m2/mc-boot/GCOROUTINES.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_COROUTINES_H)
 #   define _COROUTINES_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GCmdArgs.c b/gcc/m2/mc-boot/GCmdArgs.c
index 1d7266ad8be..18d9c072553 100644
--- a/gcc/m2/mc-boot/GCmdArgs.c
+++ b/gcc/m2/mc-boot/GCmdArgs.c
@@ -51,14 +51,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
             The result of the operation is returned.
 */
 
-unsigned int CmdArgs_GetArg (char *CmdLine_, unsigned int _CmdLine_high, unsigned int n, char *Argi, unsigned int _Argi_high);
+extern "C" unsigned int CmdArgs_GetArg (const char *CmdLine_, unsigned int _CmdLine_high, unsigned int n, char *Argi, unsigned int _Argi_high);
 
 /*
    Narg - returns the number of arguments available from
           command line, CmdLine.
 */
 
-unsigned int CmdArgs_Narg (char *CmdLine_, unsigned int _CmdLine_high);
+extern "C" unsigned int CmdArgs_Narg (const char *CmdLine_, unsigned int _CmdLine_high);
 
 /*
    GetNextArg - Returns true if another argument may be found.
@@ -66,19 +66,19 @@ unsigned int CmdArgs_Narg (char *CmdLine_, unsigned int _CmdLine_high);
                 Arg is filled with the found argument.
 */
 
-static unsigned int GetNextArg (char *CmdLine_, unsigned int _CmdLine_high, unsigned int *CmdIndex, char *Arg, unsigned int _Arg_high);
+static unsigned int GetNextArg (const char *CmdLine_, unsigned int _CmdLine_high, unsigned int *CmdIndex, char *Arg, unsigned int _Arg_high);
 
 /*
    CopyUntilSpace - copies characters until a Space character is found.
 */
 
-static void CopyUntilSpace (char *From_, unsigned int _From_high, unsigned int *FromIndex, unsigned int FromHigh, char *To, unsigned int _To_high, unsigned int *ToIndex, unsigned int ToHigh);
+static void CopyUntilSpace (const char *From_, unsigned int _From_high, unsigned int *FromIndex, unsigned int FromHigh, char *To, unsigned int _To_high, unsigned int *ToIndex, unsigned int ToHigh);
 
 /*
    CopyUntil - copies characters until the UntilChar is found.
 */
 
-static void CopyUntil (char *From_, unsigned int _From_high, unsigned int *FromIndex, unsigned int FromHigh, char *To, unsigned int _To_high, unsigned int *ToIndex, unsigned int ToHigh, char UntilChar);
+static void CopyUntil (const char *From_, unsigned int _From_high, unsigned int *FromIndex, unsigned int FromHigh, char *To, unsigned int _To_high, unsigned int *ToIndex, unsigned int ToHigh, char UntilChar);
 
 /*
    CopyChar - copies a character from string From to string To and
@@ -86,7 +86,7 @@ static void CopyUntil (char *From_, unsigned int _From_high, unsigned int *FromI
               Where x is any character.
 */
 
-static void CopyChar (char *From_, unsigned int _From_high, unsigned int *FromIndex, unsigned int FromHigh, char *To, unsigned int _To_high, unsigned int *ToIndex, unsigned int ToHigh);
+static void CopyChar (const char *From_, unsigned int _From_high, unsigned int *FromIndex, unsigned int FromHigh, char *To, unsigned int _To_high, unsigned int *ToIndex, unsigned int ToHigh);
 static unsigned int Escape (char ch);
 static unsigned int Space (char ch);
 static unsigned int DoubleQuote (char ch);
@@ -99,7 +99,7 @@ static unsigned int SingleQuote (char ch);
                 Arg is filled with the found argument.
 */
 
-static unsigned int GetNextArg (char *CmdLine_, unsigned int _CmdLine_high, unsigned int *CmdIndex, char *Arg, unsigned int _Arg_high)
+static unsigned int GetNextArg (const char *CmdLine_, unsigned int _CmdLine_high, unsigned int *CmdIndex, char *Arg, unsigned int _Arg_high)
 {
   unsigned int ArgIndex;
   unsigned int HighA;
@@ -110,8 +110,8 @@ static unsigned int GetNextArg (char *CmdLine_, unsigned int _CmdLine_high, unsi
   memcpy (CmdLine, CmdLine_, _CmdLine_high+1);
 
   HighA = _Arg_high;  /* Index into Arg  */
-  HighC = StrLib_StrLen ((char *) CmdLine, _CmdLine_high);
-  ArgIndex = 0;
+  HighC = static_cast<unsigned int> (StrLib_StrLen ((const char *) CmdLine, _CmdLine_high));
+  ArgIndex = static_cast<unsigned int> (0);
   /* Skip spaces  */
   while (((*CmdIndex) < HighC) && (Space (CmdLine[(*CmdIndex)])))
     {
@@ -124,7 +124,7 @@ static unsigned int GetNextArg (char *CmdLine_, unsigned int _CmdLine_high, unsi
         {
           /* Skip over the single quote  */
           (*CmdIndex) += 1;
-          CopyUntil ((char *) CmdLine, _CmdLine_high, CmdIndex, HighC, (char *) Arg, _Arg_high, &ArgIndex, HighA, squote);
+          CopyUntil ((const char *) CmdLine, _CmdLine_high, CmdIndex, HighC, (char *) Arg, _Arg_high, &ArgIndex, HighA, squote);
           (*CmdIndex) += 1;
         }
       else if (DoubleQuote (CmdLine[(*CmdIndex)]))
@@ -132,13 +132,13 @@ static unsigned int GetNextArg (char *CmdLine_, unsigned int _CmdLine_high, unsi
           /* avoid dangling else.  */
           /* Skip over the double quote  */
           (*CmdIndex) += 1;
-          CopyUntil ((char *) CmdLine, _CmdLine_high, CmdIndex, HighC, (char *) Arg, _Arg_high, &ArgIndex, HighA, dquote);
+          CopyUntil ((const char *) CmdLine, _CmdLine_high, CmdIndex, HighC, (char *) Arg, _Arg_high, &ArgIndex, HighA, dquote);
           (*CmdIndex) += 1;
         }
       else
         {
           /* avoid dangling else.  */
-          CopyUntilSpace ((char *) CmdLine, _CmdLine_high, CmdIndex, HighC, (char *) Arg, _Arg_high, &ArgIndex, HighA);
+          CopyUntilSpace ((const char *) CmdLine, _CmdLine_high, CmdIndex, HighC, (char *) Arg, _Arg_high, &ArgIndex, HighA);
         }
     }
   /* Skip spaces  */
@@ -148,7 +148,7 @@ static unsigned int GetNextArg (char *CmdLine_, unsigned int _CmdLine_high, unsi
     }
   if (ArgIndex < HighA)
     {
-      Arg[ArgIndex] = ASCII_nul;
+      Arg[ArgIndex] = static_cast<char> (ASCII_nul);
     }
   return (*CmdIndex) < HighC;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -160,7 +160,7 @@ static unsigned int GetNextArg (char *CmdLine_, unsigned int _CmdLine_high, unsi
    CopyUntilSpace - copies characters until a Space character is found.
 */
 
-static void CopyUntilSpace (char *From_, unsigned int _From_high, unsigned int *FromIndex, unsigned int FromHigh, char *To, unsigned int _To_high, unsigned int *ToIndex, unsigned int ToHigh)
+static void CopyUntilSpace (const char *From_, unsigned int _From_high, unsigned int *FromIndex, unsigned int FromHigh, char *To, unsigned int _To_high, unsigned int *ToIndex, unsigned int ToHigh)
 {
   char From[_From_high+1];
 
@@ -169,7 +169,7 @@ static void CopyUntilSpace (char *From_, unsigned int _From_high, unsigned int *
 
   while ((((*FromIndex) < FromHigh) && ((*ToIndex) < ToHigh)) && (! (Space (From[(*FromIndex)]))))
     {
-      CopyChar ((char *) From, _From_high, FromIndex, FromHigh, (char *) To, _To_high, ToIndex, ToHigh);
+      CopyChar ((const char *) From, _From_high, FromIndex, FromHigh, (char *) To, _To_high, ToIndex, ToHigh);
     }
 }
 
@@ -178,7 +178,7 @@ static void CopyUntilSpace (char *From_, unsigned int _From_high, unsigned int *
    CopyUntil - copies characters until the UntilChar is found.
 */
 
-static void CopyUntil (char *From_, unsigned int _From_high, unsigned int *FromIndex, unsigned int FromHigh, char *To, unsigned int _To_high, unsigned int *ToIndex, unsigned int ToHigh, char UntilChar)
+static void CopyUntil (const char *From_, unsigned int _From_high, unsigned int *FromIndex, unsigned int FromHigh, char *To, unsigned int _To_high, unsigned int *ToIndex, unsigned int ToHigh, char UntilChar)
 {
   char From[_From_high+1];
 
@@ -187,7 +187,7 @@ static void CopyUntil (char *From_, unsigned int _From_high, unsigned int *FromI
 
   while ((((*FromIndex) < FromHigh) && ((*ToIndex) < ToHigh)) && (From[(*FromIndex)] != UntilChar))
     {
-      CopyChar ((char *) From, _From_high, FromIndex, FromHigh, (char *) To, _To_high, ToIndex, ToHigh);
+      CopyChar ((const char *) From, _From_high, FromIndex, FromHigh, (char *) To, _To_high, ToIndex, ToHigh);
     }
 }
 
@@ -198,7 +198,7 @@ static void CopyUntil (char *From_, unsigned int _From_high, unsigned int *FromI
               Where x is any character.
 */
 
-static void CopyChar (char *From_, unsigned int _From_high, unsigned int *FromIndex, unsigned int FromHigh, char *To, unsigned int _To_high, unsigned int *ToIndex, unsigned int ToHigh)
+static void CopyChar (const char *From_, unsigned int _From_high, unsigned int *FromIndex, unsigned int FromHigh, char *To, unsigned int _To_high, unsigned int *ToIndex, unsigned int ToHigh)
 {
   char From[_From_high+1];
 
@@ -257,7 +257,7 @@ static unsigned int SingleQuote (char ch)
             The result of the operation is returned.
 */
 
-unsigned int CmdArgs_GetArg (char *CmdLine_, unsigned int _CmdLine_high, unsigned int n, char *Argi, unsigned int _Argi_high)
+extern "C" unsigned int CmdArgs_GetArg (const char *CmdLine_, unsigned int _CmdLine_high, unsigned int n, char *Argi, unsigned int _Argi_high)
 {
   unsigned int Index;
   unsigned int i;
@@ -267,11 +267,11 @@ unsigned int CmdArgs_GetArg (char *CmdLine_, unsigned int _CmdLine_high, unsigne
   /* make a local copy of each unbounded array.  */
   memcpy (CmdLine, CmdLine_, _CmdLine_high+1);
 
-  Index = 0;
+  Index = static_cast<unsigned int> (0);
   /* Continually retrieve an argument until we get the n th argument.  */
-  i = 0;
+  i = static_cast<unsigned int> (0);
   do {
-    Another = GetNextArg ((char *) CmdLine, _CmdLine_high, &Index, (char *) Argi, _Argi_high);
+    Another = static_cast<unsigned int> (GetNextArg ((const char *) CmdLine, _CmdLine_high, &Index, (char *) Argi, _Argi_high));
     i += 1;
   } while (! ((i > n) || ! Another));
   return i > n;
@@ -285,7 +285,7 @@ unsigned int CmdArgs_GetArg (char *CmdLine_, unsigned int _CmdLine_high, unsigne
           command line, CmdLine.
 */
 
-unsigned int CmdArgs_Narg (char *CmdLine_, unsigned int _CmdLine_high)
+extern "C" unsigned int CmdArgs_Narg (const char *CmdLine_, unsigned int _CmdLine_high)
 {
   typedef struct _T1_a _T1;
 
@@ -297,8 +297,8 @@ unsigned int CmdArgs_Narg (char *CmdLine_, unsigned int _CmdLine_high)
   /* make a local copy of each unbounded array.  */
   memcpy (CmdLine, CmdLine_, _CmdLine_high+1);
 
-  ArgNo = 0;
-  while (CmdArgs_GetArg ((char *) CmdLine, _CmdLine_high, ArgNo, (char *) &a.array[0], 1000))
+  ArgNo = static_cast<unsigned int> (0);
+  while (CmdArgs_GetArg ((const char *) CmdLine, _CmdLine_high, ArgNo, (char *) &a.array[0], 1000))
     {
       ArgNo += 1;
     }
@@ -313,10 +313,10 @@ unsigned int CmdArgs_Narg (char *CmdLine_, unsigned int _CmdLine_high)
   __builtin_unreachable ();
 }
 
-void _M2_CmdArgs_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_CmdArgs_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_CmdArgs_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_CmdArgs_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GCmdArgs.h b/gcc/m2/mc-boot/GCmdArgs.h
index 59ea438bef4..50c365230df 100644
--- a/gcc/m2/mc-boot/GCmdArgs.h
+++ b/gcc/m2/mc-boot/GCmdArgs.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_CmdArgs_H)
 #   define _CmdArgs_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
@@ -53,14 +53,14 @@ extern "C" {
             the success of the operation is returned.
 */
 
-EXTERN unsigned int CmdArgs_GetArg (char *CmdLine_, unsigned int _CmdLine_high, unsigned int n, char *Argi, unsigned int _Argi_high);
+EXTERN unsigned int CmdArgs_GetArg (const char *CmdLine_, unsigned int _CmdLine_high, unsigned int n, char *Argi, unsigned int _Argi_high);
 
 /*
    Narg - returns the number of arguments available from
           command line, CmdLine.
 */
 
-EXTERN unsigned int CmdArgs_Narg (char *CmdLine_, unsigned int _CmdLine_high);
+EXTERN unsigned int CmdArgs_Narg (const char *CmdLine_, unsigned int _CmdLine_high);
 #   ifdef __cplusplus
 }
 #   endif
diff --git a/gcc/m2/mc-boot/GDebug.c b/gcc/m2/mc-boot/GDebug.c
index 64c83d2e571..ab77526cf76 100644
--- a/gcc/m2/mc-boot/GDebug.c
+++ b/gcc/m2/mc-boot/GDebug.c
@@ -51,7 +51,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
           It then terminates by calling HALT.
 */
 
-void Debug_Halt (char *Message_, unsigned int _Message_high, unsigned int LineNo, char *Module_, unsigned int _Module_high);
+extern "C" void Debug_Halt (const char *Message_, unsigned int _Message_high, unsigned int LineNo, const char *Module_, unsigned int _Module_high);
 
 /*
    DebugString - writes a string to the debugging device (Scn.Write).
@@ -59,7 +59,7 @@ void Debug_Halt (char *Message_, unsigned int _Message_high, unsigned int LineNo
  as carriage return, linefeed.
 */
 
-void Debug_DebugString (char *a_, unsigned int _a_high);
+extern "C" void Debug_DebugString (const char *a_, unsigned int _a_high);
 
 /*
    WriteLn - writes a carriage return and a newline
@@ -88,7 +88,7 @@ static void WriteLn (void)
           It then terminates by calling HALT.
 */
 
-void Debug_Halt (char *Message_, unsigned int _Message_high, unsigned int LineNo, char *Module_, unsigned int _Module_high)
+extern "C" void Debug_Halt (const char *Message_, unsigned int _Message_high, unsigned int LineNo, const char *Module_, unsigned int _Module_high)
 {
   typedef struct _T1_a _T1;
 
@@ -101,13 +101,13 @@ void Debug_Halt (char *Message_, unsigned int _Message_high, unsigned int LineNo
   memcpy (Message, Message_, _Message_high+1);
   memcpy (Module, Module_, _Module_high+1);
 
-  Debug_DebugString ((char *) Module, _Module_high);  /* should be large enough for most source files..  */
+  Debug_DebugString ((const char *) Module, _Module_high);  /* should be large enough for most source files..  */
   NumberIO_CardToStr (LineNo, 0, (char *) &No.array[0], MaxNoOfDigits);
-  Debug_DebugString ((char *) ":", 1);
-  Debug_DebugString ((char *) &No.array[0], MaxNoOfDigits);
-  Debug_DebugString ((char *) ":", 1);
-  Debug_DebugString ((char *) Message, _Message_high);
-  Debug_DebugString ((char *) "\\n", 2);
+  Debug_DebugString ((const char *) ":", 1);
+  Debug_DebugString ((const char *) &No.array[0], MaxNoOfDigits);
+  Debug_DebugString ((const char *) ":", 1);
+  Debug_DebugString ((const char *) Message, _Message_high);
+  Debug_DebugString ((const char *) "\\n", 2);
   M2RTS_HALT (-1);
   __builtin_unreachable ();
 }
@@ -119,7 +119,7 @@ void Debug_Halt (char *Message_, unsigned int _Message_high, unsigned int LineNo
  as carriage return, linefeed.
 */
 
-void Debug_DebugString (char *a_, unsigned int _a_high)
+extern "C" void Debug_DebugString (const char *a_, unsigned int _a_high)
 {
   unsigned int n;
   unsigned int high;
@@ -129,7 +129,7 @@ void Debug_DebugString (char *a_, unsigned int _a_high)
   memcpy (a, a_, _a_high+1);
 
   high = _a_high;
-  n = 0;
+  n = static_cast<unsigned int> (0);
   while ((n <= high) && (a[n] != ASCII_nul))
     {
       if (a[n] == '\\')
@@ -159,10 +159,10 @@ void Debug_DebugString (char *a_, unsigned int _a_high)
     }
 }
 
-void _M2_Debug_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_Debug_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_Debug_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_Debug_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GDebug.h b/gcc/m2/mc-boot/GDebug.h
index cd96f56ec39..cfeef7567f7 100644
--- a/gcc/m2/mc-boot/GDebug.h
+++ b/gcc/m2/mc-boot/GDebug.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_Debug_H)
 #   define _Debug_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
@@ -55,7 +55,7 @@ extern "C" {
           It then terminates by calling HALT.
 */
 
-EXTERN void Debug_Halt (char *Message_, unsigned int _Message_high, unsigned int LineNo, char *Module_, unsigned int _Module_high);
+EXTERN void Debug_Halt (const char *Message_, unsigned int _Message_high, unsigned int LineNo, const char *Module_, unsigned int _Module_high);
 
 /*
    DebugString - writes a string to the debugging device (Scn.Write).
@@ -63,7 +63,7 @@ EXTERN void Debug_Halt (char *Message_, unsigned int _Message_high, unsigned int
  as carriage return, linefeed.
 */
 
-EXTERN void Debug_DebugString (char *a_, unsigned int _a_high);
+EXTERN void Debug_DebugString (const char *a_, unsigned int _a_high);
 #   ifdef __cplusplus
 }
 #   endif
diff --git a/gcc/m2/mc-boot/GDynamicStrings.c b/gcc/m2/mc-boot/GDynamicStrings.c
index 76b9a3d052e..d11eab795dc 100644
--- a/gcc/m2/mc-boot/GDynamicStrings.c
+++ b/gcc/m2/mc-boot/GDynamicStrings.c
@@ -76,7 +76,7 @@ typedef struct frameRec_r frameRec;
 
 typedef frameRec *frame;
 
-typedef struct _T1_a _T1;
+typedef struct _T3_a _T3;
 
 typedef enum {inuse, marked, onlist, poisoned} desState;
 
@@ -104,9 +104,9 @@ struct frameRec_r {
                     frame next;
                   };
 
-struct _T1_a { char array[(MaxBuf-1)+1]; };
+struct _T3_a { char array[(MaxBuf-1)+1]; };
 struct Contents_r {
-                    _T1 buf;
+                    _T3 buf;
                     unsigned int len;
                     DynamicStrings_String next;
                   };
@@ -126,14 +126,14 @@ static DynamicStrings_String captured;
                 Initial contents are, a.
 */
 
-DynamicStrings_String DynamicStrings_InitString (char *a_, unsigned int _a_high);
+extern "C" DynamicStrings_String DynamicStrings_InitString (const char *a_, unsigned int _a_high);
 
 /*
    KillString - frees String, s, and its contents.
                 NIL is returned.
 */
 
-DynamicStrings_String DynamicStrings_KillString (DynamicStrings_String s);
+extern "C" DynamicStrings_String DynamicStrings_KillString (DynamicStrings_String s);
 
 /*
    Fin - finishes with a string, it calls KillString with, s.
@@ -141,88 +141,88 @@ DynamicStrings_String DynamicStrings_KillString (DynamicStrings_String s);
          to calling KillString and then testing the return result.
 */
 
-void DynamicStrings_Fin (DynamicStrings_String s);
+extern "C" void DynamicStrings_Fin (DynamicStrings_String s);
 
 /*
    InitStringCharStar - initializes and returns a String to contain the C string.
 */
 
-DynamicStrings_String DynamicStrings_InitStringCharStar (void * a);
+extern "C" DynamicStrings_String DynamicStrings_InitStringCharStar (void * a);
 
 /*
    InitStringChar - initializes and returns a String to contain the single character, ch.
 */
 
-DynamicStrings_String DynamicStrings_InitStringChar (char ch);
+extern "C" DynamicStrings_String DynamicStrings_InitStringChar (char ch);
 
 /*
    Mark - marks String, s, ready for garbage collection.
 */
 
-DynamicStrings_String DynamicStrings_Mark (DynamicStrings_String s);
+extern "C" DynamicStrings_String DynamicStrings_Mark (DynamicStrings_String s);
 
 /*
    Length - returns the length of the String, s.
 */
 
-unsigned int DynamicStrings_Length (DynamicStrings_String s);
+extern "C" unsigned int DynamicStrings_Length (DynamicStrings_String s);
 
 /*
    ConCat - returns String, a, after the contents of, b, have been appended.
 */
 
-DynamicStrings_String DynamicStrings_ConCat (DynamicStrings_String a, DynamicStrings_String b);
+extern "C" DynamicStrings_String DynamicStrings_ConCat (DynamicStrings_String a, DynamicStrings_String b);
 
 /*
    ConCatChar - returns String, a, after character, ch, has been appended.
 */
 
-DynamicStrings_String DynamicStrings_ConCatChar (DynamicStrings_String a, char ch);
+extern "C" DynamicStrings_String DynamicStrings_ConCatChar (DynamicStrings_String a, char ch);
 
 /*
    Assign - assigns the contents of, b, into, a.
             String, a, is returned.
 */
 
-DynamicStrings_String DynamicStrings_Assign (DynamicStrings_String a, DynamicStrings_String b);
+extern "C" DynamicStrings_String DynamicStrings_Assign (DynamicStrings_String a, DynamicStrings_String b);
 
 /*
    Dup - duplicate a String, s, returning the copy of s.
 */
 
-DynamicStrings_String DynamicStrings_Dup (DynamicStrings_String s);
+extern "C" DynamicStrings_String DynamicStrings_Dup (DynamicStrings_String s);
 
 /*
    Add - returns a new String which contains the contents of a and b.
 */
 
-DynamicStrings_String DynamicStrings_Add (DynamicStrings_String a, DynamicStrings_String b);
+extern "C" DynamicStrings_String DynamicStrings_Add (DynamicStrings_String a, DynamicStrings_String b);
 
 /*
    Equal - returns TRUE if String, a, and, b, are equal.
 */
 
-unsigned int DynamicStrings_Equal (DynamicStrings_String a, DynamicStrings_String b);
+extern "C" unsigned int DynamicStrings_Equal (DynamicStrings_String a, DynamicStrings_String b);
 
 /*
    EqualCharStar - returns TRUE if contents of String, s, is the same as the
                    string, a.
 */
 
-unsigned int DynamicStrings_EqualCharStar (DynamicStrings_String s, void * a);
+extern "C" unsigned int DynamicStrings_EqualCharStar (DynamicStrings_String s, void * a);
 
 /*
    EqualArray - returns TRUE if contents of String, s, is the same as the
                 string, a.
 */
 
-unsigned int DynamicStrings_EqualArray (DynamicStrings_String s, char *a_, unsigned int _a_high);
+extern "C" unsigned int DynamicStrings_EqualArray (DynamicStrings_String s, const char *a_, unsigned int _a_high);
 
 /*
    Mult - returns a new string which is n concatenations of String, s.
 */
 
-DynamicStrings_String DynamicStrings_Mult (DynamicStrings_String s, unsigned int n);
+extern "C" DynamicStrings_String DynamicStrings_Mult (DynamicStrings_String s, unsigned int n);
 
 /*
    Slice - returns a new string which contains the elements
@@ -236,7 +236,7 @@ DynamicStrings_String DynamicStrings_Mult (DynamicStrings_String s, unsigned int
            Slice(s, 4, -2) will return elements 4..max-2
 */
 
-DynamicStrings_String DynamicStrings_Slice (DynamicStrings_String s, int low, int high);
+extern "C" DynamicStrings_String DynamicStrings_Slice (DynamicStrings_String s, int low, int high);
 
 /*
    Index - returns the indice of the first occurance of, ch, in
@@ -244,7 +244,7 @@ DynamicStrings_String DynamicStrings_Slice (DynamicStrings_String s, int low, in
            The search starts at position, o.
 */
 
-int DynamicStrings_Index (DynamicStrings_String s, char ch, unsigned int o);
+extern "C" int DynamicStrings_Index (DynamicStrings_String s, char ch, unsigned int o);
 
 /*
    RIndex - returns the indice of the last occurance of, ch,
@@ -252,7 +252,7 @@ int DynamicStrings_Index (DynamicStrings_String s, char ch, unsigned int o);
             -1 is returned if, ch, is not found.
 */
 
-int DynamicStrings_RIndex (DynamicStrings_String s, char ch, unsigned int o);
+extern "C" int DynamicStrings_RIndex (DynamicStrings_String s, char ch, unsigned int o);
 
 /*
    RemoveComment - assuming that, comment, is a comment delimiter
@@ -262,21 +262,21 @@ int DynamicStrings_RIndex (DynamicStrings_String s, char ch, unsigned int o);
                    It leaves any white space on the left hand side alone.
 */
 
-DynamicStrings_String DynamicStrings_RemoveComment (DynamicStrings_String s, char comment);
+extern "C" DynamicStrings_String DynamicStrings_RemoveComment (DynamicStrings_String s, char comment);
 
 /*
    RemoveWhitePrefix - removes any leading white space from String, s.
                        A new string is returned.
 */
 
-DynamicStrings_String DynamicStrings_RemoveWhitePrefix (DynamicStrings_String s);
+extern "C" DynamicStrings_String DynamicStrings_RemoveWhitePrefix (DynamicStrings_String s);
 
 /*
    RemoveWhitePostfix - removes any leading white space from String, s.
                         A new string is returned.
 */
 
-DynamicStrings_String DynamicStrings_RemoveWhitePostfix (DynamicStrings_String s);
+extern "C" DynamicStrings_String DynamicStrings_RemoveWhitePostfix (DynamicStrings_String s);
 
 /*
    ToUpper - returns string, s, after it has had its lower case characters
@@ -284,7 +284,7 @@ DynamicStrings_String DynamicStrings_RemoveWhitePostfix (DynamicStrings_String s
              The string, s, is not duplicated.
 */
 
-DynamicStrings_String DynamicStrings_ToUpper (DynamicStrings_String s);
+extern "C" DynamicStrings_String DynamicStrings_ToUpper (DynamicStrings_String s);
 
 /*
    ToLower - returns string, s, after it has had its upper case characters
@@ -292,67 +292,67 @@ DynamicStrings_String DynamicStrings_ToUpper (DynamicStrings_String s);
              The string, s, is not duplicated.
 */
 
-DynamicStrings_String DynamicStrings_ToLower (DynamicStrings_String s);
+extern "C" DynamicStrings_String DynamicStrings_ToLower (DynamicStrings_String s);
 
 /*
    CopyOut - copies string, s, to a.
 */
 
-void DynamicStrings_CopyOut (char *a, unsigned int _a_high, DynamicStrings_String s);
+extern "C" void DynamicStrings_CopyOut (char *a, unsigned int _a_high, DynamicStrings_String s);
 
 /*
    char - returns the character, ch, at position, i, in String, s.
 */
 
-char DynamicStrings_char (DynamicStrings_String s, int i);
+extern "C" char DynamicStrings_char (DynamicStrings_String s, int i);
 
 /*
    string - returns the C style char * of String, s.
 */
 
-void * DynamicStrings_string (DynamicStrings_String s);
+extern "C" void * DynamicStrings_string (DynamicStrings_String s);
 
 /*
    InitStringDB - the debug version of InitString.
 */
 
-DynamicStrings_String DynamicStrings_InitStringDB (char *a_, unsigned int _a_high, char *file_, unsigned int _file_high, unsigned int line);
+extern "C" DynamicStrings_String DynamicStrings_InitStringDB (const char *a_, unsigned int _a_high, const char *file_, unsigned int _file_high, unsigned int line);
 
 /*
    InitStringCharStarDB - the debug version of InitStringCharStar.
 */
 
-DynamicStrings_String DynamicStrings_InitStringCharStarDB (void * a, char *file_, unsigned int _file_high, unsigned int line);
+extern "C" DynamicStrings_String DynamicStrings_InitStringCharStarDB (void * a, const char *file_, unsigned int _file_high, unsigned int line);
 
 /*
    InitStringCharDB - the debug version of InitStringChar.
 */
 
-DynamicStrings_String DynamicStrings_InitStringCharDB (char ch, char *file_, unsigned int _file_high, unsigned int line);
+extern "C" DynamicStrings_String DynamicStrings_InitStringCharDB (char ch, const char *file_, unsigned int _file_high, unsigned int line);
 
 /*
    MultDB - the debug version of MultDB.
 */
 
-DynamicStrings_String DynamicStrings_MultDB (DynamicStrings_String s, unsigned int n, char *file_, unsigned int _file_high, unsigned int line);
+extern "C" DynamicStrings_String DynamicStrings_MultDB (DynamicStrings_String s, unsigned int n, const char *file_, unsigned int _file_high, unsigned int line);
 
 /*
    DupDB - the debug version of Dup.
 */
 
-DynamicStrings_String DynamicStrings_DupDB (DynamicStrings_String s, char *file_, unsigned int _file_high, unsigned int line);
+extern "C" DynamicStrings_String DynamicStrings_DupDB (DynamicStrings_String s, const char *file_, unsigned int _file_high, unsigned int line);
 
 /*
    SliceDB - debug version of Slice.
 */
 
-DynamicStrings_String DynamicStrings_SliceDB (DynamicStrings_String s, int low, int high, char *file_, unsigned int _file_high, unsigned int line);
+extern "C" DynamicStrings_String DynamicStrings_SliceDB (DynamicStrings_String s, int low, int high, const char *file_, unsigned int _file_high, unsigned int line);
 
 /*
    PushAllocation - pushes the current allocation/deallocation lists.
 */
 
-void DynamicStrings_PushAllocation (void);
+extern "C" void DynamicStrings_PushAllocation (void);
 
 /*
    PopAllocation - test to see that all strings are deallocated since
@@ -363,7 +363,7 @@ void DynamicStrings_PushAllocation (void);
                    with an exit code of 1.
 */
 
-void DynamicStrings_PopAllocation (unsigned int halt);
+extern "C" void DynamicStrings_PopAllocation (unsigned int halt);
 
 /*
    PopAllocationExemption - test to see that all strings are deallocated, except
@@ -375,7 +375,7 @@ void DynamicStrings_PopAllocation (unsigned int halt);
                             with an exit code of 1.
 */
 
-DynamicStrings_String DynamicStrings_PopAllocationExemption (unsigned int halt, DynamicStrings_String e);
+extern "C" DynamicStrings_String DynamicStrings_PopAllocationExemption (unsigned int halt, DynamicStrings_String e);
 
 /*
  writeStringDesc write out debugging information about string, s.  */
@@ -441,7 +441,7 @@ static unsigned int Max (unsigned int a, unsigned int b);
    writeString - writes a string to stdout.
 */
 
-static void writeString (char *a_, unsigned int _a_high);
+static void writeString (const char *a_, unsigned int _a_high);
 
 /*
    writeCstring - writes a C string to stdout.
@@ -477,7 +477,7 @@ static void writeLn (void);
    AssignDebug - assigns, file, and, line, information to string, s.
 */
 
-static DynamicStrings_String AssignDebug (DynamicStrings_String s, char *file_, unsigned int _file_high, unsigned int line, char *proc_, unsigned int _proc_high);
+static DynamicStrings_String AssignDebug (DynamicStrings_String s, const char *file_, unsigned int _file_high, unsigned int line, const char *proc_, unsigned int _proc_high);
 
 /*
    IsOn - returns TRUE if, s, is on one of the debug lists.
@@ -550,7 +550,7 @@ static void AddDebugInfo (DynamicStrings_String s);
                     total length of, a. The offset is in, o.
 */
 
-static void ConcatContents (Contents *c, char *a_, unsigned int _a_high, unsigned int h, unsigned int o);
+static void ConcatContents (Contents *c, const char *a_, unsigned int _a_high, unsigned int h, unsigned int o);
 
 /*
    DeallocateCharStar - deallocates any charStar.
@@ -628,36 +628,36 @@ static void Init (void);
 static void writeStringDesc (DynamicStrings_String s)
 {
   writeCstring (s->debug.file);
-  writeString ((char *) ":", 1);
+  writeString ((const char *) ":", 1);
   writeCard (s->debug.line);
-  writeString ((char *) ":", 1);
+  writeString ((const char *) ":", 1);
   writeCstring (s->debug.proc);
-  writeString ((char *) " ", 1);
-  writeAddress ((void *) s);
-  writeString ((char *) " ", 1);
+  writeString ((const char *) " ", 1);
+  writeAddress (reinterpret_cast<void *> (s));
+  writeString ((const char *) " ", 1);
   switch (s->head->state)
     {
       case inuse:
-        writeString ((char *) "still in use (", 14);
+        writeString ((const char *) "still in use (", 14);
         writeCard (s->contents.len);
-        writeString ((char *) ") characters", 12);
+        writeString ((const char *) ") characters", 12);
         break;
 
       case marked:
-        writeString ((char *) "marked", 6);
+        writeString ((const char *) "marked", 6);
         break;
 
       case onlist:
-        writeString ((char *) "on a (lost) garbage list", 24);
+        writeString ((const char *) "on a (lost) garbage list", 24);
         break;
 
       case poisoned:
-        writeString ((char *) "poisoned", 8);
+        writeString ((const char *) "poisoned", 8);
         break;
 
 
       default:
-        writeString ((char *) "unknown state", 13);
+        writeString ((const char *) "unknown state", 13);
         break;
     }
 }
@@ -671,7 +671,7 @@ static void writeNspace (unsigned int n)
 {
   while (n > 0)
     {
-      writeString ((char *) " ", 1);
+      writeString ((const char *) " ", 1);
       n -= 1;
     }
 }
@@ -693,7 +693,7 @@ static void DumpStringInfo (DynamicStrings_String s, unsigned int i)
       if (s->head->garbage != NULL)
         {
           writeNspace (i);
-          writeString ((char *) "garbage list:", 13);
+          writeString ((const char *) "garbage list:", 13);
           writeLn ();
           do {
             s = s->head->garbage;
@@ -735,7 +735,7 @@ static void doDSdbExit (DynamicStrings_String s)
 {
   if (CheckOn)
     {
-      s = DynamicStrings_PopAllocationExemption (TRUE, s);
+      s = static_cast<DynamicStrings_String> (DynamicStrings_PopAllocationExemption (TRUE, s));
     }
 }
 
@@ -769,7 +769,7 @@ static unsigned int Capture (DynamicStrings_String s)
  *   #endif
   */
   captured = s;
-  return 1;
+  return static_cast<unsigned int> (1);
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -817,7 +817,7 @@ static unsigned int Max (unsigned int a, unsigned int b)
    writeString - writes a string to stdout.
 */
 
-static void writeString (char *a_, unsigned int _a_high)
+static void writeString (const char *a_, unsigned int _a_high)
 {
   int i;
   char a[_a_high+1];
@@ -825,7 +825,7 @@ static void writeString (char *a_, unsigned int _a_high)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  i = libc_write (1, &a, (size_t) StrLib_StrLen ((char *) a, _a_high));
+  i = static_cast<int> (libc_write (1, &a, static_cast<size_t> (StrLib_StrLen ((const char *) a, _a_high))));
 }
 
 
@@ -839,11 +839,11 @@ static void writeCstring (void * a)
 
   if (a == NULL)
     {
-      writeString ((char *) "(null)", 6);
+      writeString ((const char *) "(null)", 6);
     }
   else
     {
-      i = libc_write (1, a, libc_strlen (a));
+      i = static_cast<int> (libc_write (1, a, libc_strlen (a)));
     }
 }
 
@@ -865,7 +865,7 @@ static void writeCard (unsigned int c)
   else
     {
       ch = ((char) ( ((unsigned int) ('0'))+c));
-      i = libc_write (1, &ch, (size_t) 1);
+      i = static_cast<int> (libc_write (1, &ch, static_cast<size_t> (1)));
     }
 }
 
@@ -888,13 +888,13 @@ static void writeLongcard (long unsigned int l)
     {
       /* avoid dangling else.  */
       ch = ((char) ( ((unsigned int) ('0'))+((unsigned int ) (l))));
-      i = libc_write (1, &ch, (size_t) 1);
+      i = static_cast<int> (libc_write (1, &ch, static_cast<size_t> (1)));
     }
   else if (l < 16)
     {
       /* avoid dangling else.  */
       ch = ((char) (( ((unsigned int) ('a'))+((unsigned int ) (l)))-10));
-      i = libc_write (1, &ch, (size_t) 1);
+      i = static_cast<int> (libc_write (1, &ch, static_cast<size_t> (1)));
     }
 }
 
@@ -918,8 +918,8 @@ static void writeLn (void)
   char ch;
   int i;
 
-  ch = ASCII_lf;
-  i = libc_write (1, &ch, (size_t) 1);
+  ch = static_cast<char> (ASCII_lf);
+  i = static_cast<int> (libc_write (1, &ch, static_cast<size_t> (1)));
 }
 
 
@@ -927,7 +927,7 @@ static void writeLn (void)
    AssignDebug - assigns, file, and, line, information to string, s.
 */
 
-static DynamicStrings_String AssignDebug (DynamicStrings_String s, char *file_, unsigned int _file_high, unsigned int line, char *proc_, unsigned int _proc_high)
+static DynamicStrings_String AssignDebug (DynamicStrings_String s, const char *file_, unsigned int _file_high, unsigned int line, const char *proc_, unsigned int _proc_high)
 {
   void * f;
   void * p;
@@ -940,12 +940,12 @@ static DynamicStrings_String AssignDebug (DynamicStrings_String s, char *file_,
 
   f = &file;
   p = &proc;
-  Storage_ALLOCATE (&s->debug.file, (StrLib_StrLen ((char *) file, _file_high))+1);
-  if ((libc_strncpy (s->debug.file, f, (StrLib_StrLen ((char *) file, _file_high))+1)) == NULL)
+  Storage_ALLOCATE (&s->debug.file, (StrLib_StrLen ((const char *) file, _file_high))+1);
+  if ((libc_strncpy (s->debug.file, f, (StrLib_StrLen ((const char *) file, _file_high))+1)) == NULL)
     {}  /* empty.  */
   s->debug.line = line;
-  Storage_ALLOCATE (&s->debug.proc, (StrLib_StrLen ((char *) proc, _proc_high))+1);
-  if ((libc_strncpy (s->debug.proc, p, (StrLib_StrLen ((char *) proc, _proc_high))+1)) == NULL)
+  Storage_ALLOCATE (&s->debug.proc, (StrLib_StrLen ((const char *) proc, _proc_high))+1);
+  if ((libc_strncpy (s->debug.proc, p, (StrLib_StrLen ((const char *) proc, _proc_high))+1)) == NULL)
     {}  /* empty.  */
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -978,7 +978,7 @@ static void AddTo (DynamicStrings_String *list, DynamicStrings_String s)
   if ((*list) == NULL)
     {
       (*list) = s;
-      s->debug.next = NULL;
+      s->debug.next = static_cast<DynamicStrings_String> (NULL);
     }
   else
     {
@@ -1017,7 +1017,7 @@ static void SubFrom (DynamicStrings_String *list, DynamicStrings_String s)
           return;
         }
     }
-  s->debug.next = NULL;
+  s->debug.next = static_cast<DynamicStrings_String> (NULL);
 }
 
 
@@ -1174,9 +1174,9 @@ static void SubDebugInfo (DynamicStrings_String s)
 
 static void AddDebugInfo (DynamicStrings_String s)
 {
-  s->debug.next = NULL;
+  s->debug.next = static_cast<DynamicStrings_String> (NULL);
   s->debug.file = NULL;
-  s->debug.line = 0;
+  s->debug.line = static_cast<unsigned int> (0);
   s->debug.proc = NULL;
   if (CheckOn)
     {
@@ -1190,7 +1190,7 @@ static void AddDebugInfo (DynamicStrings_String s)
                     total length of, a. The offset is in, o.
 */
 
-static void ConcatContents (Contents *c, char *a_, unsigned int _a_high, unsigned int h, unsigned int o)
+static void ConcatContents (Contents *c, const char *a_, unsigned int _a_high, unsigned int h, unsigned int o)
 {
   unsigned int i;
   char a[_a_high+1];
@@ -1207,14 +1207,14 @@ static void ConcatContents (Contents *c, char *a_, unsigned int _a_high, unsigne
     }
   if (o < h)
     {
-      (*c).len = MaxBuf;
+      (*c).len = static_cast<unsigned int> (MaxBuf);
       Storage_ALLOCATE ((void **) &(*c).next, sizeof (stringRecord));
-      (*c).next->head = NULL;
-      (*c).next->contents.len = 0;
-      (*c).next->contents.next = NULL;
-      ConcatContents (&(*c).next->contents, (char *) a, _a_high, h, o);
+      (*c).next->head = static_cast<Descriptor> (NULL);
+      (*c).next->contents.len = static_cast<unsigned int> (0);
+      (*c).next->contents.next = static_cast<DynamicStrings_String> (NULL);
+      ConcatContents (&(*c).next->contents, (const char *) a, _a_high, h, o);
       AddDebugInfo ((*c).next);
-      (*c).next = AssignDebug ((*c).next, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 722, (char *) "ConcatContents", 14);
+      (*c).next = static_cast<DynamicStrings_String> (AssignDebug ((*c).next, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 722, (const char *) "ConcatContents", 14));
     }
   else
     {
@@ -1237,7 +1237,7 @@ static void DeallocateCharStar (DynamicStrings_String s)
         }
       s->head->charStarUsed = FALSE;
       s->head->charStar = NULL;
-      s->head->charStarSize = 0;
+      s->head->charStarSize = static_cast<unsigned int> (0);
       s->head->charStarValid = FALSE;
     }
 }
@@ -1268,7 +1268,7 @@ static void MarkInvalid (DynamicStrings_String s)
 {
   if (PoisonOn)
     {
-      s = CheckPoisoned (s);
+      s = static_cast<DynamicStrings_String> (CheckPoisoned (s));
     }
   if (s->head != NULL)
     {
@@ -1284,13 +1284,15 @@ static void MarkInvalid (DynamicStrings_String s)
 
 static void ConcatContentsAddress (Contents *c, void * a, unsigned int h)
 {
+  typedef char *_T1;
+
+  _T1 p;
   unsigned int i;
   unsigned int j;
-  char * p;
 
-  j = 0;
+  j = static_cast<unsigned int> (0);
   i = (*c).len;
-  p = a;
+  p = static_cast<_T1> (a);
   while ((j < h) && (i < MaxBuf))
     {
       (*c).buf.array[i] = (*p);
@@ -1301,22 +1303,22 @@ static void ConcatContentsAddress (Contents *c, void * a, unsigned int h)
   if (j < h)
     {
       /* avoid dangling else.  */
-      (*c).len = MaxBuf;
+      (*c).len = static_cast<unsigned int> (MaxBuf);
       Storage_ALLOCATE ((void **) &(*c).next, sizeof (stringRecord));
-      (*c).next->head = NULL;
-      (*c).next->contents.len = 0;
-      (*c).next->contents.next = NULL;
-      ConcatContentsAddress (&(*c).next->contents, (void *) p, h-j);
+      (*c).next->head = static_cast<Descriptor> (NULL);
+      (*c).next->contents.len = static_cast<unsigned int> (0);
+      (*c).next->contents.next = static_cast<DynamicStrings_String> (NULL);
+      ConcatContentsAddress (&(*c).next->contents, reinterpret_cast<void *> (p), h-j);
       AddDebugInfo ((*c).next);
       if (TraceOn)
         {
-          (*c).next = AssignDebug ((*c).next, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 917, (char *) "ConcatContentsAddress", 21);
+          (*c).next = static_cast<DynamicStrings_String> (AssignDebug ((*c).next, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 917, (const char *) "ConcatContentsAddress", 21));
         }
     }
   else
     {
       (*c).len = i;
-      (*c).next = NULL;
+      (*c).next = static_cast<DynamicStrings_String> (NULL);
     }
 }
 
@@ -1333,8 +1335,8 @@ static DynamicStrings_String AddToGarbage (DynamicStrings_String a, DynamicStrin
 
   if (PoisonOn)
     {
-      a = CheckPoisoned (a);
-      b = CheckPoisoned (b);
+      a = static_cast<DynamicStrings_String> (CheckPoisoned (a));
+      b = static_cast<DynamicStrings_String> (CheckPoisoned (b));
     }
   /* 
    IF (a#NIL) AND (a#b) AND (a^.head^.state=marked)
@@ -1409,26 +1411,26 @@ static void DumpState (DynamicStrings_String s)
   switch (s->head->state)
     {
       case inuse:
-        writeString ((char *) "still in use (", 14);
+        writeString ((const char *) "still in use (", 14);
         writeCard (s->contents.len);
-        writeString ((char *) ") characters", 12);
+        writeString ((const char *) ") characters", 12);
         break;
 
       case marked:
-        writeString ((char *) "marked", 6);
+        writeString ((const char *) "marked", 6);
         break;
 
       case onlist:
-        writeString ((char *) "on a garbage list", 17);
+        writeString ((const char *) "on a garbage list", 17);
         break;
 
       case poisoned:
-        writeString ((char *) "poisoned", 8);
+        writeString ((const char *) "poisoned", 8);
         break;
 
 
       default:
-        writeString ((char *) "unknown state", 13);
+        writeString ((const char *) "unknown state", 13);
         break;
     }
 }
@@ -1441,27 +1443,27 @@ static void DumpState (DynamicStrings_String s)
 static void DumpStringSynopsis (DynamicStrings_String s)
 {
   writeCstring (s->debug.file);
-  writeString ((char *) ":", 1);
+  writeString ((const char *) ":", 1);
   writeCard (s->debug.line);
-  writeString ((char *) ":", 1);
+  writeString ((const char *) ":", 1);
   writeCstring (s->debug.proc);
-  writeString ((char *) " string ", 8);
-  writeAddress ((void *) s);
-  writeString ((char *) " ", 1);
+  writeString ((const char *) " string ", 8);
+  writeAddress (reinterpret_cast<void *> (s));
+  writeString ((const char *) " ", 1);
   DumpState (s);
   if (IsOnAllocated (s))
     {
-      writeString ((char *) " globally allocated", 19);
+      writeString ((const char *) " globally allocated", 19);
     }
   else if (IsOnDeallocated (s))
     {
       /* avoid dangling else.  */
-      writeString ((char *) " globally deallocated", 21);
+      writeString ((const char *) " globally deallocated", 21);
     }
   else
     {
       /* avoid dangling else.  */
-      writeString ((char *) " globally unknown", 17);
+      writeString ((const char *) " globally unknown", 17);
     }
   writeLn ();
 }
@@ -1480,7 +1482,7 @@ static void DumpString (DynamicStrings_String s)
       DumpStringSynopsis (s);
       if ((s->head != NULL) && (s->head->garbage != NULL))
         {
-          writeString ((char *) "display chained strings on the garbage list", 43);
+          writeString ((const char *) "display chained strings on the garbage list", 43);
           writeLn ();
           t = s->head->garbage;
           while (t != NULL)
@@ -1502,7 +1504,7 @@ static void Init (void)
   if (! Initialized)
     {
       Initialized = TRUE;
-      frameHead = NULL;
+      frameHead = static_cast<frame> (NULL);
       DynamicStrings_PushAllocation ();
     }
 }
@@ -1513,7 +1515,7 @@ static void Init (void)
                 Initial contents are, a.
 */
 
-DynamicStrings_String DynamicStrings_InitString (char *a_, unsigned int _a_high)
+extern "C" DynamicStrings_String DynamicStrings_InitString (const char *a_, unsigned int _a_high)
 {
   DynamicStrings_String s;
   char a[_a_high+1];
@@ -1522,20 +1524,20 @@ DynamicStrings_String DynamicStrings_InitString (char *a_, unsigned int _a_high)
   memcpy (a, a_, _a_high+1);
 
   Storage_ALLOCATE ((void **) &s, sizeof (stringRecord));
-  s->contents.len = 0;
-  s->contents.next = NULL;
-  ConcatContents (&s->contents, (char *) a, _a_high, StrLib_StrLen ((char *) a, _a_high), 0);
+  s->contents.len = static_cast<unsigned int> (0);
+  s->contents.next = static_cast<DynamicStrings_String> (NULL);
+  ConcatContents (&s->contents, (const char *) a, _a_high, StrLib_StrLen ((const char *) a, _a_high), 0);
   Storage_ALLOCATE ((void **) &s->head, sizeof (descriptor));
   s->head->charStarUsed = FALSE;
   s->head->charStar = NULL;
-  s->head->charStarSize = 0;
+  s->head->charStarSize = static_cast<unsigned int> (0);
   s->head->charStarValid = FALSE;
-  s->head->garbage = NULL;
+  s->head->garbage = static_cast<DynamicStrings_String> (NULL);
   s->head->state = inuse;
   AddDebugInfo (s);
   if (TraceOn)
     {
-      s = AssignDebug (s, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 758, (char *) "InitString", 10);
+      s = static_cast<DynamicStrings_String> (AssignDebug (s, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 758, (const char *) "InitString", 10));
     }
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -1548,13 +1550,13 @@ DynamicStrings_String DynamicStrings_InitString (char *a_, unsigned int _a_high)
                 NIL is returned.
 */
 
-DynamicStrings_String DynamicStrings_KillString (DynamicStrings_String s)
+extern "C" DynamicStrings_String DynamicStrings_KillString (DynamicStrings_String s)
 {
   DynamicStrings_String t;
 
   if (PoisonOn)
     {
-      s = CheckPoisoned (s);
+      s = static_cast<DynamicStrings_String> (CheckPoisoned (s));
     }
   if (s != NULL)
     {
@@ -1574,7 +1576,7 @@ DynamicStrings_String DynamicStrings_KillString (DynamicStrings_String s)
       if (s->head != NULL)
         {
           s->head->state = poisoned;
-          s->head->garbage = DynamicStrings_KillString (s->head->garbage);
+          s->head->garbage = static_cast<DynamicStrings_String> (DynamicStrings_KillString (s->head->garbage));
           if (! PoisonOn)
             {
               DeallocateCharStar (s);
@@ -1582,16 +1584,16 @@ DynamicStrings_String DynamicStrings_KillString (DynamicStrings_String s)
           if (! PoisonOn)
             {
               Storage_DEALLOCATE ((void **) &s->head, sizeof (descriptor));
-              s->head = NULL;
+              s->head = static_cast<Descriptor> (NULL);
             }
         }
-      t = DynamicStrings_KillString (s->contents.next);
+      t = static_cast<DynamicStrings_String> (DynamicStrings_KillString (s->contents.next));
       if (! PoisonOn)
         {
           Storage_DEALLOCATE ((void **) &s, sizeof (stringRecord));
         }
     }
-  return NULL;
+  return static_cast<DynamicStrings_String> (NULL);
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -1603,7 +1605,7 @@ DynamicStrings_String DynamicStrings_KillString (DynamicStrings_String s)
          to calling KillString and then testing the return result.
 */
 
-void DynamicStrings_Fin (DynamicStrings_String s)
+extern "C" void DynamicStrings_Fin (DynamicStrings_String s)
 {
   if ((DynamicStrings_KillString (s)) != NULL)
     {
@@ -1617,28 +1619,28 @@ void DynamicStrings_Fin (DynamicStrings_String s)
    InitStringCharStar - initializes and returns a String to contain the C string.
 */
 
-DynamicStrings_String DynamicStrings_InitStringCharStar (void * a)
+extern "C" DynamicStrings_String DynamicStrings_InitStringCharStar (void * a)
 {
   DynamicStrings_String s;
 
   Storage_ALLOCATE ((void **) &s, sizeof (stringRecord));
-  s->contents.len = 0;
-  s->contents.next = NULL;
+  s->contents.len = static_cast<unsigned int> (0);
+  s->contents.next = static_cast<DynamicStrings_String> (NULL);
   if (a != NULL)
     {
-      ConcatContentsAddress (&s->contents, a, (unsigned int) libc_strlen (a));
+      ConcatContentsAddress (&s->contents, a, static_cast<unsigned int> (libc_strlen (a)));
     }
   Storage_ALLOCATE ((void **) &s->head, sizeof (descriptor));
   s->head->charStarUsed = FALSE;
   s->head->charStar = NULL;
-  s->head->charStarSize = 0;
+  s->head->charStarSize = static_cast<unsigned int> (0);
   s->head->charStarValid = FALSE;
-  s->head->garbage = NULL;
+  s->head->garbage = static_cast<DynamicStrings_String> (NULL);
   s->head->state = inuse;
   AddDebugInfo (s);
   if (TraceOn)
     {
-      s = AssignDebug (s, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 957, (char *) "InitStringCharStar", 18);
+      s = static_cast<DynamicStrings_String> (AssignDebug (s, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 957, (const char *) "InitStringCharStar", 18));
     }
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -1650,20 +1652,20 @@ DynamicStrings_String DynamicStrings_InitStringCharStar (void * a)
    InitStringChar - initializes and returns a String to contain the single character, ch.
 */
 
-DynamicStrings_String DynamicStrings_InitStringChar (char ch)
+extern "C" DynamicStrings_String DynamicStrings_InitStringChar (char ch)
 {
-  typedef struct _T2_a _T2;
+  typedef struct _T4_a _T4;
 
-  struct _T2_a { char array[1+1]; };
-  _T2 a;
+  struct _T4_a { char array[1+1]; };
+  _T4 a;
   DynamicStrings_String s;
 
   a.array[0] = ch;
-  a.array[1] = ASCII_nul;
-  s = DynamicStrings_InitString ((char *) &a.array[0], 1);
+  a.array[1] = static_cast<char> (ASCII_nul);
+  s = static_cast<DynamicStrings_String> (DynamicStrings_InitString ((const char *) &a.array[0], 1));
   if (TraceOn)
     {
-      s = AssignDebug (s, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 977, (char *) "InitStringChar", 14);
+      s = static_cast<DynamicStrings_String> (AssignDebug (s, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 977, (const char *) "InitStringChar", 14));
     }
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -1675,11 +1677,11 @@ DynamicStrings_String DynamicStrings_InitStringChar (char ch)
    Mark - marks String, s, ready for garbage collection.
 */
 
-DynamicStrings_String DynamicStrings_Mark (DynamicStrings_String s)
+extern "C" DynamicStrings_String DynamicStrings_Mark (DynamicStrings_String s)
 {
   if (PoisonOn)
     {
-      s = CheckPoisoned (s);
+      s = static_cast<DynamicStrings_String> (CheckPoisoned (s));
     }
   if ((s != NULL) && (s->head->state == inuse))
     {
@@ -1695,15 +1697,15 @@ DynamicStrings_String DynamicStrings_Mark (DynamicStrings_String s)
    Length - returns the length of the String, s.
 */
 
-unsigned int DynamicStrings_Length (DynamicStrings_String s)
+extern "C" unsigned int DynamicStrings_Length (DynamicStrings_String s)
 {
   if (s == NULL)
     {
-      return 0;
+      return static_cast<unsigned int> (0);
     }
   else
     {
-      return s->contents.len+(DynamicStrings_Length (s->contents.next));
+      return static_cast<unsigned int> (s->contents.len+(DynamicStrings_Length (s->contents.next)));
     }
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
@@ -1714,23 +1716,23 @@ unsigned int DynamicStrings_Length (DynamicStrings_String s)
    ConCat - returns String, a, after the contents of, b, have been appended.
 */
 
-DynamicStrings_String DynamicStrings_ConCat (DynamicStrings_String a, DynamicStrings_String b)
+extern "C" DynamicStrings_String DynamicStrings_ConCat (DynamicStrings_String a, DynamicStrings_String b)
 {
   DynamicStrings_String t;
 
   if (PoisonOn)
     {
-      a = CheckPoisoned (a);
-      b = CheckPoisoned (b);
+      a = static_cast<DynamicStrings_String> (CheckPoisoned (a));
+      b = static_cast<DynamicStrings_String> (CheckPoisoned (b));
     }
   if (a == b)
     {
-      return DynamicStrings_ConCat (a, DynamicStrings_Mark (DynamicStrings_Dup (b)));
+      return static_cast<DynamicStrings_String> (DynamicStrings_ConCat (a, DynamicStrings_Mark (DynamicStrings_Dup (b))));
     }
   else if (a != NULL)
     {
       /* avoid dangling else.  */
-      a = AddToGarbage (a, b);
+      a = static_cast<DynamicStrings_String> (AddToGarbage (a, b));
       MarkInvalid (a);
       t = a;
       while (b != NULL)
@@ -1739,7 +1741,7 @@ DynamicStrings_String DynamicStrings_ConCat (DynamicStrings_String a, DynamicStr
             {
               t = t->contents.next;
             }
-          ConcatContents (&t->contents, (char *) &b->contents.buf.array[0], (MaxBuf-1), b->contents.len, 0);
+          ConcatContents (&t->contents, (const char *) &b->contents.buf.array[0], (MaxBuf-1), b->contents.len, 0);
           b = b->contents.next;
         }
     }
@@ -1758,17 +1760,17 @@ DynamicStrings_String DynamicStrings_ConCat (DynamicStrings_String a, DynamicStr
    ConCatChar - returns String, a, after character, ch, has been appended.
 */
 
-DynamicStrings_String DynamicStrings_ConCatChar (DynamicStrings_String a, char ch)
+extern "C" DynamicStrings_String DynamicStrings_ConCatChar (DynamicStrings_String a, char ch)
 {
-  typedef struct _T3_a _T3;
+  typedef struct _T5_a _T5;
 
-  struct _T3_a { char array[1+1]; };
-  _T3 b;
+  struct _T5_a { char array[1+1]; };
+  _T5 b;
   DynamicStrings_String t;
 
   if (PoisonOn)
     {
-      a = CheckPoisoned (a);
+      a = static_cast<DynamicStrings_String> (CheckPoisoned (a));
     }
   b.array[0] = ch;
   b.array[1] = ASCII_nul;
@@ -1778,7 +1780,7 @@ DynamicStrings_String DynamicStrings_ConCatChar (DynamicStrings_String a, char c
     {
       t = t->contents.next;
     }
-  ConcatContents (&t->contents, (char *) &b.array[0], 1, 1, 0);
+  ConcatContents (&t->contents, (const char *) &b.array[0], 1, 1, 0);
   return a;
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
@@ -1790,19 +1792,19 @@ DynamicStrings_String DynamicStrings_ConCatChar (DynamicStrings_String a, char c
             String, a, is returned.
 */
 
-DynamicStrings_String DynamicStrings_Assign (DynamicStrings_String a, DynamicStrings_String b)
+extern "C" DynamicStrings_String DynamicStrings_Assign (DynamicStrings_String a, DynamicStrings_String b)
 {
   if (PoisonOn)
     {
-      a = CheckPoisoned (a);
-      b = CheckPoisoned (b);
+      a = static_cast<DynamicStrings_String> (CheckPoisoned (a));
+      b = static_cast<DynamicStrings_String> (CheckPoisoned (b));
     }
   if ((a != NULL) && (b != NULL))
     {
-      a->contents.next = DynamicStrings_KillString (a->contents.next);
-      a->contents.len = 0;
+      a->contents.next = static_cast<DynamicStrings_String> (DynamicStrings_KillString (a->contents.next));
+      a->contents.len = static_cast<unsigned int> (0);
     }
-  return DynamicStrings_ConCat (a, b);
+  return static_cast<DynamicStrings_String> (DynamicStrings_ConCat (a, b));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -1812,16 +1814,16 @@ DynamicStrings_String DynamicStrings_Assign (DynamicStrings_String a, DynamicStr
    Dup - duplicate a String, s, returning the copy of s.
 */
 
-DynamicStrings_String DynamicStrings_Dup (DynamicStrings_String s)
+extern "C" DynamicStrings_String DynamicStrings_Dup (DynamicStrings_String s)
 {
   if (PoisonOn)
     {
-      s = CheckPoisoned (s);
+      s = static_cast<DynamicStrings_String> (CheckPoisoned (s));
     }
-  s = DynamicStrings_Assign (DynamicStrings_InitString ((char *) "", 0), s);
+  s = static_cast<DynamicStrings_String> (DynamicStrings_Assign (DynamicStrings_InitString ((const char *) "", 0), s));
   if (TraceOn)
     {
-      s = AssignDebug (s, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1173, (char *) "Dup", 3);
+      s = static_cast<DynamicStrings_String> (AssignDebug (s, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1173, (const char *) "Dup", 3));
     }
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -1833,17 +1835,17 @@ DynamicStrings_String DynamicStrings_Dup (DynamicStrings_String s)
    Add - returns a new String which contains the contents of a and b.
 */
 
-DynamicStrings_String DynamicStrings_Add (DynamicStrings_String a, DynamicStrings_String b)
+extern "C" DynamicStrings_String DynamicStrings_Add (DynamicStrings_String a, DynamicStrings_String b)
 {
   if (PoisonOn)
     {
-      a = CheckPoisoned (a);
-      b = CheckPoisoned (b);
+      a = static_cast<DynamicStrings_String> (CheckPoisoned (a));
+      b = static_cast<DynamicStrings_String> (CheckPoisoned (b));
     }
-  a = DynamicStrings_ConCat (DynamicStrings_ConCat (DynamicStrings_InitString ((char *) "", 0), a), b);
+  a = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "", 0), a), b));
   if (TraceOn)
     {
-      a = AssignDebug (a, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1193, (char *) "Add", 3);
+      a = static_cast<DynamicStrings_String> (AssignDebug (a, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1193, (const char *) "Add", 3));
     }
   return a;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -1855,20 +1857,20 @@ DynamicStrings_String DynamicStrings_Add (DynamicStrings_String a, DynamicString
    Equal - returns TRUE if String, a, and, b, are equal.
 */
 
-unsigned int DynamicStrings_Equal (DynamicStrings_String a, DynamicStrings_String b)
+extern "C" unsigned int DynamicStrings_Equal (DynamicStrings_String a, DynamicStrings_String b)
 {
   unsigned int i;
 
   if (PoisonOn)
     {
-      a = CheckPoisoned (a);
-      b = CheckPoisoned (b);
+      a = static_cast<DynamicStrings_String> (CheckPoisoned (a));
+      b = static_cast<DynamicStrings_String> (CheckPoisoned (b));
     }
   if ((DynamicStrings_Length (a)) == (DynamicStrings_Length (b)))
     {
       while ((a != NULL) && (b != NULL))
         {
-          i = 0;
+          i = static_cast<unsigned int> (0);
           Assertion_Assert (a->contents.len == b->contents.len);
           while (i < a->contents.len)
             {
@@ -1907,28 +1909,28 @@ unsigned int DynamicStrings_Equal (DynamicStrings_String a, DynamicStrings_Strin
                    string, a.
 */
 
-unsigned int DynamicStrings_EqualCharStar (DynamicStrings_String s, void * a)
+extern "C" unsigned int DynamicStrings_EqualCharStar (DynamicStrings_String s, void * a)
 {
   DynamicStrings_String t;
 
   if (PoisonOn)
     {
-      s = CheckPoisoned (s);
+      s = static_cast<DynamicStrings_String> (CheckPoisoned (s));
     }
-  t = DynamicStrings_InitStringCharStar (a);
+  t = static_cast<DynamicStrings_String> (DynamicStrings_InitStringCharStar (a));
   if (TraceOn)
     {
-      t = AssignDebug (t, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1258, (char *) "EqualCharStar", 13);
+      t = static_cast<DynamicStrings_String> (AssignDebug (t, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1258, (const char *) "EqualCharStar", 13));
     }
-  t = AddToGarbage (t, s);
+  t = static_cast<DynamicStrings_String> (AddToGarbage (t, s));
   if (DynamicStrings_Equal (t, s))
     {
-      t = DynamicStrings_KillString (t);
+      t = static_cast<DynamicStrings_String> (DynamicStrings_KillString (t));
       return TRUE;
     }
   else
     {
-      t = DynamicStrings_KillString (t);
+      t = static_cast<DynamicStrings_String> (DynamicStrings_KillString (t));
       return FALSE;
     }
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -1941,7 +1943,7 @@ unsigned int DynamicStrings_EqualCharStar (DynamicStrings_String s, void * a)
                 string, a.
 */
 
-unsigned int DynamicStrings_EqualArray (DynamicStrings_String s, char *a_, unsigned int _a_high)
+extern "C" unsigned int DynamicStrings_EqualArray (DynamicStrings_String s, const char *a_, unsigned int _a_high)
 {
   DynamicStrings_String t;
   char a[_a_high+1];
@@ -1951,22 +1953,22 @@ unsigned int DynamicStrings_EqualArray (DynamicStrings_String s, char *a_, unsig
 
   if (PoisonOn)
     {
-      s = CheckPoisoned (s);
+      s = static_cast<DynamicStrings_String> (CheckPoisoned (s));
     }
-  t = DynamicStrings_InitString ((char *) a, _a_high);
+  t = static_cast<DynamicStrings_String> (DynamicStrings_InitString ((const char *) a, _a_high));
   if (TraceOn)
     {
-      t = AssignDebug (t, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1288, (char *) "EqualArray", 10);
+      t = static_cast<DynamicStrings_String> (AssignDebug (t, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1288, (const char *) "EqualArray", 10));
     }
-  t = AddToGarbage (t, s);
+  t = static_cast<DynamicStrings_String> (AddToGarbage (t, s));
   if (DynamicStrings_Equal (t, s))
     {
-      t = DynamicStrings_KillString (t);
+      t = static_cast<DynamicStrings_String> (DynamicStrings_KillString (t));
       return TRUE;
     }
   else
     {
-      t = DynamicStrings_KillString (t);
+      t = static_cast<DynamicStrings_String> (DynamicStrings_KillString (t));
       return FALSE;
     }
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -1978,23 +1980,23 @@ unsigned int DynamicStrings_EqualArray (DynamicStrings_String s, char *a_, unsig
    Mult - returns a new string which is n concatenations of String, s.
 */
 
-DynamicStrings_String DynamicStrings_Mult (DynamicStrings_String s, unsigned int n)
+extern "C" DynamicStrings_String DynamicStrings_Mult (DynamicStrings_String s, unsigned int n)
 {
   if (PoisonOn)
     {
-      s = CheckPoisoned (s);
+      s = static_cast<DynamicStrings_String> (CheckPoisoned (s));
     }
   if (n <= 0)
     {
-      s = AddToGarbage (DynamicStrings_InitString ((char *) "", 0), s);
+      s = static_cast<DynamicStrings_String> (AddToGarbage (DynamicStrings_InitString ((const char *) "", 0), s));
     }
   else
     {
-      s = DynamicStrings_ConCat (DynamicStrings_Mult (s, n-1), s);
+      s = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (DynamicStrings_Mult (s, n-1), s));
     }
   if (TraceOn)
     {
-      s = AssignDebug (s, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1320, (char *) "Mult", 4);
+      s = static_cast<DynamicStrings_String> (AssignDebug (s, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1320, (const char *) "Mult", 4));
     }
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -2014,7 +2016,7 @@ DynamicStrings_String DynamicStrings_Mult (DynamicStrings_String s, unsigned int
            Slice(s, 4, -2) will return elements 4..max-2
 */
 
-DynamicStrings_String DynamicStrings_Slice (DynamicStrings_String s, int low, int high)
+extern "C" DynamicStrings_String DynamicStrings_Slice (DynamicStrings_String s, int low, int high)
 {
   DynamicStrings_String d;
   DynamicStrings_String t;
@@ -2024,24 +2026,24 @@ DynamicStrings_String DynamicStrings_Slice (DynamicStrings_String s, int low, in
 
   if (PoisonOn)
     {
-      s = CheckPoisoned (s);
+      s = static_cast<DynamicStrings_String> (CheckPoisoned (s));
     }
   if (low < 0)
     {
-      low = ((int ) (DynamicStrings_Length (s)))+low;
+      low = static_cast<int> (((int ) (DynamicStrings_Length (s)))+low);
     }
   if (high <= 0)
     {
-      high = ((int ) (DynamicStrings_Length (s)))+high;
+      high = static_cast<int> (((int ) (DynamicStrings_Length (s)))+high);
     }
   else
     {
       /* make sure high is <= Length (s)  */
-      high = Min (DynamicStrings_Length (s), (unsigned int) high);
+      high = static_cast<int> (Min (DynamicStrings_Length (s), static_cast<unsigned int> (high)));
     }
-  d = DynamicStrings_InitString ((char *) "", 0);
-  d = AddToGarbage (d, s);
-  o = 0;
+  d = static_cast<DynamicStrings_String> (DynamicStrings_InitString ((const char *) "", 0));
+  d = static_cast<DynamicStrings_String> (AddToGarbage (d, s));
+  o = static_cast<int> (0);
   t = d;
   while (s != NULL)
     {
@@ -2049,36 +2051,36 @@ DynamicStrings_String DynamicStrings_Slice (DynamicStrings_String s, int low, in
         {
           if (o > high)
             {
-              s = NULL;
+              s = static_cast<DynamicStrings_String> (NULL);
             }
           else
             {
               /* found sliceable unit  */
               if (low < o)
                 {
-                  start = 0;
+                  start = static_cast<int> (0);
                 }
               else
                 {
-                  start = low-o;
+                  start = static_cast<int> (low-o);
                 }
-              end = Max (Min (MaxBuf, (unsigned int) high-o), 0);
+              end = static_cast<int> (Max (Min (MaxBuf, static_cast<unsigned int> (high-o)), 0));
               while (t->contents.len == MaxBuf)
                 {
                   if (t->contents.next == NULL)
                     {
                       Storage_ALLOCATE ((void **) &t->contents.next, sizeof (stringRecord));
-                      t->contents.next->head = NULL;
-                      t->contents.next->contents.len = 0;
+                      t->contents.next->head = static_cast<Descriptor> (NULL);
+                      t->contents.next->contents.len = static_cast<unsigned int> (0);
                       AddDebugInfo (t->contents.next);
                       if (TraceOn)
                         {
-                          t->contents.next = AssignDebug (t->contents.next, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1388, (char *) "Slice", 5);
+                          t->contents.next = static_cast<DynamicStrings_String> (AssignDebug (t->contents.next, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1388, (const char *) "Slice", 5));
                         }
                     }
                   t = t->contents.next;
                 }
-              ConcatContentsAddress (&t->contents, &s->contents.buf.array[start], (unsigned int) end-start);
+              ConcatContentsAddress (&t->contents, &s->contents.buf.array[start], static_cast<unsigned int> (end-start));
               o += s->contents.len;
               s = s->contents.next;
             }
@@ -2091,7 +2093,7 @@ DynamicStrings_String DynamicStrings_Slice (DynamicStrings_String s, int low, in
     }
   if (TraceOn)
     {
-      d = AssignDebug (d, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1405, (char *) "Slice", 5);
+      d = static_cast<DynamicStrings_String> (AssignDebug (d, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1405, (const char *) "Slice", 5));
     }
   return d;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -2105,16 +2107,16 @@ DynamicStrings_String DynamicStrings_Slice (DynamicStrings_String s, int low, in
            The search starts at position, o.
 */
 
-int DynamicStrings_Index (DynamicStrings_String s, char ch, unsigned int o)
+extern "C" int DynamicStrings_Index (DynamicStrings_String s, char ch, unsigned int o)
 {
   unsigned int i;
   unsigned int k;
 
   if (PoisonOn)
     {
-      s = CheckPoisoned (s);
+      s = static_cast<DynamicStrings_String> (CheckPoisoned (s));
     }
-  k = 0;
+  k = static_cast<unsigned int> (0);
   while (s != NULL)
     {
       if ((k+s->contents.len) < o)
@@ -2123,12 +2125,12 @@ int DynamicStrings_Index (DynamicStrings_String s, char ch, unsigned int o)
         }
       else
         {
-          i = o-k;
+          i = static_cast<unsigned int> (o-k);
           while (i < s->contents.len)
             {
               if (s->contents.buf.array[i] == ch)
                 {
-                  return k+i;
+                  return static_cast<int> (k+i);
                 }
               i += 1;
             }
@@ -2137,7 +2139,7 @@ int DynamicStrings_Index (DynamicStrings_String s, char ch, unsigned int o)
         }
       s = s->contents.next;
     }
-  return -1;
+  return static_cast<int> (-1);
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -2149,7 +2151,7 @@ int DynamicStrings_Index (DynamicStrings_String s, char ch, unsigned int o)
             -1 is returned if, ch, is not found.
 */
 
-int DynamicStrings_RIndex (DynamicStrings_String s, char ch, unsigned int o)
+extern "C" int DynamicStrings_RIndex (DynamicStrings_String s, char ch, unsigned int o)
 {
   unsigned int i;
   unsigned int k;
@@ -2157,10 +2159,10 @@ int DynamicStrings_RIndex (DynamicStrings_String s, char ch, unsigned int o)
 
   if (PoisonOn)
     {
-      s = CheckPoisoned (s);
+      s = static_cast<DynamicStrings_String> (CheckPoisoned (s));
     }
-  j = -1;
-  k = 0;
+  j = static_cast<int> (-1);
+  k = static_cast<unsigned int> (0);
   while (s != NULL)
     {
       if ((k+s->contents.len) < o)
@@ -2171,17 +2173,17 @@ int DynamicStrings_RIndex (DynamicStrings_String s, char ch, unsigned int o)
         {
           if (o < k)
             {
-              i = 0;
+              i = static_cast<unsigned int> (0);
             }
           else
             {
-              i = o-k;
+              i = static_cast<unsigned int> (o-k);
             }
           while (i < s->contents.len)
             {
               if (s->contents.buf.array[i] == ch)
                 {
-                  j = k;
+                  j = static_cast<int> (k);
                 }
               k += 1;
               i += 1;
@@ -2203,23 +2205,23 @@ int DynamicStrings_RIndex (DynamicStrings_String s, char ch, unsigned int o)
                    It leaves any white space on the left hand side alone.
 */
 
-DynamicStrings_String DynamicStrings_RemoveComment (DynamicStrings_String s, char comment)
+extern "C" DynamicStrings_String DynamicStrings_RemoveComment (DynamicStrings_String s, char comment)
 {
   int i;
 
-  i = DynamicStrings_Index (s, comment, 0);
+  i = static_cast<int> (DynamicStrings_Index (s, comment, 0));
   if (i == 0)
     {
-      s = DynamicStrings_InitString ((char *) "", 0);
+      s = static_cast<DynamicStrings_String> (DynamicStrings_InitString ((const char *) "", 0));
     }
   else if (i > 0)
     {
       /* avoid dangling else.  */
-      s = DynamicStrings_RemoveWhitePostfix (DynamicStrings_Slice (DynamicStrings_Mark (s), 0, i));
+      s = static_cast<DynamicStrings_String> (DynamicStrings_RemoveWhitePostfix (DynamicStrings_Slice (DynamicStrings_Mark (s), 0, i)));
     }
   if (TraceOn)
     {
-      s = AssignDebug (s, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1517, (char *) "RemoveComment", 13);
+      s = static_cast<DynamicStrings_String> (AssignDebug (s, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1517, (const char *) "RemoveComment", 13));
     }
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -2232,19 +2234,19 @@ DynamicStrings_String DynamicStrings_RemoveComment (DynamicStrings_String s, cha
                        A new string is returned.
 */
 
-DynamicStrings_String DynamicStrings_RemoveWhitePrefix (DynamicStrings_String s)
+extern "C" DynamicStrings_String DynamicStrings_RemoveWhitePrefix (DynamicStrings_String s)
 {
   unsigned int i;
 
-  i = 0;
-  while (IsWhite (DynamicStrings_char (s, (int) i)))
+  i = static_cast<unsigned int> (0);
+  while (IsWhite (DynamicStrings_char (s, static_cast<int> (i))))
     {
       i += 1;
     }
-  s = DynamicStrings_Slice (s, (int ) (i), 0);
+  s = static_cast<DynamicStrings_String> (DynamicStrings_Slice (s, (int ) (i), 0));
   if (TraceOn)
     {
-      s = AssignDebug (s, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1629, (char *) "RemoveWhitePrefix", 17);
+      s = static_cast<DynamicStrings_String> (AssignDebug (s, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1629, (const char *) "RemoveWhitePrefix", 17));
     }
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -2257,19 +2259,19 @@ DynamicStrings_String DynamicStrings_RemoveWhitePrefix (DynamicStrings_String s)
                         A new string is returned.
 */
 
-DynamicStrings_String DynamicStrings_RemoveWhitePostfix (DynamicStrings_String s)
+extern "C" DynamicStrings_String DynamicStrings_RemoveWhitePostfix (DynamicStrings_String s)
 {
   int i;
 
-  i = ((int ) (DynamicStrings_Length (s)))-1;
+  i = static_cast<int> (((int ) (DynamicStrings_Length (s)))-1);
   while ((i >= 0) && (IsWhite (DynamicStrings_char (s, i))))
     {
       i -= 1;
     }
-  s = DynamicStrings_Slice (s, 0, i+1);
+  s = static_cast<DynamicStrings_String> (DynamicStrings_Slice (s, 0, i+1));
   if (TraceOn)
     {
-      s = AssignDebug (s, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1651, (char *) "RemoveWhitePostfix", 18);
+      s = static_cast<DynamicStrings_String> (AssignDebug (s, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 1651, (const char *) "RemoveWhitePostfix", 18));
     }
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -2283,7 +2285,7 @@ DynamicStrings_String DynamicStrings_RemoveWhitePostfix (DynamicStrings_String s
              The string, s, is not duplicated.
 */
 
-DynamicStrings_String DynamicStrings_ToUpper (DynamicStrings_String s)
+extern "C" DynamicStrings_String DynamicStrings_ToUpper (DynamicStrings_String s)
 {
   char ch;
   unsigned int i;
@@ -2295,7 +2297,7 @@ DynamicStrings_String DynamicStrings_ToUpper (DynamicStrings_String s)
       t = s;
       while (t != NULL)
         {
-          i = 0;
+          i = static_cast<unsigned int> (0);
           while (i < t->contents.len)
             {
               ch = t->contents.buf.array[i];
@@ -2320,7 +2322,7 @@ DynamicStrings_String DynamicStrings_ToUpper (DynamicStrings_String s)
              The string, s, is not duplicated.
 */
 
-DynamicStrings_String DynamicStrings_ToLower (DynamicStrings_String s)
+extern "C" DynamicStrings_String DynamicStrings_ToLower (DynamicStrings_String s)
 {
   char ch;
   unsigned int i;
@@ -2332,7 +2334,7 @@ DynamicStrings_String DynamicStrings_ToLower (DynamicStrings_String s)
       t = s;
       while (t != NULL)
         {
-          i = 0;
+          i = static_cast<unsigned int> (0);
           while (i < t->contents.len)
             {
               ch = t->contents.buf.array[i];
@@ -2355,16 +2357,16 @@ DynamicStrings_String DynamicStrings_ToLower (DynamicStrings_String s)
    CopyOut - copies string, s, to a.
 */
 
-void DynamicStrings_CopyOut (char *a, unsigned int _a_high, DynamicStrings_String s)
+extern "C" void DynamicStrings_CopyOut (char *a, unsigned int _a_high, DynamicStrings_String s)
 {
   unsigned int i;
   unsigned int l;
 
-  l = Min (_a_high+1, DynamicStrings_Length (s));
-  i = 0;
+  l = static_cast<unsigned int> (Min (_a_high+1, DynamicStrings_Length (s)));
+  i = static_cast<unsigned int> (0);
   while (i < l)
     {
-      a[i] = DynamicStrings_char (s, (int) i);
+      a[i] = static_cast<char> (DynamicStrings_char (s, static_cast<int> (i)));
       i += 1;
     }
   if (i <= _a_high)
@@ -2378,13 +2380,13 @@ void DynamicStrings_CopyOut (char *a, unsigned int _a_high, DynamicStrings_Strin
    char - returns the character, ch, at position, i, in String, s.
 */
 
-char DynamicStrings_char (DynamicStrings_String s, int i)
+extern "C" char DynamicStrings_char (DynamicStrings_String s, int i)
 {
   unsigned int c;
 
   if (PoisonOn)
     {
-      s = CheckPoisoned (s);
+      s = static_cast<DynamicStrings_String> (CheckPoisoned (s));
     }
   if (i < 0)
     {
@@ -2392,7 +2394,7 @@ char DynamicStrings_char (DynamicStrings_String s, int i)
     }
   else
     {
-      c = i;
+      c = static_cast<unsigned int> (i);
     }
   while ((s != NULL) && (c >= s->contents.len))
     {
@@ -2416,16 +2418,18 @@ char DynamicStrings_char (DynamicStrings_String s, int i)
    string - returns the C style char * of String, s.
 */
 
-void * DynamicStrings_string (DynamicStrings_String s)
+extern "C" void * DynamicStrings_string (DynamicStrings_String s)
 {
+  typedef char *_T2;
+
   DynamicStrings_String a;
   unsigned int l;
   unsigned int i;
-  char * p;
+  _T2 p;
 
   if (PoisonOn)
     {
-      s = CheckPoisoned (s);
+      s = static_cast<DynamicStrings_String> (CheckPoisoned (s));
     }
   if (s == NULL)
     {
@@ -2435,19 +2439,19 @@ void * DynamicStrings_string (DynamicStrings_String s)
     {
       if (! s->head->charStarValid)
         {
-          l = DynamicStrings_Length (s);
+          l = static_cast<unsigned int> (DynamicStrings_Length (s));
           if (! (s->head->charStarUsed && (s->head->charStarSize > l)))
             {
               DeallocateCharStar (s);
               Storage_ALLOCATE (&s->head->charStar, l+1);
-              s->head->charStarSize = l+1;
+              s->head->charStarSize = static_cast<unsigned int> (l+1);
               s->head->charStarUsed = TRUE;
             }
-          p = s->head->charStar;
+          p = static_cast<_T2> (s->head->charStar);
           a = s;
           while (a != NULL)
             {
-              i = 0;
+              i = static_cast<unsigned int> (0);
               while (i < a->contents.len)
                 {
                   (*p) = a->contents.buf.array[i];
@@ -2470,7 +2474,7 @@ void * DynamicStrings_string (DynamicStrings_String s)
    InitStringDB - the debug version of InitString.
 */
 
-DynamicStrings_String DynamicStrings_InitStringDB (char *a_, unsigned int _a_high, char *file_, unsigned int _file_high, unsigned int line)
+extern "C" DynamicStrings_String DynamicStrings_InitStringDB (const char *a_, unsigned int _a_high, const char *file_, unsigned int _file_high, unsigned int line)
 {
   char a[_a_high+1];
   char file[_file_high+1];
@@ -2479,7 +2483,7 @@ DynamicStrings_String DynamicStrings_InitStringDB (char *a_, unsigned int _a_hig
   memcpy (a, a_, _a_high+1);
   memcpy (file, file_, _file_high+1);
 
-  return AssignDebug (DynamicStrings_InitString ((char *) a, _a_high), (char *) file, _file_high, line, (char *) "InitString", 10);
+  return static_cast<DynamicStrings_String> (AssignDebug (DynamicStrings_InitString ((const char *) a, _a_high), (const char *) file, _file_high, line, (const char *) "InitString", 10));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -2489,14 +2493,14 @@ DynamicStrings_String DynamicStrings_InitStringDB (char *a_, unsigned int _a_hig
    InitStringCharStarDB - the debug version of InitStringCharStar.
 */
 
-DynamicStrings_String DynamicStrings_InitStringCharStarDB (void * a, char *file_, unsigned int _file_high, unsigned int line)
+extern "C" DynamicStrings_String DynamicStrings_InitStringCharStarDB (void * a, const char *file_, unsigned int _file_high, unsigned int line)
 {
   char file[_file_high+1];
 
   /* make a local copy of each unbounded array.  */
   memcpy (file, file_, _file_high+1);
 
-  return AssignDebug (DynamicStrings_InitStringCharStar (a), (char *) file, _file_high, line, (char *) "InitStringCharStar", 18);
+  return static_cast<DynamicStrings_String> (AssignDebug (DynamicStrings_InitStringCharStar (a), (const char *) file, _file_high, line, (const char *) "InitStringCharStar", 18));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -2506,14 +2510,14 @@ DynamicStrings_String DynamicStrings_InitStringCharStarDB (void * a, char *file_
    InitStringCharDB - the debug version of InitStringChar.
 */
 
-DynamicStrings_String DynamicStrings_InitStringCharDB (char ch, char *file_, unsigned int _file_high, unsigned int line)
+extern "C" DynamicStrings_String DynamicStrings_InitStringCharDB (char ch, const char *file_, unsigned int _file_high, unsigned int line)
 {
   char file[_file_high+1];
 
   /* make a local copy of each unbounded array.  */
   memcpy (file, file_, _file_high+1);
 
-  return AssignDebug (DynamicStrings_InitStringChar (ch), (char *) file, _file_high, line, (char *) "InitStringChar", 14);
+  return static_cast<DynamicStrings_String> (AssignDebug (DynamicStrings_InitStringChar (ch), (const char *) file, _file_high, line, (const char *) "InitStringChar", 14));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -2523,14 +2527,14 @@ DynamicStrings_String DynamicStrings_InitStringCharDB (char ch, char *file_, uns
    MultDB - the debug version of MultDB.
 */
 
-DynamicStrings_String DynamicStrings_MultDB (DynamicStrings_String s, unsigned int n, char *file_, unsigned int _file_high, unsigned int line)
+extern "C" DynamicStrings_String DynamicStrings_MultDB (DynamicStrings_String s, unsigned int n, const char *file_, unsigned int _file_high, unsigned int line)
 {
   char file[_file_high+1];
 
   /* make a local copy of each unbounded array.  */
   memcpy (file, file_, _file_high+1);
 
-  return AssignDebug (DynamicStrings_Mult (s, n), (char *) file, _file_high, line, (char *) "Mult", 4);
+  return static_cast<DynamicStrings_String> (AssignDebug (DynamicStrings_Mult (s, n), (const char *) file, _file_high, line, (const char *) "Mult", 4));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -2540,14 +2544,14 @@ DynamicStrings_String DynamicStrings_MultDB (DynamicStrings_String s, unsigned i
    DupDB - the debug version of Dup.
 */
 
-DynamicStrings_String DynamicStrings_DupDB (DynamicStrings_String s, char *file_, unsigned int _file_high, unsigned int line)
+extern "C" DynamicStrings_String DynamicStrings_DupDB (DynamicStrings_String s, const char *file_, unsigned int _file_high, unsigned int line)
 {
   char file[_file_high+1];
 
   /* make a local copy of each unbounded array.  */
   memcpy (file, file_, _file_high+1);
 
-  return AssignDebug (DynamicStrings_Dup (s), (char *) file, _file_high, line, (char *) "Dup", 3);
+  return static_cast<DynamicStrings_String> (AssignDebug (DynamicStrings_Dup (s), (const char *) file, _file_high, line, (const char *) "Dup", 3));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -2557,7 +2561,7 @@ DynamicStrings_String DynamicStrings_DupDB (DynamicStrings_String s, char *file_
    SliceDB - debug version of Slice.
 */
 
-DynamicStrings_String DynamicStrings_SliceDB (DynamicStrings_String s, int low, int high, char *file_, unsigned int _file_high, unsigned int line)
+extern "C" DynamicStrings_String DynamicStrings_SliceDB (DynamicStrings_String s, int low, int high, const char *file_, unsigned int _file_high, unsigned int line)
 {
   char file[_file_high+1];
 
@@ -2565,7 +2569,7 @@ DynamicStrings_String DynamicStrings_SliceDB (DynamicStrings_String s, int low,
   memcpy (file, file_, _file_high+1);
 
   DSdbEnter ();
-  s = AssignDebug (DynamicStrings_Slice (s, low, high), (char *) file, _file_high, line, (char *) "Slice", 5);
+  s = static_cast<DynamicStrings_String> (AssignDebug (DynamicStrings_Slice (s, low, high), (const char *) file, _file_high, line, (const char *) "Slice", 5));
   DSdbExit (s);
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -2577,7 +2581,7 @@ DynamicStrings_String DynamicStrings_SliceDB (DynamicStrings_String s, int low,
    PushAllocation - pushes the current allocation/deallocation lists.
 */
 
-void DynamicStrings_PushAllocation (void)
+extern "C" void DynamicStrings_PushAllocation (void)
 {
   frame f;
 
@@ -2586,8 +2590,8 @@ void DynamicStrings_PushAllocation (void)
       Init ();
       Storage_ALLOCATE ((void **) &f, sizeof (frameRec));
       f->next = frameHead;
-      f->alloc = NULL;
-      f->dealloc = NULL;
+      f->alloc = static_cast<DynamicStrings_String> (NULL);
+      f->dealloc = static_cast<DynamicStrings_String> (NULL);
       frameHead = f;
     }
 }
@@ -2602,11 +2606,11 @@ void DynamicStrings_PushAllocation (void)
                    with an exit code of 1.
 */
 
-void DynamicStrings_PopAllocation (unsigned int halt)
+extern "C" void DynamicStrings_PopAllocation (unsigned int halt)
 {
   if (CheckOn)
     {
-      if ((DynamicStrings_PopAllocationExemption (halt, (DynamicStrings_String) NULL)) == NULL)
+      if ((DynamicStrings_PopAllocationExemption (halt, reinterpret_cast<DynamicStrings_String> (NULL))) == NULL)
         {}  /* empty.  */
     }
 }
@@ -2622,7 +2626,7 @@ void DynamicStrings_PopAllocation (unsigned int halt)
                             with an exit code of 1.
 */
 
-DynamicStrings_String DynamicStrings_PopAllocationExemption (unsigned int halt, DynamicStrings_String e)
+extern "C" DynamicStrings_String DynamicStrings_PopAllocationExemption (unsigned int halt, DynamicStrings_String e)
 {
   DynamicStrings_String s;
   frame f;
@@ -2636,7 +2640,7 @@ DynamicStrings_String DynamicStrings_PopAllocationExemption (unsigned int halt,
         {
           stop ();
           /* writeString ("mismatched number of PopAllocation's compared to PushAllocation's")  */
-          M2RTS_Halt ((char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 176, (char *) "PopAllocationExemption", 22, (char *) "mismatched number of PopAllocation's compared to PushAllocation's", 65);
+          M2RTS_Halt ((const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/DynamicStrings.mod", 86, 176, (const char *) "PopAllocationExemption", 22, (const char *) "mismatched number of PopAllocation's compared to PushAllocation's", 65);
         }
       else
         {
@@ -2650,7 +2654,7 @@ DynamicStrings_String DynamicStrings_PopAllocationExemption (unsigned int halt,
                     {
                       if (! b)
                         {
-                          writeString ((char *) "the following strings have been lost", 36);
+                          writeString ((const char *) "the following strings have been lost", 36);
                           writeLn ();
                           b = TRUE;
                         }
@@ -2671,12 +2675,12 @@ DynamicStrings_String DynamicStrings_PopAllocationExemption (unsigned int halt,
   __builtin_unreachable ();
 }
 
-void _M2_DynamicStrings_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_DynamicStrings_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
   Initialized = FALSE;
   Init ();
 }
 
-void _M2_DynamicStrings_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_DynamicStrings_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GDynamicStrings.h b/gcc/m2/mc-boot/GDynamicStrings.h
index 9720e44f436..d09e847df08 100644
--- a/gcc/m2/mc-boot/GDynamicStrings.h
+++ b/gcc/m2/mc-boot/GDynamicStrings.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_DynamicStrings_H)
 #   define _DynamicStrings_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
@@ -59,7 +59,7 @@ extern "C" {
                 Initial contents are, a.
 */
 
-EXTERN DynamicStrings_String DynamicStrings_InitString (char *a_, unsigned int _a_high);
+EXTERN DynamicStrings_String DynamicStrings_InitString (const char *a_, unsigned int _a_high);
 
 /*
    KillString - frees String, s, and its contents.
@@ -149,7 +149,7 @@ EXTERN unsigned int DynamicStrings_EqualCharStar (DynamicStrings_String s, void
                 string, a.
 */
 
-EXTERN unsigned int DynamicStrings_EqualArray (DynamicStrings_String s, char *a_, unsigned int _a_high);
+EXTERN unsigned int DynamicStrings_EqualArray (DynamicStrings_String s, const char *a_, unsigned int _a_high);
 
 /*
    Mult - returns a new string which is n concatenations of String, s.
@@ -258,37 +258,37 @@ EXTERN void * DynamicStrings_string (DynamicStrings_String s);
    InitStringDB - the debug version of InitString.
 */
 
-EXTERN DynamicStrings_String DynamicStrings_InitStringDB (char *a_, unsigned int _a_high, char *file_, unsigned int _file_high, unsigned int line);
+EXTERN DynamicStrings_String DynamicStrings_InitStringDB (const char *a_, unsigned int _a_high, const char *file_, unsigned int _file_high, unsigned int line);
 
 /*
    InitStringCharStarDB - the debug version of InitStringCharStar.
 */
 
-EXTERN DynamicStrings_String DynamicStrings_InitStringCharStarDB (void * a, char *file_, unsigned int _file_high, unsigned int line);
+EXTERN DynamicStrings_String DynamicStrings_InitStringCharStarDB (void * a, const char *file_, unsigned int _file_high, unsigned int line);
 
 /*
    InitStringCharDB - the debug version of InitStringChar.
 */
 
-EXTERN DynamicStrings_String DynamicStrings_InitStringCharDB (char ch, char *file_, unsigned int _file_high, unsigned int line);
+EXTERN DynamicStrings_String DynamicStrings_InitStringCharDB (char ch, const char *file_, unsigned int _file_high, unsigned int line);
 
 /*
    MultDB - the debug version of MultDB.
 */
 
-EXTERN DynamicStrings_String DynamicStrings_MultDB (DynamicStrings_String s, unsigned int n, char *file_, unsigned int _file_high, unsigned int line);
+EXTERN DynamicStrings_String DynamicStrings_MultDB (DynamicStrings_String s, unsigned int n, const char *file_, unsigned int _file_high, unsigned int line);
 
 /*
    DupDB - the debug version of Dup.
 */
 
-EXTERN DynamicStrings_String DynamicStrings_DupDB (DynamicStrings_String s, char *file_, unsigned int _file_high, unsigned int line);
+EXTERN DynamicStrings_String DynamicStrings_DupDB (DynamicStrings_String s, const char *file_, unsigned int _file_high, unsigned int line);
 
 /*
    SliceDB - debug version of Slice.
 */
 
-EXTERN DynamicStrings_String DynamicStrings_SliceDB (DynamicStrings_String s, int low, int high, char *file_, unsigned int _file_high, unsigned int line);
+EXTERN DynamicStrings_String DynamicStrings_SliceDB (DynamicStrings_String s, int low, int high, const char *file_, unsigned int _file_high, unsigned int line);
 
 /*
    PushAllocation - pushes the current allocation/deallocation lists.
diff --git a/gcc/m2/mc-boot/GEnvironment.c b/gcc/m2/mc-boot/GEnvironment.c
index ccaf432bc99..ade68ad2f05 100644
--- a/gcc/m2/mc-boot/GEnvironment.c
+++ b/gcc/m2/mc-boot/GEnvironment.c
@@ -51,7 +51,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
       	       	    a copy of its value into string, a.
 */
 
-unsigned int Environment_GetEnvironment (char *Env_, unsigned int _Env_high, char *a, unsigned int _a_high);
+extern "C" unsigned int Environment_GetEnvironment (const char *Env_, unsigned int _Env_high, char *a, unsigned int _a_high);
 
 
 /*
@@ -59,19 +59,21 @@ unsigned int Environment_GetEnvironment (char *Env_, unsigned int _Env_high, cha
       	       	    a copy of its value into string, a.
 */
 
-unsigned int Environment_GetEnvironment (char *Env_, unsigned int _Env_high, char *a, unsigned int _a_high)
+extern "C" unsigned int Environment_GetEnvironment (const char *Env_, unsigned int _Env_high, char *a, unsigned int _a_high)
 {
+  typedef char *_T1;
+
   unsigned int High;
   unsigned int i;
-  char * Addr;
+  _T1 Addr;
   char Env[_Env_high+1];
 
   /* make a local copy of each unbounded array.  */
   memcpy (Env, Env_, _Env_high+1);
 
-  i = 0;
+  i = static_cast<unsigned int> (0);
   High = _a_high;
-  Addr = libc_getenv (&Env);
+  Addr = static_cast<_T1> (libc_getenv (&Env));
   while (((i < High) && (Addr != NULL)) && ((*Addr) != ASCII_nul))
     {
       a[i] = (*Addr);
@@ -87,10 +89,10 @@ unsigned int Environment_GetEnvironment (char *Env_, unsigned int _Env_high, cha
   __builtin_unreachable ();
 }
 
-void _M2_Environment_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_Environment_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_Environment_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_Environment_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GEnvironment.h b/gcc/m2/mc-boot/GEnvironment.h
index b0f7e851ebc..6c662aab457 100644
--- a/gcc/m2/mc-boot/GEnvironment.h
+++ b/gcc/m2/mc-boot/GEnvironment.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_Environment_H)
 #   define _Environment_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
@@ -53,7 +53,7 @@ extern "C" {
       	       	    a copy of its value into string, a.
 */
 
-EXTERN unsigned int Environment_GetEnvironment (char *Env_, unsigned int _Env_high, char *a, unsigned int _a_high);
+EXTERN unsigned int Environment_GetEnvironment (const char *Env_, unsigned int _Env_high, char *a, unsigned int _a_high);
 #   ifdef __cplusplus
 }
 #   endif
diff --git a/gcc/m2/mc-boot/GFIO.c b/gcc/m2/mc-boot/GFIO.c
index 75ec3898cf1..89ed76e91f3 100644
--- a/gcc/m2/mc-boot/GFIO.c
+++ b/gcc/m2/mc-boot/GFIO.c
@@ -81,7 +81,7 @@ typedef struct fds_r fds;
 
 typedef fds *FileDescriptor;
 
-typedef struct _T1_a _T1;
+typedef struct _T7_a _T7;
 
 typedef char *PtrToChar;
 
@@ -102,10 +102,10 @@ struct buf_r {
                unsigned int filled;
                unsigned int size;
                unsigned int left;
-               _T1 *contents;
+               _T7 *contents;
              };
 
-struct _T1_a { char array[MaxBufferLength+1]; };
+struct _T7_a { char array[MaxBufferLength+1]; };
 struct fds_r {
                int unixfd;
                NameInfo name;
@@ -123,17 +123,17 @@ static FIO_File Error;
    IsNoError - returns a TRUE if no error has occured on file, f.
 */
 
-unsigned int FIO_IsNoError (FIO_File f);
+extern "C" unsigned int FIO_IsNoError (FIO_File f);
 
 /*
    IsActive - returns TRUE if the file, f, is still active.
 */
 
-unsigned int FIO_IsActive (FIO_File f);
-unsigned int FIO_Exists (char *fname_, unsigned int _fname_high);
-FIO_File FIO_OpenToRead (char *fname_, unsigned int _fname_high);
-FIO_File FIO_OpenToWrite (char *fname_, unsigned int _fname_high);
-FIO_File FIO_OpenForRandom (char *fname_, unsigned int _fname_high, unsigned int towrite, unsigned int newfile);
+extern "C" unsigned int FIO_IsActive (FIO_File f);
+extern "C" unsigned int FIO_Exists (const char *fname_, unsigned int _fname_high);
+extern "C" FIO_File FIO_OpenToRead (const char *fname_, unsigned int _fname_high);
+extern "C" FIO_File FIO_OpenToWrite (const char *fname_, unsigned int _fname_high);
+extern "C" FIO_File FIO_OpenForRandom (const char *fname_, unsigned int _fname_high, unsigned int towrite, unsigned int newfile);
 
 /*
    Close - close a file which has been previously opened using:
@@ -141,13 +141,13 @@ FIO_File FIO_OpenForRandom (char *fname_, unsigned int _fname_high, unsigned int
            It is correct to close a file which has an error status.
 */
 
-void FIO_Close (FIO_File f);
+extern "C" void FIO_Close (FIO_File f);
 
 /*
    exists - returns TRUE if a file named, fname exists for reading.
 */
 
-unsigned int FIO_exists (void * fname, unsigned int flength);
+extern "C" unsigned int FIO_exists (void * fname, unsigned int flength);
 
 /*
    openToRead - attempts to open a file, fname, for reading and
@@ -156,7 +156,7 @@ unsigned int FIO_exists (void * fname, unsigned int flength);
                 calling IsNoError.
 */
 
-FIO_File FIO_openToRead (void * fname, unsigned int flength);
+extern "C" FIO_File FIO_openToRead (void * fname, unsigned int flength);
 
 /*
    openToWrite - attempts to open a file, fname, for write and
@@ -165,7 +165,7 @@ FIO_File FIO_openToRead (void * fname, unsigned int flength);
                  calling IsNoError.
 */
 
-FIO_File FIO_openToWrite (void * fname, unsigned int flength);
+extern "C" FIO_File FIO_openToWrite (void * fname, unsigned int flength);
 
 /*
    openForRandom - attempts to open a file, fname, for random access
@@ -176,13 +176,13 @@ FIO_File FIO_openToWrite (void * fname, unsigned int flength);
                    opened for writing or reading.
 */
 
-FIO_File FIO_openForRandom (void * fname, unsigned int flength, unsigned int towrite, unsigned int newfile);
+extern "C" FIO_File FIO_openForRandom (void * fname, unsigned int flength, unsigned int towrite, unsigned int newfile);
 
 /*
    FlushBuffer - flush contents of file, f.
 */
 
-void FIO_FlushBuffer (FIO_File f);
+extern "C" void FIO_FlushBuffer (FIO_File f);
 
 /*
    ReadNBytes - reads nBytes of a file into memory area, a, returning
@@ -191,7 +191,7 @@ void FIO_FlushBuffer (FIO_File f);
                 perform direct libc reads. It is ideal for large reads.
 */
 
-unsigned int FIO_ReadNBytes (FIO_File f, unsigned int nBytes, void * a);
+extern "C" unsigned int FIO_ReadNBytes (FIO_File f, unsigned int nBytes, void * a);
 
 /*
    ReadAny - reads HIGH(a) bytes into, a. All input
@@ -199,7 +199,7 @@ unsigned int FIO_ReadNBytes (FIO_File f, unsigned int nBytes, void * a);
              suited to small reads.
 */
 
-void FIO_ReadAny (FIO_File f, unsigned char *a, unsigned int _a_high);
+extern "C" void FIO_ReadAny (FIO_File f, unsigned char *a, unsigned int _a_high);
 
 /*
    WriteNBytes - writes nBytes of a file into memory area, a, returning
@@ -209,7 +209,7 @@ void FIO_ReadAny (FIO_File f, unsigned char *a, unsigned int _a_high);
                  It is ideal for large writes.
 */
 
-unsigned int FIO_WriteNBytes (FIO_File f, unsigned int nBytes, void * a);
+extern "C" unsigned int FIO_WriteNBytes (FIO_File f, unsigned int nBytes, void * a);
 
 /*
    WriteAny - writes HIGH(a) bytes onto, file, f. All output
@@ -217,32 +217,32 @@ unsigned int FIO_WriteNBytes (FIO_File f, unsigned int nBytes, void * a);
               suited to small writes.
 */
 
-void FIO_WriteAny (FIO_File f, unsigned char *a, unsigned int _a_high);
+extern "C" void FIO_WriteAny (FIO_File f, unsigned char *a, unsigned int _a_high);
 
 /*
    WriteChar - writes a single character to file, f.
 */
 
-void FIO_WriteChar (FIO_File f, char ch);
+extern "C" void FIO_WriteChar (FIO_File f, char ch);
 
 /*
    EOF - tests to see whether a file, f, has reached end of file.
 */
 
-unsigned int FIO_EOF (FIO_File f);
+extern "C" unsigned int FIO_EOF (FIO_File f);
 
 /*
    EOLN - tests to see whether a file, f, is upon a newline.
           It does NOT consume the newline.
 */
 
-unsigned int FIO_EOLN (FIO_File f);
+extern "C" unsigned int FIO_EOLN (FIO_File f);
 
 /*
    WasEOLN - tests to see whether a file, f, has just seen a newline.
 */
 
-unsigned int FIO_WasEOLN (FIO_File f);
+extern "C" unsigned int FIO_WasEOLN (FIO_File f);
 
 /*
    ReadChar - returns a character read from file, f.
@@ -250,7 +250,7 @@ unsigned int FIO_WasEOLN (FIO_File f);
               this function.
 */
 
-char FIO_ReadChar (FIO_File f);
+extern "C" char FIO_ReadChar (FIO_File f);
 
 /*
    UnReadChar - replaces a character, ch, back into file, f.
@@ -263,19 +263,19 @@ char FIO_ReadChar (FIO_File f);
                 Otherwise it is left alone.
 */
 
-void FIO_UnReadChar (FIO_File f, char ch);
+extern "C" void FIO_UnReadChar (FIO_File f, char ch);
 
 /*
    WriteLine - writes out a linefeed to file, f.
 */
 
-void FIO_WriteLine (FIO_File f);
+extern "C" void FIO_WriteLine (FIO_File f);
 
 /*
    WriteString - writes a string to file, f.
 */
 
-void FIO_WriteString (FIO_File f, char *a_, unsigned int _a_high);
+extern "C" void FIO_WriteString (FIO_File f, const char *a_, unsigned int _a_high);
 
 /*
    ReadString - reads a string from file, f, into string, a.
@@ -283,7 +283,7 @@ void FIO_WriteString (FIO_File f, char *a_, unsigned int _a_high);
                 if a newline is seen or an error occurs.
 */
 
-void FIO_ReadString (FIO_File f, char *a, unsigned int _a_high);
+extern "C" void FIO_ReadString (FIO_File f, char *a, unsigned int _a_high);
 
 /*
    WriteCardinal - writes a CARDINAL to file, f.
@@ -291,7 +291,7 @@ void FIO_ReadString (FIO_File f, char *a, unsigned int _a_high);
                    to file, f.
 */
 
-void FIO_WriteCardinal (FIO_File f, unsigned int c);
+extern "C" void FIO_WriteCardinal (FIO_File f, unsigned int c);
 
 /*
    ReadCardinal - reads a CARDINAL from file, f.
@@ -299,49 +299,49 @@ void FIO_WriteCardinal (FIO_File f, unsigned int c);
                   from a file, f.
 */
 
-unsigned int FIO_ReadCardinal (FIO_File f);
+extern "C" unsigned int FIO_ReadCardinal (FIO_File f);
 
 /*
    GetUnixFileDescriptor - returns the UNIX file descriptor of a file.
 */
 
-int FIO_GetUnixFileDescriptor (FIO_File f);
+extern "C" int FIO_GetUnixFileDescriptor (FIO_File f);
 
 /*
    SetPositionFromBeginning - sets the position from the beginning of the file.
 */
 
-void FIO_SetPositionFromBeginning (FIO_File f, long int pos);
+extern "C" void FIO_SetPositionFromBeginning (FIO_File f, long int pos);
 
 /*
    SetPositionFromEnd - sets the position from the end of the file.
 */
 
-void FIO_SetPositionFromEnd (FIO_File f, long int pos);
+extern "C" void FIO_SetPositionFromEnd (FIO_File f, long int pos);
 
 /*
    FindPosition - returns the current absolute position in file, f.
 */
 
-long int FIO_FindPosition (FIO_File f);
+extern "C" long int FIO_FindPosition (FIO_File f);
 
 /*
    GetFileName - assigns, a, with the filename associated with, f.
 */
 
-void FIO_GetFileName (FIO_File f, char *a, unsigned int _a_high);
+extern "C" void FIO_GetFileName (FIO_File f, char *a, unsigned int _a_high);
 
 /*
    getFileName - returns the address of the filename associated with, f.
 */
 
-void * FIO_getFileName (FIO_File f);
+extern "C" void * FIO_getFileName (FIO_File f);
 
 /*
    getFileNameLength - returns the number of characters associated with filename, f.
 */
 
-unsigned int FIO_getFileNameLength (FIO_File f);
+extern "C" unsigned int FIO_getFileNameLength (FIO_File f);
 
 /*
    FlushOutErr - flushes, StdOut, and, StdErr.
@@ -350,7 +350,7 @@ unsigned int FIO_getFileNameLength (FIO_File f);
                  scaffold).
 */
 
-void FIO_FlushOutErr (void);
+extern "C" void FIO_FlushOutErr (void);
 
 /*
    Max - returns the maximum of two values.
@@ -416,38 +416,38 @@ static int BufferedRead (FIO_File f, unsigned int nBytes, void * a);
  and \t into their respective ascii codes.
 */
 
-static void HandleEscape (char *dest, unsigned int _dest_high, char *src_, unsigned int _src_high, unsigned int *i, unsigned int *j, unsigned int HighSrc, unsigned int HighDest);
+static void HandleEscape (char *dest, unsigned int _dest_high, const char *src_, unsigned int _src_high, unsigned int *i, unsigned int *j, unsigned int HighSrc, unsigned int HighDest);
 
 /*
    Cast - casts a := b
 */
 
-static void Cast (unsigned char *a, unsigned int _a_high, unsigned char *b_, unsigned int _b_high);
+static void Cast (unsigned char *a, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high);
 
 /*
    StringFormat1 - converts string, src, into, dest, together with encapsulated
                    entity, w. It only formats the first %s or %d with n.
 */
 
-static void StringFormat1 (char *dest, unsigned int _dest_high, char *src_, unsigned int _src_high, unsigned char *w_, unsigned int _w_high);
+static void StringFormat1 (char *dest, unsigned int _dest_high, const char *src_, unsigned int _src_high, const unsigned char *w_, unsigned int _w_high);
 
 /*
    FormatError - provides a orthoganal counterpart to the procedure below.
 */
 
-static void FormatError (char *a_, unsigned int _a_high);
+static void FormatError (const char *a_, unsigned int _a_high);
 
 /*
    FormatError1 - fairly generic error procedure.
 */
 
-static void FormatError1 (char *a_, unsigned int _a_high, unsigned char *w_, unsigned int _w_high);
+static void FormatError1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high);
 
 /*
    FormatError2 - fairly generic error procedure.
 */
 
-static void FormatError2 (char *a_, unsigned int _a_high, unsigned char *w1_, unsigned int _w1_high, unsigned char *w2_, unsigned int _w2_high);
+static void FormatError2 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high);
 
 /*
    CheckAccess - checks to see whether a file, f, has been
@@ -476,7 +476,7 @@ static int BufferedWrite (FIO_File f, unsigned int nBytes, void * a);
    PreInitialize - preinitialize the file descriptor.
 */
 
-static void PreInitialize (FIO_File f, char *fname_, unsigned int _fname_high, FileStatus state, FileUsage use, unsigned int towrite, int osfd, unsigned int bufsize);
+static void PreInitialize (FIO_File f, const char *fname_, unsigned int _fname_high, FileStatus state, FileUsage use, unsigned int towrite, int osfd, unsigned int bufsize);
 
 /*
    Init - initialize the modules, global variables.
@@ -534,13 +534,13 @@ static FIO_File GetNextFreeDescriptor (void)
   FIO_File h;
   FileDescriptor fd;
 
-  f = Error+1;
-  h = Indexing_HighIndice (FileInfo);
+  f = static_cast<FIO_File> (Error+1);
+  h = static_cast<FIO_File> (Indexing_HighIndice (FileInfo));
   for (;;)
   {
     if (f <= h)
       {
-        fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+        fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
         if (fd == NULL)
           {
             return f;
@@ -549,7 +549,7 @@ static FIO_File GetNextFreeDescriptor (void)
     f += 1;
     if (f > h)
       {
-        Indexing_PutIndice (FileInfo, (unsigned int) f, NULL);  /* create new slot  */
+        Indexing_PutIndice (FileInfo, static_cast<unsigned int> (f), NULL);  /* create new slot  */
         return f;  /* create new slot  */
       }
   }
@@ -566,7 +566,7 @@ static void SetState (FIO_File f, FileStatus s)
 {
   FileDescriptor fd;
 
-  fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+  fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
   fd->state = s;
 }
 
@@ -583,13 +583,13 @@ static FIO_File InitializeFile (FIO_File f, void * fname, unsigned int flength,
   Storage_ALLOCATE ((void **) &fd, sizeof (fds));
   if (fd == NULL)
     {
-      SetState (Error, (FileStatus) outofmemory);
+      SetState (Error, static_cast<FileStatus> (outofmemory));
       return Error;
     }
   else
     {
-      Indexing_PutIndice (FileInfo, (unsigned int) f, (void *) fd);
-      fd->name.size = flength+1;  /* need to guarantee the nul for C  */
+      Indexing_PutIndice (FileInfo, static_cast<unsigned int> (f), reinterpret_cast<void *> (fd));
+      fd->name.size = static_cast<unsigned int> (flength+1);  /* need to guarantee the nul for C  */
       fd->usage = use;  /* need to guarantee the nul for C  */
       fd->output = towrite;
       Storage_ALLOCATE (&fd->name.address, fd->name.size);
@@ -598,26 +598,26 @@ static FIO_File InitializeFile (FIO_File f, void * fname, unsigned int flength,
           fd->state = outofmemory;
           return f;
         }
-      fd->name.address = libc_strncpy (fd->name.address, fname, flength);
+      fd->name.address = reinterpret_cast<void *> (libc_strncpy (fd->name.address, fname, flength));
       /* and assign nul to the last byte  */
-      p = fd->name.address;
+      p = static_cast<PtrToChar> (fd->name.address);
       p += flength;
-      (*p) = ASCII_nul;
-      fd->abspos = 0;
+      (*p) = static_cast<char> (ASCII_nul);
+      fd->abspos = static_cast<long int> (0);
       /* now for the buffer  */
       Storage_ALLOCATE ((void **) &fd->buffer, sizeof (buf));
       if (fd->buffer == NULL)
         {
-          SetState (Error, (FileStatus) outofmemory);
+          SetState (Error, static_cast<FileStatus> (outofmemory));
           return Error;
         }
       else
         {
           fd->buffer->valid = FALSE;
-          fd->buffer->bufstart = 0;
+          fd->buffer->bufstart = static_cast<long int> (0);
           fd->buffer->size = buflength;
-          fd->buffer->position = 0;
-          fd->buffer->filled = 0;
+          fd->buffer->position = static_cast<unsigned int> (0);
+          fd->buffer->filled = static_cast<unsigned int> (0);
           if (fd->buffer->size == 0)
             {
               fd->buffer->address = NULL;
@@ -637,9 +637,9 @@ static FIO_File InitializeFile (FIO_File f, void * fname, unsigned int flength,
             }
           else
             {
-              fd->buffer->left = 0;
+              fd->buffer->left = static_cast<unsigned int> (0);
             }
-          fd->buffer->contents = fd->buffer->address;  /* provides easy access for reading characters  */
+          fd->buffer->contents = reinterpret_cast<_T7 *> (fd->buffer->address);  /* provides easy access for reading characters  */
           fd->state = fstate;  /* provides easy access for reading characters  */
         }
     }
@@ -659,23 +659,23 @@ static void ConnectToUnix (FIO_File f, unsigned int towrite, unsigned int newfil
 
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (fd != NULL)
         {
           if (towrite)
             {
               if (newfile)
                 {
-                  fd->unixfd = libc_creat (fd->name.address, CreatePermissions);
+                  fd->unixfd = static_cast<int> (libc_creat (fd->name.address, CreatePermissions));
                 }
               else
                 {
-                  fd->unixfd = libc_open (fd->name.address, UNIXWRITEONLY, 0);
+                  fd->unixfd = static_cast<int> (libc_open (fd->name.address, UNIXWRITEONLY, 0));
                 }
             }
           else
             {
-              fd->unixfd = libc_open (fd->name.address, UNIXREADONLY, 0);
+              fd->unixfd = static_cast<int> (libc_open (fd->name.address, UNIXREADONLY, 0));
             }
           if (fd->unixfd < 0)
             {
@@ -698,17 +698,19 @@ static void ConnectToUnix (FIO_File f, unsigned int towrite, unsigned int newfil
 
 static int ReadFromBuffer (FIO_File f, void * a, unsigned int nBytes)
 {
+  typedef unsigned char *_T1;
+
   void * t;
   int result;
   unsigned int total;
   unsigned int n;
-  unsigned char * p;
+  _T1 p;
   FileDescriptor fd;
 
   if (f != Error)
     {
-      total = 0;  /* how many bytes have we read  */
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);  /* how many bytes have we read  */
+      total = static_cast<unsigned int> (0);  /* how many bytes have we read  */
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));  /* how many bytes have we read  */
       /* extract from the buffer first  */
       if ((fd->buffer != NULL) && fd->buffer->valid)
         {
@@ -718,28 +720,28 @@ static int ReadFromBuffer (FIO_File f, void * a, unsigned int nBytes)
               if (nBytes == 1)
                 {
                   /* too expensive to call memcpy for 1 character  */
-                  p = a;
-                  (*p) = (*fd->buffer->contents).array[fd->buffer->position];
+                  p = static_cast<_T1> (a);
+                  (*p) = static_cast<unsigned char> ((*fd->buffer->contents).array[fd->buffer->position]);
                   fd->buffer->left -= 1;  /* remove consumed bytes  */
                   fd->buffer->position += 1;  /* move onwards n bytes  */
-                  nBytes = 0;  /* reduce the amount for future direct  */
+                  nBytes = static_cast<unsigned int> (0);  /* reduce the amount for future direct  */
                   /* read  */
-                  return 1;
+                  return static_cast<int> (1);
                 }
               else
                 {
-                  n = Min (fd->buffer->left, nBytes);
+                  n = static_cast<unsigned int> (Min (fd->buffer->left, nBytes));
                   t = fd->buffer->address;
-                  t += fd->buffer->position;
-                  p = libc_memcpy (a, t, (size_t) n);
+                  t = reinterpret_cast<void *> (reinterpret_cast<char *> (t)+fd->buffer->position);
+                  p = static_cast<_T1> (libc_memcpy (a, t, static_cast<size_t> (n)));
                   fd->buffer->left -= n;  /* remove consumed bytes  */
                   fd->buffer->position += n;  /* move onwards n bytes  */
                   /* move onwards ready for direct reads  */
-                  a += n;
+                  a = reinterpret_cast<void *> (reinterpret_cast<char *> (a)+n);
                   nBytes -= n;  /* reduce the amount for future direct  */
                   /* read  */
                   total += n;
-                  return total;  /* much cleaner to return now,  */
+                  return static_cast<int> (total);  /* much cleaner to return now,  */
                 }
                /* difficult to record an error if  */
             }
@@ -748,7 +750,7 @@ static int ReadFromBuffer (FIO_File f, void * a, unsigned int nBytes)
       if (nBytes > 0)
         {
           /* still more to read  */
-          result = libc_read (fd->unixfd, a, (size_t) (int ) (nBytes));
+          result = static_cast<int> (libc_read (fd->unixfd, a, static_cast<size_t> ((int ) (nBytes))));
           if (result > 0)
             {
               /* avoid dangling else.  */
@@ -775,21 +777,21 @@ static int ReadFromBuffer (FIO_File f, void * a, unsigned int nBytes)
               if (fd->buffer != NULL)
                 {
                   fd->buffer->valid = FALSE;
-                  fd->buffer->left = 0;
-                  fd->buffer->position = 0;
+                  fd->buffer->left = static_cast<unsigned int> (0);
+                  fd->buffer->position = static_cast<unsigned int> (0);
                   if (fd->buffer->address != NULL)
                     {
                       (*fd->buffer->contents).array[fd->buffer->position] = ASCII_nul;
                     }
                 }
-              return -1;
+              return static_cast<int> (-1);
             }
         }
-      return total;
+      return static_cast<int> (total);
     }
   else
     {
-      return -1;
+      return static_cast<int> (-1);
     }
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
@@ -806,18 +808,20 @@ static int ReadFromBuffer (FIO_File f, void * a, unsigned int nBytes)
 
 static int BufferedRead (FIO_File f, unsigned int nBytes, void * a)
 {
+  typedef unsigned char *_T3;
+
   void * t;
   int result;
   int total;
   int n;
-  unsigned char * p;
+  _T3 p;
   FileDescriptor fd;
 
   if (f != Error)
     {
       /* avoid dangling else.  */
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
-      total = 0;  /* how many bytes have we read  */
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
+      total = static_cast<int> (0);  /* how many bytes have we read  */
       if (fd != NULL)  /* how many bytes have we read  */
         {
           /* extract from the buffer first  */
@@ -830,8 +834,8 @@ static int BufferedRead (FIO_File f, unsigned int nBytes, void * a)
                       if (nBytes == 1)
                         {
                           /* too expensive to call memcpy for 1 character  */
-                          p = a;
-                          (*p) = (*fd->buffer->contents).array[fd->buffer->position];
+                          p = static_cast<_T3> (a);
+                          (*p) = static_cast<unsigned char> ((*fd->buffer->contents).array[fd->buffer->position]);
                           fd->buffer->left -= 1;  /* remove consumed byte  */
                           fd->buffer->position += 1;  /* move onwards n byte  */
                           total += 1;  /* move onwards n byte  */
@@ -839,14 +843,14 @@ static int BufferedRead (FIO_File f, unsigned int nBytes, void * a)
                         }
                       else
                         {
-                          n = Min (fd->buffer->left, nBytes);
+                          n = static_cast<int> (Min (fd->buffer->left, nBytes));
                           t = fd->buffer->address;
-                          t += fd->buffer->position;
-                          p = libc_memcpy (a, t, (size_t) n);
+                          t = reinterpret_cast<void *> (reinterpret_cast<char *> (t)+fd->buffer->position);
+                          p = static_cast<_T3> (libc_memcpy (a, t, static_cast<size_t> (n)));
                           fd->buffer->left -= n;  /* remove consumed bytes  */
                           fd->buffer->position += n;  /* move onwards n bytes  */
                           /* move onwards ready for direct reads  */
-                          a += n;
+                          a = reinterpret_cast<void *> (reinterpret_cast<char *> (a)+n);
                           nBytes -= n;  /* reduce the amount for future direct  */
                           /* read  */
                           total += n;
@@ -855,29 +859,29 @@ static int BufferedRead (FIO_File f, unsigned int nBytes, void * a)
                   else
                     {
                       /* refill buffer  */
-                      n = libc_read (fd->unixfd, fd->buffer->address, (size_t) fd->buffer->size);
+                      n = static_cast<int> (libc_read (fd->unixfd, fd->buffer->address, static_cast<size_t> (fd->buffer->size)));
                       if (n >= 0)
                         {
                           /* avoid dangling else.  */
                           fd->buffer->valid = TRUE;
-                          fd->buffer->position = 0;
-                          fd->buffer->left = n;
-                          fd->buffer->filled = n;
+                          fd->buffer->position = static_cast<unsigned int> (0);
+                          fd->buffer->left = static_cast<unsigned int> (n);
+                          fd->buffer->filled = static_cast<unsigned int> (n);
                           fd->buffer->bufstart = fd->abspos;
                           fd->abspos += n;
                           if (n == 0)
                             {
                               /* eof reached  */
                               fd->state = endoffile;
-                              return -1;
+                              return static_cast<int> (-1);
                             }
                         }
                       else
                         {
                           fd->buffer->valid = FALSE;
-                          fd->buffer->position = 0;
-                          fd->buffer->left = 0;
-                          fd->buffer->filled = 0;
+                          fd->buffer->position = static_cast<unsigned int> (0);
+                          fd->buffer->left = static_cast<unsigned int> (0);
+                          fd->buffer->filled = static_cast<unsigned int> (0);
                           fd->state = failed;
                           return total;
                         }
@@ -887,13 +891,13 @@ static int BufferedRead (FIO_File f, unsigned int nBytes, void * a)
             }
           else
             {
-              return -1;
+              return static_cast<int> (-1);
             }
         }
     }
   else
     {
-      return -1;
+      return static_cast<int> (-1);
     }
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
@@ -905,7 +909,7 @@ static int BufferedRead (FIO_File f, unsigned int nBytes, void * a)
  and \t into their respective ascii codes.
 */
 
-static void HandleEscape (char *dest, unsigned int _dest_high, char *src_, unsigned int _src_high, unsigned int *i, unsigned int *j, unsigned int HighSrc, unsigned int HighDest)
+static void HandleEscape (char *dest, unsigned int _dest_high, const char *src_, unsigned int _src_high, unsigned int *i, unsigned int *j, unsigned int HighSrc, unsigned int HighDest)
 {
   char src[_src_high+1];
 
@@ -918,7 +922,7 @@ static void HandleEscape (char *dest, unsigned int _dest_high, char *src_, unsig
       if (src[(*i)+1] == 'n')
         {
           /* requires a newline  */
-          dest[(*j)] = ASCII_nl;
+          dest[(*j)] = static_cast<char> (ASCII_nl);
           (*j) += 1;
           (*i) += 2;
         }
@@ -926,7 +930,7 @@ static void HandleEscape (char *dest, unsigned int _dest_high, char *src_, unsig
         {
           /* avoid dangling else.  */
           /* requires a tab (yuck) tempted to fake this but I better not..  */
-          dest[(*j)] = ASCII_tab;
+          dest[(*j)] = static_cast<char> (ASCII_tab);
           (*j) += 1;
           (*i) += 2;
         }
@@ -947,7 +951,7 @@ static void HandleEscape (char *dest, unsigned int _dest_high, char *src_, unsig
    Cast - casts a := b
 */
 
-static void Cast (unsigned char *a, unsigned int _a_high, unsigned char *b_, unsigned int _b_high)
+static void Cast (unsigned char *a, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high)
 {
   unsigned int i;
   unsigned char b[_b_high+1];
@@ -964,7 +968,7 @@ static void Cast (unsigned char *a, unsigned int _a_high, unsigned char *b_, uns
     }
   else
     {
-      FormatError ((char *) "cast failed", 11);
+      FormatError ((const char *) "cast failed", 11);
     }
 }
 
@@ -974,18 +978,20 @@ static void Cast (unsigned char *a, unsigned int _a_high, unsigned char *b_, uns
                    entity, w. It only formats the first %s or %d with n.
 */
 
-static void StringFormat1 (char *dest, unsigned int _dest_high, char *src_, unsigned int _src_high, unsigned char *w_, unsigned int _w_high)
+static void StringFormat1 (char *dest, unsigned int _dest_high, const char *src_, unsigned int _src_high, const unsigned char *w_, unsigned int _w_high)
 {
-  typedef struct _T2_a _T2;
+  typedef struct _T8_a _T8;
+
+  typedef char *_T4;
 
-  struct _T2_a { char array[MaxErrorString+1]; };
+  struct _T8_a { char array[MaxErrorString+1]; };
   unsigned int HighSrc;
   unsigned int HighDest;
   unsigned int c;
   unsigned int i;
   unsigned int j;
-  _T2 str;
-  char * p;
+  _T8 str;
+  _T4 p;
   char src[_src_high+1];
   unsigned char w[_w_high+1];
 
@@ -993,15 +999,15 @@ static void StringFormat1 (char *dest, unsigned int _dest_high, char *src_, unsi
   memcpy (src, src_, _src_high+1);
   memcpy (w, w_, _w_high+1);
 
-  HighSrc = StrLib_StrLen ((char *) src, _src_high);
+  HighSrc = static_cast<unsigned int> (StrLib_StrLen ((const char *) src, _src_high));
   HighDest = _dest_high;
-  i = 0;
-  j = 0;
+  i = static_cast<unsigned int> (0);
+  j = static_cast<unsigned int> (0);
   while ((((i < HighSrc) && (src[i] != ASCII_nul)) && (j < HighDest)) && (src[i] != '%'))
     {
       if (src[i] == '\\')
         {
-          HandleEscape ((char *) dest, _dest_high, (char *) src, _src_high, &i, &j, HighSrc, HighDest);
+          HandleEscape ((char *) dest, _dest_high, (const char *) src, _src_high, &i, &j, HighSrc, HighDest);
         }
       else
         {
@@ -1015,7 +1021,7 @@ static void StringFormat1 (char *dest, unsigned int _dest_high, char *src_, unsi
       /* avoid gcc warning by using compound statement even if not strictly necessary.  */
       if (src[i+1] == 's')
         {
-          Cast ((unsigned char *) &p, (sizeof (p)-1), (unsigned char *) w, _w_high);
+          Cast ((unsigned char *) &p, (sizeof (p)-1), (const unsigned char *) w, _w_high);
           while ((j < HighDest) && ((*p) != ASCII_nul))
             {
               dest[j] = (*p);
@@ -1026,17 +1032,17 @@ static void StringFormat1 (char *dest, unsigned int _dest_high, char *src_, unsi
             {
               dest[j] = ASCII_nul;
             }
-          j = StrLib_StrLen ((char *) dest, _dest_high);
+          j = static_cast<unsigned int> (StrLib_StrLen ((const char *) dest, _dest_high));
           i += 2;
         }
       else if (src[i+1] == 'd')
         {
           /* avoid dangling else.  */
           dest[j] = ASCII_nul;
-          Cast ((unsigned char *) &c, (sizeof (c)-1), (unsigned char *) w, _w_high);
+          Cast ((unsigned char *) &c, (sizeof (c)-1), (const unsigned char *) w, _w_high);
           NumberIO_CardToStr (c, 0, (char *) &str.array[0], MaxErrorString);
-          StrLib_StrConCat ((char *) dest, _dest_high, (char *) &str.array[0], MaxErrorString, (char *) dest, _dest_high);
-          j = StrLib_StrLen ((char *) dest, _dest_high);
+          StrLib_StrConCat ((const char *) dest, _dest_high, (const char *) &str.array[0], MaxErrorString, (char *) dest, _dest_high);
+          j = static_cast<unsigned int> (StrLib_StrLen ((const char *) dest, _dest_high));
           i += 2;
         }
       else
@@ -1052,7 +1058,7 @@ static void StringFormat1 (char *dest, unsigned int _dest_high, char *src_, unsi
     {
       if (src[i] == '\\')
         {
-          HandleEscape ((char *) dest, _dest_high, (char *) src, _src_high, &i, &j, HighSrc, HighDest);
+          HandleEscape ((char *) dest, _dest_high, (const char *) src, _src_high, &i, &j, HighSrc, HighDest);
         }
       else
         {
@@ -1072,14 +1078,14 @@ static void StringFormat1 (char *dest, unsigned int _dest_high, char *src_, unsi
    FormatError - provides a orthoganal counterpart to the procedure below.
 */
 
-static void FormatError (char *a_, unsigned int _a_high)
+static void FormatError (const char *a_, unsigned int _a_high)
 {
   char a[_a_high+1];
 
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  FIO_WriteString (FIO_StdErr, (char *) a, _a_high);
+  FIO_WriteString (FIO_StdErr, (const char *) a, _a_high);
 }
 
 
@@ -1087,12 +1093,12 @@ static void FormatError (char *a_, unsigned int _a_high)
    FormatError1 - fairly generic error procedure.
 */
 
-static void FormatError1 (char *a_, unsigned int _a_high, unsigned char *w_, unsigned int _w_high)
+static void FormatError1 (const char *a_, unsigned int _a_high, const unsigned char *w_, unsigned int _w_high)
 {
-  typedef struct _T3_a _T3;
+  typedef struct _T9_a _T9;
 
-  struct _T3_a { char array[MaxErrorString+1]; };
-  _T3 s;
+  struct _T9_a { char array[MaxErrorString+1]; };
+  _T9 s;
   char a[_a_high+1];
   unsigned char w[_w_high+1];
 
@@ -1100,8 +1106,8 @@ static void FormatError1 (char *a_, unsigned int _a_high, unsigned char *w_, uns
   memcpy (a, a_, _a_high+1);
   memcpy (w, w_, _w_high+1);
 
-  StringFormat1 ((char *) &s.array[0], MaxErrorString, (char *) a, _a_high, (unsigned char *) w, _w_high);
-  FormatError ((char *) &s.array[0], MaxErrorString);
+  StringFormat1 ((char *) &s.array[0], MaxErrorString, (const char *) a, _a_high, (const unsigned char *) w, _w_high);
+  FormatError ((const char *) &s.array[0], MaxErrorString);
 }
 
 
@@ -1109,12 +1115,12 @@ static void FormatError1 (char *a_, unsigned int _a_high, unsigned char *w_, uns
    FormatError2 - fairly generic error procedure.
 */
 
-static void FormatError2 (char *a_, unsigned int _a_high, unsigned char *w1_, unsigned int _w1_high, unsigned char *w2_, unsigned int _w2_high)
+static void FormatError2 (const char *a_, unsigned int _a_high, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high)
 {
-  typedef struct _T4_a _T4;
+  typedef struct _T10_a _T10;
 
-  struct _T4_a { char array[MaxErrorString+1]; };
-  _T4 s;
+  struct _T10_a { char array[MaxErrorString+1]; };
+  _T10 s;
   char a[_a_high+1];
   unsigned char w1[_w1_high+1];
   unsigned char w2[_w2_high+1];
@@ -1124,8 +1130,8 @@ static void FormatError2 (char *a_, unsigned int _a_high, unsigned char *w1_, un
   memcpy (w1, w1_, _w1_high+1);
   memcpy (w2, w2_, _w2_high+1);
 
-  StringFormat1 ((char *) &s.array[0], MaxErrorString, (char *) a, _a_high, (unsigned char *) w1, _w1_high);
-  FormatError1 ((char *) &s.array[0], MaxErrorString, (unsigned char *) w2, _w2_high);
+  StringFormat1 ((char *) &s.array[0], MaxErrorString, (const char *) a, _a_high, (const unsigned char *) w1, _w1_high);
+  FormatError1 ((const char *) &s.array[0], MaxErrorString, (const unsigned char *) w2, _w2_high);
 }
 
 
@@ -1141,12 +1147,12 @@ static void CheckAccess (FIO_File f, FileUsage use, unsigned int towrite)
   if (f != Error)
     {
       /* avoid dangling else.  */
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (fd == NULL)
         {
           if (f != FIO_StdErr)
             {
-              FormatError ((char *) "this file has probably been closed and not reopened successfully or alternatively never opened\\n", 96);
+              FormatError ((const char *) "this file has probably been closed and not reopened successfully or alternatively never opened\\n", 96);
             }
           M2RTS_HALT (-1);
           __builtin_unreachable ();
@@ -1155,21 +1161,21 @@ static void CheckAccess (FIO_File f, FileUsage use, unsigned int towrite)
         {
           if ((use == openedforwrite) && (fd->usage == openedforread))
             {
-              FormatError1 ((char *) "this file (%s) has been opened for reading but is now being written\\n", 69, (unsigned char *) &fd->name.address, (sizeof (fd->name.address)-1));
+              FormatError1 ((const char *) "this file (%s) has been opened for reading but is now being written\\n", 69, (const unsigned char *) &fd->name.address, (sizeof (fd->name.address)-1));
               M2RTS_HALT (-1);
               __builtin_unreachable ();
             }
           else if ((use == openedforread) && (fd->usage == openedforwrite))
             {
               /* avoid dangling else.  */
-              FormatError1 ((char *) "this file (%s) has been opened for writing but is now being read\\n", 66, (unsigned char *) &fd->name.address, (sizeof (fd->name.address)-1));
+              FormatError1 ((const char *) "this file (%s) has been opened for writing but is now being read\\n", 66, (const unsigned char *) &fd->name.address, (sizeof (fd->name.address)-1));
               M2RTS_HALT (-1);
               __builtin_unreachable ();
             }
           else if (fd->state == connectionfailure)
             {
               /* avoid dangling else.  */
-              FormatError1 ((char *) "this file (%s) was not successfully opened\\n", 44, (unsigned char *) &fd->name.address, (sizeof (fd->name.address)-1));
+              FormatError1 ((const char *) "this file (%s) was not successfully opened\\n", 44, (const unsigned char *) &fd->name.address, (sizeof (fd->name.address)-1));
               M2RTS_HALT (-1);
               __builtin_unreachable ();
             }
@@ -1178,13 +1184,13 @@ static void CheckAccess (FIO_File f, FileUsage use, unsigned int towrite)
               /* avoid dangling else.  */
               if (fd->output)
                 {
-                  FormatError1 ((char *) "this file (%s) was opened for writing but is now being read\\n", 61, (unsigned char *) &fd->name.address, (sizeof (fd->name.address)-1));
+                  FormatError1 ((const char *) "this file (%s) was opened for writing but is now being read\\n", 61, (const unsigned char *) &fd->name.address, (sizeof (fd->name.address)-1));
                   M2RTS_HALT (-1);
                   __builtin_unreachable ();
                 }
               else
                 {
-                  FormatError1 ((char *) "this file (%s) was opened for reading but is now being written\\n", 64, (unsigned char *) &fd->name.address, (sizeof (fd->name.address)-1));
+                  FormatError1 ((const char *) "this file (%s) was opened for reading but is now being written\\n", 64, (const unsigned char *) &fd->name.address, (sizeof (fd->name.address)-1));
                   M2RTS_HALT (-1);
                   __builtin_unreachable ();
                 }
@@ -1193,7 +1199,7 @@ static void CheckAccess (FIO_File f, FileUsage use, unsigned int towrite)
     }
   else
     {
-      FormatError ((char *) "this file has not been opened successfully\\n", 44);
+      FormatError ((const char *) "this file has not been opened successfully\\n", 44);
       M2RTS_HALT (-1);
       __builtin_unreachable ();
     }
@@ -1208,10 +1214,10 @@ static void SetEndOfLine (FIO_File f, char ch)
 {
   FileDescriptor fd;
 
-  CheckAccess (f, (FileUsage) openedforread, FALSE);
+  CheckAccess (f, static_cast<FileUsage> (openedforread), FALSE);
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (ch == ASCII_nl)
         {
           fd->state = endofline;
@@ -1234,19 +1240,21 @@ static void SetEndOfLine (FIO_File f, char ch)
 
 static int BufferedWrite (FIO_File f, unsigned int nBytes, void * a)
 {
+  typedef unsigned char *_T5;
+
   void * t;
   int result;
   int total;
   int n;
-  unsigned char * p;
+  _T5 p;
   FileDescriptor fd;
 
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (fd != NULL)
         {
-          total = 0;  /* how many bytes have we read  */
+          total = static_cast<int> (0);  /* how many bytes have we read  */
           if (fd->buffer != NULL)  /* how many bytes have we read  */
             {
               /* place into the buffer first  */
@@ -1257,8 +1265,8 @@ static int BufferedWrite (FIO_File f, unsigned int nBytes, void * a)
                       if (nBytes == 1)
                         {
                           /* too expensive to call memcpy for 1 character  */
-                          p = a;
-                          (*fd->buffer->contents).array[fd->buffer->position] = (*p);
+                          p = static_cast<_T5> (a);
+                          (*fd->buffer->contents).array[fd->buffer->position] = static_cast<char> ((*p));
                           fd->buffer->left -= 1;  /* reduce space  */
                           fd->buffer->position += 1;  /* move onwards n byte  */
                           total += 1;  /* move onwards n byte  */
@@ -1266,14 +1274,14 @@ static int BufferedWrite (FIO_File f, unsigned int nBytes, void * a)
                         }
                       else
                         {
-                          n = Min (fd->buffer->left, nBytes);
+                          n = static_cast<int> (Min (fd->buffer->left, nBytes));
                           t = fd->buffer->address;
-                          t += fd->buffer->position;
-                          p = libc_memcpy (a, t, (size_t) (unsigned int ) (n));
+                          t = reinterpret_cast<void *> (reinterpret_cast<char *> (t)+fd->buffer->position);
+                          p = static_cast<_T5> (libc_memcpy (a, t, static_cast<size_t> ((unsigned int ) (n))));
                           fd->buffer->left -= n;  /* remove consumed bytes  */
                           fd->buffer->position += n;  /* move onwards n bytes  */
                           /* move ready for further writes  */
-                          a += n;
+                          a = reinterpret_cast<void *> (reinterpret_cast<char *> (a)+n);
                           nBytes -= n;  /* reduce the amount for future writes  */
                           total += n;  /* reduce the amount for future writes  */
                         }
@@ -1283,7 +1291,7 @@ static int BufferedWrite (FIO_File f, unsigned int nBytes, void * a)
                       FIO_FlushBuffer (f);
                       if ((fd->state != successful) && (fd->state != endofline))
                         {
-                          nBytes = 0;
+                          nBytes = static_cast<unsigned int> (0);
                         }
                     }
                 }
@@ -1291,7 +1299,7 @@ static int BufferedWrite (FIO_File f, unsigned int nBytes, void * a)
             }
         }
     }
-  return -1;
+  return static_cast<int> (-1);
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -1301,7 +1309,7 @@ static int BufferedWrite (FIO_File f, unsigned int nBytes, void * a)
    PreInitialize - preinitialize the file descriptor.
 */
 
-static void PreInitialize (FIO_File f, char *fname_, unsigned int _fname_high, FileStatus state, FileUsage use, unsigned int towrite, int osfd, unsigned int bufsize)
+static void PreInitialize (FIO_File f, const char *fname_, unsigned int _fname_high, FileStatus state, FileUsage use, unsigned int towrite, int osfd, unsigned int bufsize)
 {
   FileDescriptor fd;
   FileDescriptor fe;
@@ -1310,12 +1318,12 @@ static void PreInitialize (FIO_File f, char *fname_, unsigned int _fname_high, F
   /* make a local copy of each unbounded array.  */
   memcpy (fname, fname_, _fname_high+1);
 
-  if ((InitializeFile (f, &fname, StrLib_StrLen ((char *) fname, _fname_high), state, use, towrite, bufsize)) == f)
+  if ((InitializeFile (f, &fname, StrLib_StrLen ((const char *) fname, _fname_high), state, use, towrite, bufsize)) == f)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (f == Error)
         {
-          fe = Indexing_GetIndice (FileInfo, (unsigned int) FIO_StdErr);
+          fe = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (FIO_StdErr)));
           if (fe == NULL)
             {
               M2RTS_HALT (-1);
@@ -1345,15 +1353,15 @@ static void PreInitialize (FIO_File f, char *fname_, unsigned int _fname_high, F
 
 static void Init (void)
 {
-  FileInfo = Indexing_InitIndex (0);
-  Error = 0;
-  PreInitialize (Error, (char *) "error", 5, (FileStatus) toomanyfilesopen, (FileUsage) unused, FALSE, -1, 0);
-  FIO_StdIn = 1;
-  PreInitialize (FIO_StdIn, (char *) "<stdin>", 7, (FileStatus) successful, (FileUsage) openedforread, FALSE, 0, MaxBufferLength);
-  FIO_StdOut = 2;
-  PreInitialize (FIO_StdOut, (char *) "<stdout>", 8, (FileStatus) successful, (FileUsage) openedforwrite, TRUE, 1, MaxBufferLength);
-  FIO_StdErr = 3;
-  PreInitialize (FIO_StdErr, (char *) "<stderr>", 8, (FileStatus) successful, (FileUsage) openedforwrite, TRUE, 2, MaxBufferLength);
+  FileInfo = static_cast<Indexing_Index> (Indexing_InitIndex (0));
+  Error = static_cast<FIO_File> (0);
+  PreInitialize (Error, (const char *) "error", 5, static_cast<FileStatus> (toomanyfilesopen), static_cast<FileUsage> (unused), FALSE, -1, 0);
+  FIO_StdIn = static_cast<FIO_File> (1);
+  PreInitialize (FIO_StdIn, (const char *) "<stdin>", 7, static_cast<FileStatus> (successful), static_cast<FileUsage> (openedforread), FALSE, 0, MaxBufferLength);
+  FIO_StdOut = static_cast<FIO_File> (2);
+  PreInitialize (FIO_StdOut, (const char *) "<stdout>", 8, static_cast<FileStatus> (successful), static_cast<FileUsage> (openedforwrite), TRUE, 1, MaxBufferLength);
+  FIO_StdErr = static_cast<FIO_File> (3);
+  PreInitialize (FIO_StdErr, (const char *) "<stderr>", 8, static_cast<FileStatus> (successful), static_cast<FileUsage> (openedforwrite), TRUE, 2, MaxBufferLength);
   if (! (M2RTS_InstallTerminationProcedure ((PROC ) {(PROC_t) FIO_FlushOutErr})))
     {
       M2RTS_HALT (-1);
@@ -1366,7 +1374,7 @@ static void Init (void)
    IsNoError - returns a TRUE if no error has occured on file, f.
 */
 
-unsigned int FIO_IsNoError (FIO_File f)
+extern "C" unsigned int FIO_IsNoError (FIO_File f)
 {
   FileDescriptor fd;
 
@@ -1376,7 +1384,7 @@ unsigned int FIO_IsNoError (FIO_File f)
     }
   else
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       return (fd != NULL) && (((fd->state == successful) || (fd->state == endoffile)) || (fd->state == endofline));
     }
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -1388,7 +1396,7 @@ unsigned int FIO_IsNoError (FIO_File f)
    IsActive - returns TRUE if the file, f, is still active.
 */
 
-unsigned int FIO_IsActive (FIO_File f)
+extern "C" unsigned int FIO_IsActive (FIO_File f)
 {
   if (f == Error)
     {
@@ -1396,13 +1404,13 @@ unsigned int FIO_IsActive (FIO_File f)
     }
   else
     {
-      return (Indexing_GetIndice (FileInfo, (unsigned int) f)) != NULL;
+      return (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f))) != NULL;
     }
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
 
-unsigned int FIO_Exists (char *fname_, unsigned int _fname_high)
+extern "C" unsigned int FIO_Exists (const char *fname_, unsigned int _fname_high)
 {
   char fname[_fname_high+1];
 
@@ -1412,43 +1420,43 @@ unsigned int FIO_Exists (char *fname_, unsigned int _fname_high)
   /* 
    The following functions are wrappers for the above.
   */
-  return FIO_exists (&fname, StrLib_StrLen ((char *) fname, _fname_high));
+  return static_cast<unsigned int> (FIO_exists (&fname, StrLib_StrLen ((const char *) fname, _fname_high)));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
 
-FIO_File FIO_OpenToRead (char *fname_, unsigned int _fname_high)
+extern "C" FIO_File FIO_OpenToRead (const char *fname_, unsigned int _fname_high)
 {
   char fname[_fname_high+1];
 
   /* make a local copy of each unbounded array.  */
   memcpy (fname, fname_, _fname_high+1);
 
-  return FIO_openToRead (&fname, StrLib_StrLen ((char *) fname, _fname_high));
+  return static_cast<FIO_File> (FIO_openToRead (&fname, StrLib_StrLen ((const char *) fname, _fname_high)));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
 
-FIO_File FIO_OpenToWrite (char *fname_, unsigned int _fname_high)
+extern "C" FIO_File FIO_OpenToWrite (const char *fname_, unsigned int _fname_high)
 {
   char fname[_fname_high+1];
 
   /* make a local copy of each unbounded array.  */
   memcpy (fname, fname_, _fname_high+1);
 
-  return FIO_openToWrite (&fname, StrLib_StrLen ((char *) fname, _fname_high));
+  return static_cast<FIO_File> (FIO_openToWrite (&fname, StrLib_StrLen ((const char *) fname, _fname_high)));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
 
-FIO_File FIO_OpenForRandom (char *fname_, unsigned int _fname_high, unsigned int towrite, unsigned int newfile)
+extern "C" FIO_File FIO_OpenForRandom (const char *fname_, unsigned int _fname_high, unsigned int towrite, unsigned int newfile)
 {
   char fname[_fname_high+1];
 
   /* make a local copy of each unbounded array.  */
   memcpy (fname, fname_, _fname_high+1);
 
-  return FIO_openForRandom (&fname, StrLib_StrLen ((char *) fname, _fname_high), towrite, newfile);
+  return static_cast<FIO_File> (FIO_openForRandom (&fname, StrLib_StrLen ((const char *) fname, _fname_high), towrite, newfile));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -1460,13 +1468,13 @@ FIO_File FIO_OpenForRandom (char *fname_, unsigned int _fname_high, unsigned int
            It is correct to close a file which has an error status.
 */
 
-void FIO_Close (FIO_File f)
+extern "C" void FIO_Close (FIO_File f)
 {
   FileDescriptor fd;
 
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       /* 
          we allow users to close files which have an error status
   */
@@ -1477,7 +1485,7 @@ void FIO_Close (FIO_File f)
             {
               if ((libc_close (fd->unixfd)) != 0)
                 {
-                  FormatError1 ((char *) "failed to close file (%s)\\n", 27, (unsigned char *) &fd->name.address, (sizeof (fd->name.address)-1));
+                  FormatError1 ((const char *) "failed to close file (%s)\\n", 27, (const unsigned char *) &fd->name.address, (sizeof (fd->name.address)-1));
                   fd->state = failed;  /* --fixme-- too late to notify user (unless we return a BOOLEAN)  */
                 }
             }
@@ -1492,10 +1500,10 @@ void FIO_Close (FIO_File f)
                   Storage_DEALLOCATE (&fd->buffer->address, fd->buffer->size);
                 }
               Storage_DEALLOCATE ((void **) &fd->buffer, sizeof (buf));
-              fd->buffer = NULL;
+              fd->buffer = static_cast<Buffer> (NULL);
             }
           Storage_DEALLOCATE ((void **) &fd, sizeof (fds));
-          Indexing_PutIndice (FileInfo, (unsigned int) f, NULL);
+          Indexing_PutIndice (FileInfo, static_cast<unsigned int> (f), NULL);
         }
     }
 }
@@ -1505,11 +1513,11 @@ void FIO_Close (FIO_File f)
    exists - returns TRUE if a file named, fname exists for reading.
 */
 
-unsigned int FIO_exists (void * fname, unsigned int flength)
+extern "C" unsigned int FIO_exists (void * fname, unsigned int flength)
 {
   FIO_File f;
 
-  f = FIO_openToRead (fname, flength);
+  f = static_cast<FIO_File> (FIO_openToRead (fname, flength));
   if (FIO_IsNoError (f))
     {
       FIO_Close (f);
@@ -1532,18 +1540,18 @@ unsigned int FIO_exists (void * fname, unsigned int flength)
                 calling IsNoError.
 */
 
-FIO_File FIO_openToRead (void * fname, unsigned int flength)
+extern "C" FIO_File FIO_openToRead (void * fname, unsigned int flength)
 {
   FIO_File f;
 
-  f = GetNextFreeDescriptor ();
+  f = static_cast<FIO_File> (GetNextFreeDescriptor ());
   if (f == Error)
     {
-      SetState (f, (FileStatus) toomanyfilesopen);
+      SetState (f, static_cast<FileStatus> (toomanyfilesopen));
     }
   else
     {
-      f = InitializeFile (f, fname, flength, (FileStatus) successful, (FileUsage) openedforread, FALSE, MaxBufferLength);
+      f = static_cast<FIO_File> (InitializeFile (f, fname, flength, static_cast<FileStatus> (successful), static_cast<FileUsage> (openedforread), FALSE, MaxBufferLength));
       ConnectToUnix (f, FALSE, FALSE);
     }
   return f;
@@ -1559,18 +1567,18 @@ FIO_File FIO_openToRead (void * fname, unsigned int flength)
                  calling IsNoError.
 */
 
-FIO_File FIO_openToWrite (void * fname, unsigned int flength)
+extern "C" FIO_File FIO_openToWrite (void * fname, unsigned int flength)
 {
   FIO_File f;
 
-  f = GetNextFreeDescriptor ();
+  f = static_cast<FIO_File> (GetNextFreeDescriptor ());
   if (f == Error)
     {
-      SetState (f, (FileStatus) toomanyfilesopen);
+      SetState (f, static_cast<FileStatus> (toomanyfilesopen));
     }
   else
     {
-      f = InitializeFile (f, fname, flength, (FileStatus) successful, (FileUsage) openedforwrite, TRUE, MaxBufferLength);
+      f = static_cast<FIO_File> (InitializeFile (f, fname, flength, static_cast<FileStatus> (successful), static_cast<FileUsage> (openedforwrite), TRUE, MaxBufferLength));
       ConnectToUnix (f, TRUE, TRUE);
     }
   return f;
@@ -1588,18 +1596,18 @@ FIO_File FIO_openToWrite (void * fname, unsigned int flength)
                    opened for writing or reading.
 */
 
-FIO_File FIO_openForRandom (void * fname, unsigned int flength, unsigned int towrite, unsigned int newfile)
+extern "C" FIO_File FIO_openForRandom (void * fname, unsigned int flength, unsigned int towrite, unsigned int newfile)
 {
   FIO_File f;
 
-  f = GetNextFreeDescriptor ();
+  f = static_cast<FIO_File> (GetNextFreeDescriptor ());
   if (f == Error)
     {
-      SetState (f, (FileStatus) toomanyfilesopen);
+      SetState (f, static_cast<FileStatus> (toomanyfilesopen));
     }
   else
     {
-      f = InitializeFile (f, fname, flength, (FileStatus) successful, (FileUsage) openedforrandom, towrite, MaxBufferLength);
+      f = static_cast<FIO_File> (InitializeFile (f, fname, flength, static_cast<FileStatus> (successful), static_cast<FileUsage> (openedforrandom), towrite, MaxBufferLength));
       ConnectToUnix (f, towrite, newfile);
     }
   return f;
@@ -1612,23 +1620,23 @@ FIO_File FIO_openForRandom (void * fname, unsigned int flength, unsigned int tow
    FlushBuffer - flush contents of file, f.
 */
 
-void FIO_FlushBuffer (FIO_File f)
+extern "C" void FIO_FlushBuffer (FIO_File f)
 {
   FileDescriptor fd;
 
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (fd != NULL)
         {
           if (fd->output && (fd->buffer != NULL))
             {
-              if ((fd->buffer->position == 0) || ((libc_write (fd->unixfd, fd->buffer->address, (size_t) fd->buffer->position)) == ((int ) (fd->buffer->position))))
+              if ((fd->buffer->position == 0) || ((libc_write (fd->unixfd, fd->buffer->address, static_cast<size_t> (fd->buffer->position))) == ((int ) (fd->buffer->position))))
                 {
                   fd->abspos += fd->buffer->position;
                   fd->buffer->bufstart = fd->abspos;
-                  fd->buffer->position = 0;
-                  fd->buffer->filled = 0;
+                  fd->buffer->position = static_cast<unsigned int> (0);
+                  fd->buffer->filled = static_cast<unsigned int> (0);
                   fd->buffer->left = fd->buffer->size;
                 }
               else
@@ -1648,30 +1656,32 @@ void FIO_FlushBuffer (FIO_File f)
                 perform direct libc reads. It is ideal for large reads.
 */
 
-unsigned int FIO_ReadNBytes (FIO_File f, unsigned int nBytes, void * a)
+extern "C" unsigned int FIO_ReadNBytes (FIO_File f, unsigned int nBytes, void * a)
 {
+  typedef char *_T2;
+
   int n;
-  char * p;
+  _T2 p;
 
   if (f != Error)
     {
-      CheckAccess (f, (FileUsage) openedforread, FALSE);
-      n = ReadFromBuffer (f, a, nBytes);
+      CheckAccess (f, static_cast<FileUsage> (openedforread), FALSE);
+      n = static_cast<int> (ReadFromBuffer (f, a, nBytes));
       if (n <= 0)
         {
-          return 0;
+          return static_cast<unsigned int> (0);
         }
       else
         {
-          p = a;
+          p = static_cast<_T2> (a);
           p += n-1;
           SetEndOfLine (f, (*p));
-          return n;
+          return static_cast<unsigned int> (n);
         }
     }
   else
     {
-      return 0;
+      return static_cast<unsigned int> (0);
     }
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
@@ -1684,12 +1694,12 @@ unsigned int FIO_ReadNBytes (FIO_File f, unsigned int nBytes, void * a)
              suited to small reads.
 */
 
-void FIO_ReadAny (FIO_File f, unsigned char *a, unsigned int _a_high)
+extern "C" void FIO_ReadAny (FIO_File f, unsigned char *a, unsigned int _a_high)
 {
-  CheckAccess (f, (FileUsage) openedforread, FALSE);
+  CheckAccess (f, static_cast<FileUsage> (openedforread), FALSE);
   if ((BufferedRead (f, _a_high, a)) == _a_high)
     {
-      SetEndOfLine (f, (char) a[_a_high]);
+      SetEndOfLine (f, static_cast<char> (a[_a_high]));
     }
 }
 
@@ -1702,23 +1712,23 @@ void FIO_ReadAny (FIO_File f, unsigned char *a, unsigned int _a_high)
                  It is ideal for large writes.
 */
 
-unsigned int FIO_WriteNBytes (FIO_File f, unsigned int nBytes, void * a)
+extern "C" unsigned int FIO_WriteNBytes (FIO_File f, unsigned int nBytes, void * a)
 {
   int total;
   FileDescriptor fd;
 
-  CheckAccess (f, (FileUsage) openedforwrite, TRUE);
+  CheckAccess (f, static_cast<FileUsage> (openedforwrite), TRUE);
   FIO_FlushBuffer (f);
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (fd != NULL)
         {
-          total = libc_write (fd->unixfd, a, (size_t) (int ) (nBytes));
+          total = static_cast<int> (libc_write (fd->unixfd, a, static_cast<size_t> ((int ) (nBytes))));
           if (total < 0)
             {
               fd->state = failed;
-              return 0;
+              return static_cast<unsigned int> (0);
             }
           else
             {
@@ -1731,7 +1741,7 @@ unsigned int FIO_WriteNBytes (FIO_File f, unsigned int nBytes, void * a)
             }
         }
     }
-  return 0;
+  return static_cast<unsigned int> (0);
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -1743,9 +1753,9 @@ unsigned int FIO_WriteNBytes (FIO_File f, unsigned int nBytes, void * a)
               suited to small writes.
 */
 
-void FIO_WriteAny (FIO_File f, unsigned char *a, unsigned int _a_high)
+extern "C" void FIO_WriteAny (FIO_File f, unsigned char *a, unsigned int _a_high)
 {
-  CheckAccess (f, (FileUsage) openedforwrite, TRUE);
+  CheckAccess (f, static_cast<FileUsage> (openedforwrite), TRUE);
   if ((BufferedWrite (f, _a_high, a)) == _a_high)
     {}  /* empty.  */
 }
@@ -1755,9 +1765,9 @@ void FIO_WriteAny (FIO_File f, unsigned char *a, unsigned int _a_high)
    WriteChar - writes a single character to file, f.
 */
 
-void FIO_WriteChar (FIO_File f, char ch)
+extern "C" void FIO_WriteChar (FIO_File f, char ch)
 {
-  CheckAccess (f, (FileUsage) openedforwrite, TRUE);
+  CheckAccess (f, static_cast<FileUsage> (openedforwrite), TRUE);
   if ((BufferedWrite (f, sizeof (ch), &ch)) == sizeof (ch))
     {}  /* empty.  */
 }
@@ -1767,14 +1777,14 @@ void FIO_WriteChar (FIO_File f, char ch)
    EOF - tests to see whether a file, f, has reached end of file.
 */
 
-unsigned int FIO_EOF (FIO_File f)
+extern "C" unsigned int FIO_EOF (FIO_File f)
 {
   FileDescriptor fd;
 
-  CheckAccess (f, (FileUsage) openedforread, FALSE);
+  CheckAccess (f, static_cast<FileUsage> (openedforread), FALSE);
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (fd != NULL)
         {
           return fd->state == endoffile;
@@ -1791,24 +1801,24 @@ unsigned int FIO_EOF (FIO_File f)
           It does NOT consume the newline.
 */
 
-unsigned int FIO_EOLN (FIO_File f)
+extern "C" unsigned int FIO_EOLN (FIO_File f)
 {
   char ch;
   FileDescriptor fd;
 
-  CheckAccess (f, (FileUsage) openedforread, FALSE);
+  CheckAccess (f, static_cast<FileUsage> (openedforread), FALSE);
   /* 
       we will read a character and then push it back onto the input stream,
       having noted the file status, we also reset the status.
   */
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (fd != NULL)
         {
           if ((fd->state == successful) || (fd->state == endofline))
             {
-              ch = FIO_ReadChar (f);
+              ch = static_cast<char> (FIO_ReadChar (f));
               if ((fd->state == successful) || (fd->state == endofline))
                 {
                   FIO_UnReadChar (f, ch);
@@ -1827,18 +1837,18 @@ unsigned int FIO_EOLN (FIO_File f)
    WasEOLN - tests to see whether a file, f, has just seen a newline.
 */
 
-unsigned int FIO_WasEOLN (FIO_File f)
+extern "C" unsigned int FIO_WasEOLN (FIO_File f)
 {
   FileDescriptor fd;
 
-  CheckAccess (f, (FileUsage) openedforread, FALSE);
+  CheckAccess (f, static_cast<FileUsage> (openedforread), FALSE);
   if (f == Error)
     {
       return FALSE;
     }
   else
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       return (fd != NULL) && (fd->state == endofline);
     }
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -1852,11 +1862,11 @@ unsigned int FIO_WasEOLN (FIO_File f)
               this function.
 */
 
-char FIO_ReadChar (FIO_File f)
+extern "C" char FIO_ReadChar (FIO_File f)
 {
   char ch;
 
-  CheckAccess (f, (FileUsage) openedforread, FALSE);
+  CheckAccess (f, static_cast<FileUsage> (openedforread), FALSE);
   if ((BufferedRead (f, sizeof (ch), &ch)) == sizeof (ch))
     {
       SetEndOfLine (f, ch);
@@ -1882,17 +1892,17 @@ char FIO_ReadChar (FIO_File f)
                 Otherwise it is left alone.
 */
 
-void FIO_UnReadChar (FIO_File f, char ch)
+extern "C" void FIO_UnReadChar (FIO_File f, char ch)
 {
   FileDescriptor fd;
   unsigned int n;
   void * a;
   void * b;
 
-  CheckAccess (f, (FileUsage) openedforread, FALSE);
+  CheckAccess (f, static_cast<FileUsage> (openedforread), FALSE);
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (((fd->state == successful) || (fd->state == endoffile)) || (fd->state == endofline))
         {
           /* avoid dangling else.  */
@@ -1901,9 +1911,9 @@ void FIO_UnReadChar (FIO_File f, char ch)
               /* we assume that a ReadChar has occurred, we will check just in case.  */
               if (fd->state == endoffile)
                 {
-                  fd->buffer->position = MaxBufferLength;
-                  fd->buffer->left = 0;
-                  fd->buffer->filled = 0;
+                  fd->buffer->position = static_cast<unsigned int> (MaxBufferLength);
+                  fd->buffer->left = static_cast<unsigned int> (0);
+                  fd->buffer->filled = static_cast<unsigned int> (0);
                   fd->state = successful;
                 }
               if (fd->buffer->position > 0)
@@ -1917,14 +1927,14 @@ void FIO_UnReadChar (FIO_File f, char ch)
                   /* if possible make room and store ch  */
                   if (fd->buffer->filled == fd->buffer->size)
                     {
-                      FormatError1 ((char *) "performing too many UnReadChar calls on file (%d)\\n", 51, (unsigned char *) &f, (sizeof (f)-1));
+                      FormatError1 ((const char *) "performing too many UnReadChar calls on file (%d)\\n", 51, (const unsigned char *) &f, (sizeof (f)-1));
                     }
                   else
                     {
-                      n = fd->buffer->filled-fd->buffer->position;
+                      n = static_cast<unsigned int> (fd->buffer->filled-fd->buffer->position);
                       b = &(*fd->buffer->contents).array[fd->buffer->position];
                       a = &(*fd->buffer->contents).array[fd->buffer->position+1];
-                      a = libc_memcpy (a, b, (size_t) n);
+                      a = reinterpret_cast<void *> (libc_memcpy (a, b, static_cast<size_t> (n)));
                       fd->buffer->filled += 1;
                       (*fd->buffer->contents).array[fd->buffer->position] = ch;
                     }
@@ -1933,7 +1943,7 @@ void FIO_UnReadChar (FIO_File f, char ch)
         }
       else
         {
-          FormatError1 ((char *) "UnReadChar can only be called if the previous read was successful or end of file, error on file (%d)\\n", 102, (unsigned char *) &f, (sizeof (f)-1));
+          FormatError1 ((const char *) "UnReadChar can only be called if the previous read was successful or end of file, error on file (%d)\\n", 102, (const unsigned char *) &f, (sizeof (f)-1));
         }
     }
 }
@@ -1943,7 +1953,7 @@ void FIO_UnReadChar (FIO_File f, char ch)
    WriteLine - writes out a linefeed to file, f.
 */
 
-void FIO_WriteLine (FIO_File f)
+extern "C" void FIO_WriteLine (FIO_File f)
 {
   FIO_WriteChar (f, ASCII_nl);
 }
@@ -1953,7 +1963,7 @@ void FIO_WriteLine (FIO_File f)
    WriteString - writes a string to file, f.
 */
 
-void FIO_WriteString (FIO_File f, char *a_, unsigned int _a_high)
+extern "C" void FIO_WriteString (FIO_File f, const char *a_, unsigned int _a_high)
 {
   unsigned int l;
   char a[_a_high+1];
@@ -1961,7 +1971,7 @@ void FIO_WriteString (FIO_File f, char *a_, unsigned int _a_high)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  l = StrLib_StrLen ((char *) a, _a_high);
+  l = static_cast<unsigned int> (StrLib_StrLen ((const char *) a, _a_high));
   if ((FIO_WriteNBytes (f, l, &a)) != l)
     {}  /* empty.  */
 }
@@ -1973,17 +1983,17 @@ void FIO_WriteString (FIO_File f, char *a_, unsigned int _a_high)
                 if a newline is seen or an error occurs.
 */
 
-void FIO_ReadString (FIO_File f, char *a, unsigned int _a_high)
+extern "C" void FIO_ReadString (FIO_File f, char *a, unsigned int _a_high)
 {
   unsigned int high;
   unsigned int i;
   char ch;
 
-  CheckAccess (f, (FileUsage) openedforread, FALSE);
+  CheckAccess (f, static_cast<FileUsage> (openedforread), FALSE);
   high = _a_high;
-  i = 0;
+  i = static_cast<unsigned int> (0);
   do {
-    ch = FIO_ReadChar (f);
+    ch = static_cast<char> (FIO_ReadChar (f));
     if (i <= high)
       {
         /* avoid gcc warning by using compound statement even if not strictly necessary.  */
@@ -2008,7 +2018,7 @@ void FIO_ReadString (FIO_File f, char *a, unsigned int _a_high)
                    to file, f.
 */
 
-void FIO_WriteCardinal (FIO_File f, unsigned int c)
+extern "C" void FIO_WriteCardinal (FIO_File f, unsigned int c)
 {
   FIO_WriteAny (f, (unsigned char *) &c, (sizeof (c)-1));
 }
@@ -2020,7 +2030,7 @@ void FIO_WriteCardinal (FIO_File f, unsigned int c)
                   from a file, f.
 */
 
-unsigned int FIO_ReadCardinal (FIO_File f)
+extern "C" unsigned int FIO_ReadCardinal (FIO_File f)
 {
   unsigned int c;
 
@@ -2035,20 +2045,20 @@ unsigned int FIO_ReadCardinal (FIO_File f)
    GetUnixFileDescriptor - returns the UNIX file descriptor of a file.
 */
 
-int FIO_GetUnixFileDescriptor (FIO_File f)
+extern "C" int FIO_GetUnixFileDescriptor (FIO_File f)
 {
   FileDescriptor fd;
 
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (fd != NULL)
         {
           return fd->unixfd;
         }
     }
-  FormatError1 ((char *) "file %d has not been opened or is out of range\\n", 48, (unsigned char *) &f, (sizeof (f)-1));
-  return -1;
+  FormatError1 ((const char *) "file %d has not been opened or is out of range\\n", 48, (const unsigned char *) &f, (sizeof (f)-1));
+  return static_cast<int> (-1);
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -2058,14 +2068,14 @@ int FIO_GetUnixFileDescriptor (FIO_File f)
    SetPositionFromBeginning - sets the position from the beginning of the file.
 */
 
-void FIO_SetPositionFromBeginning (FIO_File f, long int pos)
+extern "C" void FIO_SetPositionFromBeginning (FIO_File f, long int pos)
 {
   long int offset;
   FileDescriptor fd;
 
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (fd != NULL)
         {
           /* always force the lseek, until we are confident that abspos is always correct,
@@ -2081,12 +2091,12 @@ void FIO_SetPositionFromBeginning (FIO_File f, long int pos)
                     }
                   else
                     {
-                      fd->buffer->left = 0;
+                      fd->buffer->left = static_cast<unsigned int> (0);
                     }
-                  fd->buffer->position = 0;
-                  fd->buffer->filled = 0;
+                  fd->buffer->position = static_cast<unsigned int> (0);
+                  fd->buffer->filled = static_cast<unsigned int> (0);
                 }
-              offset = libc_lseek (fd->unixfd, pos, SEEK_SET);
+              offset = static_cast<long int> (libc_lseek (fd->unixfd, pos, SEEK_SET));
               if ((offset >= 0) && (pos == offset))
                 {
                   fd->abspos = pos;
@@ -2094,7 +2104,7 @@ void FIO_SetPositionFromBeginning (FIO_File f, long int pos)
               else
                 {
                   fd->state = failed;
-                  fd->abspos = 0;
+                  fd->abspos = static_cast<long int> (0);
                 }
               if (fd->buffer != NULL)
                 {
@@ -2111,14 +2121,14 @@ void FIO_SetPositionFromBeginning (FIO_File f, long int pos)
    SetPositionFromEnd - sets the position from the end of the file.
 */
 
-void FIO_SetPositionFromEnd (FIO_File f, long int pos)
+extern "C" void FIO_SetPositionFromEnd (FIO_File f, long int pos)
 {
   long int offset;
   FileDescriptor fd;
 
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (fd != NULL)
         {
           FIO_FlushBuffer (f);
@@ -2130,12 +2140,12 @@ void FIO_SetPositionFromEnd (FIO_File f, long int pos)
                 }
               else
                 {
-                  fd->buffer->left = 0;
+                  fd->buffer->left = static_cast<unsigned int> (0);
                 }
-              fd->buffer->position = 0;
-              fd->buffer->filled = 0;
+              fd->buffer->position = static_cast<unsigned int> (0);
+              fd->buffer->filled = static_cast<unsigned int> (0);
             }
-          offset = libc_lseek (fd->unixfd, pos, SEEK_END);
+          offset = static_cast<long int> (libc_lseek (fd->unixfd, pos, SEEK_END));
           if (offset >= 0)
             {
               fd->abspos = offset;
@@ -2143,8 +2153,8 @@ void FIO_SetPositionFromEnd (FIO_File f, long int pos)
           else
             {
               fd->state = failed;
-              fd->abspos = 0;
-              offset = 0;
+              fd->abspos = static_cast<long int> (0);
+              offset = static_cast<long int> (0);
             }
           if (fd->buffer != NULL)
             {
@@ -2160,13 +2170,13 @@ void FIO_SetPositionFromEnd (FIO_File f, long int pos)
    FindPosition - returns the current absolute position in file, f.
 */
 
-long int FIO_FindPosition (FIO_File f)
+extern "C" long int FIO_FindPosition (FIO_File f)
 {
   FileDescriptor fd;
 
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (fd != NULL)
         {
           if ((fd->buffer == NULL) || ! fd->buffer->valid)
@@ -2175,11 +2185,11 @@ long int FIO_FindPosition (FIO_File f)
             }
           else
             {
-              return fd->buffer->bufstart+((long int ) (fd->buffer->position));
+              return static_cast<long int> (fd->buffer->bufstart+((long int ) (fd->buffer->position)));
             }
         }
     }
-  return 0;
+  return static_cast<long int> (0);
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -2189,18 +2199,20 @@ long int FIO_FindPosition (FIO_File f)
    GetFileName - assigns, a, with the filename associated with, f.
 */
 
-void FIO_GetFileName (FIO_File f, char *a, unsigned int _a_high)
+extern "C" void FIO_GetFileName (FIO_File f, char *a, unsigned int _a_high)
 {
+  typedef char *_T6;
+
   unsigned int i;
+  _T6 p;
   FileDescriptor fd;
-  char * p;
 
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (fd == NULL)
         {
-          FormatError ((char *) "this file has probably been closed and not reopened successfully or alternatively never opened\\n", 96);
+          FormatError ((const char *) "this file has probably been closed and not reopened successfully or alternatively never opened\\n", 96);
           M2RTS_HALT (-1);
           __builtin_unreachable ();
         }
@@ -2208,12 +2220,12 @@ void FIO_GetFileName (FIO_File f, char *a, unsigned int _a_high)
         {
           if (fd->name.address == NULL)
             {
-              StrLib_StrCopy ((char *) "", 0, (char *) a, _a_high);
+              StrLib_StrCopy ((const char *) "", 0, (char *) a, _a_high);
             }
           else
             {
-              p = fd->name.address;
-              i = 0;
+              p = static_cast<_T6> (fd->name.address);
+              i = static_cast<unsigned int> (0);
               while (((*p) != ASCII_nul) && (i <= _a_high))
                 {
                   a[i] = (*p);
@@ -2230,16 +2242,16 @@ void FIO_GetFileName (FIO_File f, char *a, unsigned int _a_high)
    getFileName - returns the address of the filename associated with, f.
 */
 
-void * FIO_getFileName (FIO_File f)
+extern "C" void * FIO_getFileName (FIO_File f)
 {
   FileDescriptor fd;
 
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (fd == NULL)
         {
-          FormatError ((char *) "this file has probably been closed and not reopened successfully or alternatively never opened\\n", 96);
+          FormatError ((const char *) "this file has probably been closed and not reopened successfully or alternatively never opened\\n", 96);
           M2RTS_HALT (-1);
           __builtin_unreachable ();
         }
@@ -2257,16 +2269,16 @@ void * FIO_getFileName (FIO_File f)
    getFileNameLength - returns the number of characters associated with filename, f.
 */
 
-unsigned int FIO_getFileNameLength (FIO_File f)
+extern "C" unsigned int FIO_getFileNameLength (FIO_File f)
 {
   FileDescriptor fd;
 
   if (f != Error)
     {
-      fd = Indexing_GetIndice (FileInfo, (unsigned int) f);
+      fd = static_cast<FileDescriptor> (Indexing_GetIndice (FileInfo, static_cast<unsigned int> (f)));
       if (fd == NULL)
         {
-          FormatError ((char *) "this file has probably been closed and not reopened successfully or alternatively never opened\\n", 96);
+          FormatError ((const char *) "this file has probably been closed and not reopened successfully or alternatively never opened\\n", 96);
           M2RTS_HALT (-1);
           __builtin_unreachable ();
         }
@@ -2287,7 +2299,7 @@ unsigned int FIO_getFileNameLength (FIO_File f)
                  scaffold).
 */
 
-void FIO_FlushOutErr (void)
+extern "C" void FIO_FlushOutErr (void)
 {
   if (FIO_IsNoError (FIO_StdOut))
     {
@@ -2299,12 +2311,12 @@ void FIO_FlushOutErr (void)
     }
 }
 
-void _M2_FIO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_FIO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
   Init ();
 }
 
-void _M2_FIO_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_FIO_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
   FIO_FlushOutErr ();
 }
diff --git a/gcc/m2/mc-boot/GFIO.h b/gcc/m2/mc-boot/GFIO.h
index d6cc03bd6e0..027d7053259 100644
--- a/gcc/m2/mc-boot/GFIO.h
+++ b/gcc/m2/mc-boot/GFIO.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_FIO_H)
 #   define _FIO_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
@@ -70,7 +70,7 @@ EXTERN unsigned int FIO_IsActive (FIO_File f);
    Exists - returns TRUE if a file named, fname exists for reading.
 */
 
-EXTERN unsigned int FIO_Exists (char *fname_, unsigned int _fname_high);
+EXTERN unsigned int FIO_Exists (const char *fname_, unsigned int _fname_high);
 
 /*
    OpenToRead - attempts to open a file, fname, for reading and
@@ -79,7 +79,7 @@ EXTERN unsigned int FIO_Exists (char *fname_, unsigned int _fname_high);
                 calling IsNoError.
 */
 
-EXTERN FIO_File FIO_OpenToRead (char *fname_, unsigned int _fname_high);
+EXTERN FIO_File FIO_OpenToRead (const char *fname_, unsigned int _fname_high);
 
 /*
    OpenToWrite - attempts to open a file, fname, for write and
@@ -88,7 +88,7 @@ EXTERN FIO_File FIO_OpenToRead (char *fname_, unsigned int _fname_high);
                  calling IsNoError.
 */
 
-EXTERN FIO_File FIO_OpenToWrite (char *fname_, unsigned int _fname_high);
+EXTERN FIO_File FIO_OpenToWrite (const char *fname_, unsigned int _fname_high);
 
 /*
    OpenForRandom - attempts to open a file, fname, for random access
@@ -103,7 +103,7 @@ EXTERN FIO_File FIO_OpenToWrite (char *fname_, unsigned int _fname_high);
                    and modify an existing file.
 */
 
-EXTERN FIO_File FIO_OpenForRandom (char *fname_, unsigned int _fname_high, unsigned int towrite, unsigned int newfile);
+EXTERN FIO_File FIO_OpenForRandom (const char *fname_, unsigned int _fname_high, unsigned int towrite, unsigned int newfile);
 
 /*
    Close - close a file which has been previously opened using:
@@ -213,7 +213,7 @@ EXTERN void FIO_WriteLine (FIO_File f);
    WriteString - writes a string to file, f.
 */
 
-EXTERN void FIO_WriteString (FIO_File f, char *a_, unsigned int _a_high);
+EXTERN void FIO_WriteString (FIO_File f, const char *a_, unsigned int _a_high);
 
 /*
    ReadString - reads a string from file, f, into string, a.
diff --git a/gcc/m2/mc-boot/GFormatStrings.c b/gcc/m2/mc-boot/GFormatStrings.c
index a4ce01f0cb0..52260c57ff0 100644
--- a/gcc/m2/mc-boot/GFormatStrings.c
+++ b/gcc/m2/mc-boot/GFormatStrings.c
@@ -60,32 +60,32 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
               escape sequences translated.
 */
 
-DynamicStrings_String FormatStrings_Sprintf0 (DynamicStrings_String fmt);
+extern "C" DynamicStrings_String FormatStrings_Sprintf0 (DynamicStrings_String fmt);
 
 /*
    Sprintf1 - returns a String containing, s, together with encapsulated
               entity, w. It only formats the first %s or %d with n.
 */
 
-DynamicStrings_String FormatStrings_Sprintf1 (DynamicStrings_String fmt, unsigned char *w_, unsigned int _w_high);
+extern "C" DynamicStrings_String FormatStrings_Sprintf1 (DynamicStrings_String fmt, const unsigned char *w_, unsigned int _w_high);
 
 /*
    Sprintf2 - returns a string, s, which has been formatted.
 */
 
-DynamicStrings_String FormatStrings_Sprintf2 (DynamicStrings_String fmt, unsigned char *w1_, unsigned int _w1_high, unsigned char *w2_, unsigned int _w2_high);
+extern "C" DynamicStrings_String FormatStrings_Sprintf2 (DynamicStrings_String fmt, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high);
 
 /*
    Sprintf3 - returns a string, s, which has been formatted.
 */
 
-DynamicStrings_String FormatStrings_Sprintf3 (DynamicStrings_String fmt, unsigned char *w1_, unsigned int _w1_high, unsigned char *w2_, unsigned int _w2_high, unsigned char *w3_, unsigned int _w3_high);
+extern "C" DynamicStrings_String FormatStrings_Sprintf3 (DynamicStrings_String fmt, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high);
 
 /*
    Sprintf4 - returns a string, s, which has been formatted.
 */
 
-DynamicStrings_String FormatStrings_Sprintf4 (DynamicStrings_String fmt, unsigned char *w1_, unsigned int _w1_high, unsigned char *w2_, unsigned int _w2_high, unsigned char *w3_, unsigned int _w3_high, unsigned char *w4_, unsigned int _w4_high);
+extern "C" DynamicStrings_String FormatStrings_Sprintf4 (DynamicStrings_String fmt, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high, const unsigned char *w4_, unsigned int _w4_high);
 
 /*
    HandleEscape - translates \a, \b, \e, \f, 
@@ -94,7 +94,7 @@ DynamicStrings_String FormatStrings_Sprintf4 (DynamicStrings_String fmt, unsigne
                   a single [any] character.
 */
 
-DynamicStrings_String FormatStrings_HandleEscape (DynamicStrings_String s);
+extern "C" DynamicStrings_String FormatStrings_HandleEscape (DynamicStrings_String s);
 
 /*
    doDSdbEnter -
@@ -130,7 +130,7 @@ static unsigned int IsDigit (char ch);
    Cast - casts a := b
 */
 
-static void Cast (unsigned char *a, unsigned int _a_high, unsigned char *b_, unsigned int _b_high);
+static void Cast (unsigned char *a, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high);
 
 /*
    isHex -
@@ -162,7 +162,7 @@ static unsigned int isOct (char ch);
                   A new string is returned.
 */
 
-static DynamicStrings_String FormatString (DynamicStrings_String fmt, int *startpos, DynamicStrings_String in, unsigned char *w_, unsigned int _w_high);
+static DynamicStrings_String FormatString (DynamicStrings_String fmt, int *startpos, DynamicStrings_String in, const unsigned char *w_, unsigned int _w_high);
 
 /*
    FormatString - returns a String containing, s, together with encapsulated
@@ -170,7 +170,7 @@ static DynamicStrings_String FormatString (DynamicStrings_String fmt, int *start
                   A new string is returned.
 */
 
-static DynamicStrings_String PerformFormatString (DynamicStrings_String fmt, int *startpos, DynamicStrings_String in, unsigned char *w_, unsigned int _w_high);
+static DynamicStrings_String PerformFormatString (DynamicStrings_String fmt, int *startpos, DynamicStrings_String in, const unsigned char *w_, unsigned int _w_high);
 
 /*
    Copy - copies, fmt[start:end] -> in and returns in.  Providing that start >= 0.
@@ -203,7 +203,7 @@ static void doDSdbEnter (void)
 
 static void doDSdbExit (DynamicStrings_String s)
 {
-  s = DynamicStrings_PopAllocationExemption (TRUE, s);
+  s = static_cast<DynamicStrings_String> (DynamicStrings_PopAllocationExemption (TRUE, s));
 }
 
 
@@ -241,7 +241,7 @@ static unsigned int IsDigit (char ch)
    Cast - casts a := b
 */
 
-static void Cast (unsigned char *a, unsigned int _a_high, unsigned char *b_, unsigned int _b_high)
+static void Cast (unsigned char *a, unsigned int _a_high, const unsigned char *b_, unsigned int _b_high)
 {
   unsigned int i;
   unsigned char b[_b_high+1];
@@ -284,17 +284,17 @@ static unsigned int toHex (char ch)
 {
   if ((ch >= '0') && (ch <= '9'))
     {
-      return ((unsigned int) (ch))- ((unsigned int) ('0'));
+      return static_cast<unsigned int> ( ((unsigned int) (ch))- ((unsigned int) ('0')));
     }
   else if ((ch >= 'A') && (ch <= 'F'))
     {
       /* avoid dangling else.  */
-      return ( ((unsigned int) (ch))- ((unsigned int) ('A')))+10;
+      return static_cast<unsigned int> (( ((unsigned int) (ch))- ((unsigned int) ('A')))+10);
     }
   else
     {
       /* avoid dangling else.  */
-      return ( ((unsigned int) (ch))- ((unsigned int) ('a')))+10;
+      return static_cast<unsigned int> (( ((unsigned int) (ch))- ((unsigned int) ('a')))+10);
     }
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
@@ -307,7 +307,7 @@ static unsigned int toHex (char ch)
 
 static unsigned int toOct (char ch)
 {
-  return ((unsigned int) (ch))- ((unsigned int) ('0'));
+  return static_cast<unsigned int> ( ((unsigned int) (ch))- ((unsigned int) ('0')));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -331,7 +331,7 @@ static unsigned int isOct (char ch)
                   A new string is returned.
 */
 
-static DynamicStrings_String FormatString (DynamicStrings_String fmt, int *startpos, DynamicStrings_String in, unsigned char *w_, unsigned int _w_high)
+static DynamicStrings_String FormatString (DynamicStrings_String fmt, int *startpos, DynamicStrings_String in, const unsigned char *w_, unsigned int _w_high)
 {
   DynamicStrings_String s;
   unsigned char w[_w_high+1];
@@ -342,11 +342,11 @@ static DynamicStrings_String FormatString (DynamicStrings_String fmt, int *start
   DSdbEnter ();
   if ((*startpos) >= 0)
     {
-      s = PerformFormatString (fmt, startpos, in, (unsigned char *) w, _w_high);
+      s = static_cast<DynamicStrings_String> (PerformFormatString (fmt, startpos, in, (const unsigned char *) w, _w_high));
     }
   else
     {
-      s = DynamicStrings_Dup (in);
+      s = static_cast<DynamicStrings_String> (DynamicStrings_Dup (in));
     }
   DSdbExit (s);
   return s;
@@ -361,7 +361,7 @@ static DynamicStrings_String FormatString (DynamicStrings_String fmt, int *start
                   A new string is returned.
 */
 
-static DynamicStrings_String PerformFormatString (DynamicStrings_String fmt, int *startpos, DynamicStrings_String in, unsigned char *w_, unsigned int _w_high)
+static DynamicStrings_String PerformFormatString (DynamicStrings_String fmt, int *startpos, DynamicStrings_String in, const unsigned char *w_, unsigned int _w_high)
 {
   unsigned int left;
   unsigned int u;
@@ -381,7 +381,7 @@ static DynamicStrings_String PerformFormatString (DynamicStrings_String fmt, int
 
   while ((*startpos) >= 0)
     {
-      nextperc = DynamicStrings_Index (fmt, '%', (unsigned int) (*startpos));
+      nextperc = static_cast<int> (DynamicStrings_Index (fmt, '%', static_cast<unsigned int> ((*startpos))));
       afterperc = nextperc;
       if (nextperc >= 0)
         {
@@ -395,7 +395,7 @@ static DynamicStrings_String PerformFormatString (DynamicStrings_String fmt, int
             {
               left = FALSE;
             }
-          ch = DynamicStrings_char (fmt, afterperc);
+          ch = static_cast<char> (DynamicStrings_char (fmt, afterperc));
           if (ch == '0')
             {
               leader = '0';
@@ -404,25 +404,25 @@ static DynamicStrings_String PerformFormatString (DynamicStrings_String fmt, int
             {
               leader = ' ';
             }
-          width = 0;
+          width = static_cast<int> (0);
           while (IsDigit (ch))
             {
-              width = (width*10)+((int ) ( ((unsigned int) (ch))- ((unsigned int) ('0'))));
+              width = static_cast<int> ((width*10)+((int ) ( ((unsigned int) (ch))- ((unsigned int) ('0')))));
               afterperc += 1;
-              ch = DynamicStrings_char (fmt, afterperc);
+              ch = static_cast<char> (DynamicStrings_char (fmt, afterperc));
             }
           if ((ch == 'c') || (ch == 's'))
             {
               afterperc += 1;
               if (ch == 'c')
                 {
-                  ch2 = w[0];
-                  p = DynamicStrings_ConCatChar (DynamicStrings_InitString ((char *) "", 0), ch2);
+                  ch2 = static_cast<char> (w[0]);
+                  p = static_cast<DynamicStrings_String> (DynamicStrings_ConCatChar (DynamicStrings_InitString ((const char *) "", 0), ch2));
                 }
               else
                 {
-                  Cast ((unsigned char *) &p, (sizeof (p)-1), (unsigned char *) w, _w_high);
-                  p = DynamicStrings_Dup (p);
+                  Cast ((unsigned char *) &p, (sizeof (p)-1), (const unsigned char *) w, _w_high);
+                  p = static_cast<DynamicStrings_String> (DynamicStrings_Dup (p));
                 }
               if ((width > 0) && (((int ) (DynamicStrings_Length (p))) < width))
                 {
@@ -430,55 +430,55 @@ static DynamicStrings_String PerformFormatString (DynamicStrings_String fmt, int
                   if (left)
                     {
                       /* place trailing spaces after, p.  */
-                      p = DynamicStrings_ConCat (p, DynamicStrings_Mark (DynamicStrings_Mult (DynamicStrings_Mark (DynamicStrings_InitString ((char *) " ", 1)), (unsigned int) width-((int ) (DynamicStrings_Length (p))))));
+                      p = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (p, DynamicStrings_Mark (DynamicStrings_Mult (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) " ", 1)), static_cast<unsigned int> (width-((int ) (DynamicStrings_Length (p))))))));
                     }
                   else
                     {
                       /* padd string, p, with leading spaces.  */
-                      p = DynamicStrings_ConCat (DynamicStrings_Mult (DynamicStrings_Mark (DynamicStrings_InitString ((char *) " ", 1)), (unsigned int) width-((int ) (DynamicStrings_Length (p)))), DynamicStrings_Mark (p));
+                      p = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (DynamicStrings_Mult (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) " ", 1)), static_cast<unsigned int> (width-((int ) (DynamicStrings_Length (p))))), DynamicStrings_Mark (p)));
                     }
                 }
               /* include string, p, into, in.  */
               if (nextperc > 0)
                 {
-                  in = DynamicStrings_ConCat (in, DynamicStrings_Slice (fmt, (*startpos), nextperc));
+                  in = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (in, DynamicStrings_Slice (fmt, (*startpos), nextperc)));
                 }
-              in = DynamicStrings_ConCat (in, p);
+              in = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (in, p));
               (*startpos) = afterperc;
-              DSdbExit ((DynamicStrings_String) NULL);
+              DSdbExit (static_cast<DynamicStrings_String> (NULL));
               return in;
             }
           else if (ch == 'd')
             {
               /* avoid dangling else.  */
               afterperc += 1;
-              Cast ((unsigned char *) &c, (sizeof (c)-1), (unsigned char *) w, _w_high);
-              in = Copy (fmt, in, (*startpos), nextperc);
-              in = DynamicStrings_ConCat (in, StringConvert_IntegerToString (c, (unsigned int) width, leader, FALSE, 10, FALSE));
+              Cast ((unsigned char *) &c, (sizeof (c)-1), (const unsigned char *) w, _w_high);
+              in = static_cast<DynamicStrings_String> (Copy (fmt, in, (*startpos), nextperc));
+              in = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (in, StringConvert_IntegerToString (c, static_cast<unsigned int> (width), leader, FALSE, 10, FALSE)));
               (*startpos) = afterperc;
-              DSdbExit ((DynamicStrings_String) NULL);
+              DSdbExit (static_cast<DynamicStrings_String> (NULL));
               return in;
             }
           else if (ch == 'x')
             {
               /* avoid dangling else.  */
               afterperc += 1;
-              Cast ((unsigned char *) &u, (sizeof (u)-1), (unsigned char *) w, _w_high);
-              in = DynamicStrings_ConCat (in, DynamicStrings_Slice (fmt, (*startpos), nextperc));
-              in = DynamicStrings_ConCat (in, StringConvert_CardinalToString (u, (unsigned int) width, leader, 16, TRUE));
+              Cast ((unsigned char *) &u, (sizeof (u)-1), (const unsigned char *) w, _w_high);
+              in = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (in, DynamicStrings_Slice (fmt, (*startpos), nextperc)));
+              in = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (in, StringConvert_CardinalToString (u, static_cast<unsigned int> (width), leader, 16, TRUE)));
               (*startpos) = afterperc;
-              DSdbExit ((DynamicStrings_String) NULL);
+              DSdbExit (static_cast<DynamicStrings_String> (NULL));
               return in;
             }
           else if (ch == 'u')
             {
               /* avoid dangling else.  */
               afterperc += 1;
-              Cast ((unsigned char *) &u, (sizeof (u)-1), (unsigned char *) w, _w_high);
-              in = DynamicStrings_ConCat (in, DynamicStrings_Slice (fmt, (*startpos), nextperc));
-              in = DynamicStrings_ConCat (in, StringConvert_CardinalToString (u, (unsigned int) width, leader, 10, FALSE));
+              Cast ((unsigned char *) &u, (sizeof (u)-1), (const unsigned char *) w, _w_high);
+              in = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (in, DynamicStrings_Slice (fmt, (*startpos), nextperc)));
+              in = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (in, StringConvert_CardinalToString (u, static_cast<unsigned int> (width), leader, 10, FALSE)));
               (*startpos) = afterperc;
-              DSdbExit ((DynamicStrings_String) NULL);
+              DSdbExit (static_cast<DynamicStrings_String> (NULL));
               return in;
             }
           else
@@ -488,21 +488,21 @@ static DynamicStrings_String PerformFormatString (DynamicStrings_String fmt, int
               /* copy format string.  */
               if (nextperc > 0)
                 {
-                  in = DynamicStrings_ConCat (in, DynamicStrings_Slice (fmt, (*startpos), nextperc));
+                  in = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (in, DynamicStrings_Slice (fmt, (*startpos), nextperc)));
                 }
               /* and the character after the %.  */
-              in = DynamicStrings_ConCat (in, DynamicStrings_Mark (DynamicStrings_InitStringChar (ch)));
+              in = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (in, DynamicStrings_Mark (DynamicStrings_InitStringChar (ch))));
             }
           (*startpos) = afterperc;
         }
       else
         {
           /* nothing to do.  */
-          DSdbExit ((DynamicStrings_String) NULL);
+          DSdbExit (static_cast<DynamicStrings_String> (NULL));
           return in;
         }
     }
-  DSdbExit ((DynamicStrings_String) NULL);
+  DSdbExit (static_cast<DynamicStrings_String> (NULL));
   return in;
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
@@ -520,12 +520,12 @@ static DynamicStrings_String Copy (DynamicStrings_String fmt, DynamicStrings_Str
       /* avoid gcc warning by using compound statement even if not strictly necessary.  */
       if (end > 0)
         {
-          in = DynamicStrings_ConCat (in, DynamicStrings_Mark (DynamicStrings_Slice (fmt, start, end)));
+          in = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (in, DynamicStrings_Mark (DynamicStrings_Slice (fmt, start, end))));
         }
       else if (end < 0)
         {
           /* avoid dangling else.  */
-          in = DynamicStrings_ConCat (in, DynamicStrings_Mark (DynamicStrings_Slice (fmt, start, 0)));
+          in = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (in, DynamicStrings_Mark (DynamicStrings_Slice (fmt, start, 0))));
         }
     }
   return in;
@@ -554,17 +554,17 @@ static DynamicStrings_String HandlePercent (DynamicStrings_String fmt, DynamicSt
       prevpos = startpos;
       while ((startpos >= 0) && (prevpos < ((int ) (DynamicStrings_Length (fmt)))))
         {
-          startpos = DynamicStrings_Index (fmt, '%', (unsigned int) startpos);
+          startpos = static_cast<int> (DynamicStrings_Index (fmt, '%', static_cast<unsigned int> (startpos)));
           if (startpos >= prevpos)
             {
               if (startpos > 0)
                 {
-                  s = DynamicStrings_ConCat (s, DynamicStrings_Mark (DynamicStrings_Slice (fmt, prevpos, startpos)));
+                  s = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (s, DynamicStrings_Mark (DynamicStrings_Slice (fmt, prevpos, startpos))));
                 }
               startpos += 1;
               if ((DynamicStrings_char (fmt, startpos)) == '%')
                 {
-                  s = DynamicStrings_ConCatChar (s, '%');
+                  s = static_cast<DynamicStrings_String> (DynamicStrings_ConCatChar (s, '%'));
                   startpos += 1;
                 }
               prevpos = startpos;
@@ -572,7 +572,7 @@ static DynamicStrings_String HandlePercent (DynamicStrings_String fmt, DynamicSt
         }
       if (prevpos < ((int ) (DynamicStrings_Length (fmt))))
         {
-          s = DynamicStrings_ConCat (s, DynamicStrings_Mark (DynamicStrings_Slice (fmt, prevpos, 0)));
+          s = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (s, DynamicStrings_Mark (DynamicStrings_Slice (fmt, prevpos, 0))));
         }
       return s;
     }
@@ -586,13 +586,13 @@ static DynamicStrings_String HandlePercent (DynamicStrings_String fmt, DynamicSt
               escape sequences translated.
 */
 
-DynamicStrings_String FormatStrings_Sprintf0 (DynamicStrings_String fmt)
+extern "C" DynamicStrings_String FormatStrings_Sprintf0 (DynamicStrings_String fmt)
 {
   DynamicStrings_String s;
 
   DSdbEnter ();
-  fmt = FormatStrings_HandleEscape (fmt);
-  s = HandlePercent (fmt, DynamicStrings_InitString ((char *) "", 0), 0);
+  fmt = static_cast<DynamicStrings_String> (FormatStrings_HandleEscape (fmt));
+  s = static_cast<DynamicStrings_String> (HandlePercent (fmt, DynamicStrings_InitString ((const char *) "", 0), 0));
   DSdbExit (s);
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -605,7 +605,7 @@ DynamicStrings_String FormatStrings_Sprintf0 (DynamicStrings_String fmt)
               entity, w. It only formats the first %s or %d with n.
 */
 
-DynamicStrings_String FormatStrings_Sprintf1 (DynamicStrings_String fmt, unsigned char *w_, unsigned int _w_high)
+extern "C" DynamicStrings_String FormatStrings_Sprintf1 (DynamicStrings_String fmt, const unsigned char *w_, unsigned int _w_high)
 {
   int i;
   DynamicStrings_String s;
@@ -615,10 +615,10 @@ DynamicStrings_String FormatStrings_Sprintf1 (DynamicStrings_String fmt, unsigne
   memcpy (w, w_, _w_high+1);
 
   DSdbEnter ();
-  fmt = FormatStrings_HandleEscape (fmt);
-  i = 0;
-  s = FormatString (fmt, &i, DynamicStrings_InitString ((char *) "", 0), (unsigned char *) w, _w_high);
-  s = HandlePercent (fmt, s, i);
+  fmt = static_cast<DynamicStrings_String> (FormatStrings_HandleEscape (fmt));
+  i = static_cast<int> (0);
+  s = static_cast<DynamicStrings_String> (FormatString (fmt, &i, DynamicStrings_InitString ((const char *) "", 0), (const unsigned char *) w, _w_high));
+  s = static_cast<DynamicStrings_String> (HandlePercent (fmt, s, i));
   DSdbExit (s);
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -630,7 +630,7 @@ DynamicStrings_String FormatStrings_Sprintf1 (DynamicStrings_String fmt, unsigne
    Sprintf2 - returns a string, s, which has been formatted.
 */
 
-DynamicStrings_String FormatStrings_Sprintf2 (DynamicStrings_String fmt, unsigned char *w1_, unsigned int _w1_high, unsigned char *w2_, unsigned int _w2_high)
+extern "C" DynamicStrings_String FormatStrings_Sprintf2 (DynamicStrings_String fmt, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high)
 {
   int i;
   DynamicStrings_String s;
@@ -642,11 +642,11 @@ DynamicStrings_String FormatStrings_Sprintf2 (DynamicStrings_String fmt, unsigne
   memcpy (w2, w2_, _w2_high+1);
 
   DSdbEnter ();
-  fmt = FormatStrings_HandleEscape (fmt);
-  i = 0;
-  s = FormatString (fmt, &i, DynamicStrings_InitString ((char *) "", 0), (unsigned char *) w1, _w1_high);
-  s = FormatString (fmt, &i, s, (unsigned char *) w2, _w2_high);
-  s = HandlePercent (fmt, s, i);
+  fmt = static_cast<DynamicStrings_String> (FormatStrings_HandleEscape (fmt));
+  i = static_cast<int> (0);
+  s = static_cast<DynamicStrings_String> (FormatString (fmt, &i, DynamicStrings_InitString ((const char *) "", 0), (const unsigned char *) w1, _w1_high));
+  s = static_cast<DynamicStrings_String> (FormatString (fmt, &i, s, (const unsigned char *) w2, _w2_high));
+  s = static_cast<DynamicStrings_String> (HandlePercent (fmt, s, i));
   DSdbExit (s);
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -658,7 +658,7 @@ DynamicStrings_String FormatStrings_Sprintf2 (DynamicStrings_String fmt, unsigne
    Sprintf3 - returns a string, s, which has been formatted.
 */
 
-DynamicStrings_String FormatStrings_Sprintf3 (DynamicStrings_String fmt, unsigned char *w1_, unsigned int _w1_high, unsigned char *w2_, unsigned int _w2_high, unsigned char *w3_, unsigned int _w3_high)
+extern "C" DynamicStrings_String FormatStrings_Sprintf3 (DynamicStrings_String fmt, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high)
 {
   int i;
   DynamicStrings_String s;
@@ -672,12 +672,12 @@ DynamicStrings_String FormatStrings_Sprintf3 (DynamicStrings_String fmt, unsigne
   memcpy (w3, w3_, _w3_high+1);
 
   DSdbEnter ();
-  fmt = FormatStrings_HandleEscape (fmt);
-  i = 0;
-  s = FormatString (fmt, &i, DynamicStrings_InitString ((char *) "", 0), (unsigned char *) w1, _w1_high);
-  s = FormatString (fmt, &i, s, (unsigned char *) w2, _w2_high);
-  s = FormatString (fmt, &i, s, (unsigned char *) w3, _w3_high);
-  s = HandlePercent (fmt, s, i);
+  fmt = static_cast<DynamicStrings_String> (FormatStrings_HandleEscape (fmt));
+  i = static_cast<int> (0);
+  s = static_cast<DynamicStrings_String> (FormatString (fmt, &i, DynamicStrings_InitString ((const char *) "", 0), (const unsigned char *) w1, _w1_high));
+  s = static_cast<DynamicStrings_String> (FormatString (fmt, &i, s, (const unsigned char *) w2, _w2_high));
+  s = static_cast<DynamicStrings_String> (FormatString (fmt, &i, s, (const unsigned char *) w3, _w3_high));
+  s = static_cast<DynamicStrings_String> (HandlePercent (fmt, s, i));
   DSdbExit (s);
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -689,7 +689,7 @@ DynamicStrings_String FormatStrings_Sprintf3 (DynamicStrings_String fmt, unsigne
    Sprintf4 - returns a string, s, which has been formatted.
 */
 
-DynamicStrings_String FormatStrings_Sprintf4 (DynamicStrings_String fmt, unsigned char *w1_, unsigned int _w1_high, unsigned char *w2_, unsigned int _w2_high, unsigned char *w3_, unsigned int _w3_high, unsigned char *w4_, unsigned int _w4_high)
+extern "C" DynamicStrings_String FormatStrings_Sprintf4 (DynamicStrings_String fmt, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high, const unsigned char *w4_, unsigned int _w4_high)
 {
   int i;
   DynamicStrings_String s;
@@ -705,13 +705,13 @@ DynamicStrings_String FormatStrings_Sprintf4 (DynamicStrings_String fmt, unsigne
   memcpy (w4, w4_, _w4_high+1);
 
   DSdbEnter ();
-  fmt = FormatStrings_HandleEscape (fmt);
-  i = 0;
-  s = FormatString (fmt, &i, DynamicStrings_InitString ((char *) "", 0), (unsigned char *) w1, _w1_high);
-  s = FormatString (fmt, &i, s, (unsigned char *) w2, _w2_high);
-  s = FormatString (fmt, &i, s, (unsigned char *) w3, _w3_high);
-  s = FormatString (fmt, &i, s, (unsigned char *) w4, _w4_high);
-  s = HandlePercent (fmt, s, i);
+  fmt = static_cast<DynamicStrings_String> (FormatStrings_HandleEscape (fmt));
+  i = static_cast<int> (0);
+  s = static_cast<DynamicStrings_String> (FormatString (fmt, &i, DynamicStrings_InitString ((const char *) "", 0), (const unsigned char *) w1, _w1_high));
+  s = static_cast<DynamicStrings_String> (FormatString (fmt, &i, s, (const unsigned char *) w2, _w2_high));
+  s = static_cast<DynamicStrings_String> (FormatString (fmt, &i, s, (const unsigned char *) w3, _w3_high));
+  s = static_cast<DynamicStrings_String> (FormatString (fmt, &i, s, (const unsigned char *) w4, _w4_high));
+  s = static_cast<DynamicStrings_String> (HandlePercent (fmt, s, i));
   DSdbExit (s);
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -726,7 +726,7 @@ DynamicStrings_String FormatStrings_Sprintf4 (DynamicStrings_String fmt, unsigne
                   a single [any] character.
 */
 
-DynamicStrings_String FormatStrings_HandleEscape (DynamicStrings_String s)
+extern "C" DynamicStrings_String FormatStrings_HandleEscape (DynamicStrings_String s)
 {
   DynamicStrings_String d;
   int i;
@@ -735,57 +735,57 @@ DynamicStrings_String FormatStrings_HandleEscape (DynamicStrings_String s)
   unsigned char b;
 
   DSdbEnter ();
-  d = DynamicStrings_InitString ((char *) "", 0);
-  i = DynamicStrings_Index (s, '\\', 0);
-  j = 0;
+  d = static_cast<DynamicStrings_String> (DynamicStrings_InitString ((const char *) "", 0));
+  i = static_cast<int> (DynamicStrings_Index (s, '\\', 0));
+  j = static_cast<int> (0);
   while (i >= 0)
     {
       if (i > 0)
         {
           /* initially i might be zero which means the end of the string, which is not what we want.  */
-          d = DynamicStrings_ConCat (d, DynamicStrings_Slice (s, j, i));
+          d = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (d, DynamicStrings_Slice (s, j, i)));
         }
-      ch = DynamicStrings_char (s, i+1);
+      ch = static_cast<char> (DynamicStrings_char (s, i+1));
       if (ch == 'a')
         {
           /* requires a bell.  */
-          d = DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ASCII_bel)));
+          d = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ASCII_bel))));
         }
       else if (ch == 'b')
         {
           /* avoid dangling else.  */
           /* requires a backspace.  */
-          d = DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ASCII_bs)));
+          d = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ASCII_bs))));
         }
       else if (ch == 'e')
         {
           /* avoid dangling else.  */
           /* requires a escape.  */
-          d = DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ASCII_esc)));
+          d = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ASCII_esc))));
         }
       else if (ch == 'f')
         {
           /* avoid dangling else.  */
           /* requires a formfeed.  */
-          d = DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ASCII_ff)));
+          d = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ASCII_ff))));
         }
       else if (ch == 'n')
         {
           /* avoid dangling else.  */
           /* requires a newline.  */
-          d = DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ASCII_nl)));
+          d = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ASCII_nl))));
         }
       else if (ch == 'r')
         {
           /* avoid dangling else.  */
           /* requires a carriage return.  */
-          d = DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ASCII_cr)));
+          d = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ASCII_cr))));
         }
       else if (ch == 't')
         {
           /* avoid dangling else.  */
           /* requires a tab.  */
-          d = DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ASCII_tab)));
+          d = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ASCII_tab))));
         }
       else if (ch == 'x')
         {
@@ -798,7 +798,7 @@ DynamicStrings_String FormatStrings_HandleEscape (DynamicStrings_String s)
               if (isHex (DynamicStrings_char (s, i+1)))
                 {
                   b = (unsigned char ) ((((unsigned int ) (b))*0x010)+(toHex (DynamicStrings_char (s, i+1))));
-                  d = DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar ((char ) (b))));
+                  d = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar ((char ) (b)))));
                 }
             }
         }
@@ -816,30 +816,30 @@ DynamicStrings_String FormatStrings_HandleEscape (DynamicStrings_String s)
                   b = (unsigned char ) ((((unsigned int ) (b))*8)+(toOct (DynamicStrings_char (s, i+1))));
                 }
             }
-          d = DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar ((char ) (b))));
+          d = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar ((char ) (b)))));
         }
       else
         {
           /* avoid dangling else.  */
           /* copy escaped character.  */
-          d = DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ch)));
+          d = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_InitStringChar (ch))));
         }
       i += 2;
       j = i;
-      i = DynamicStrings_Index (s, '\\', (unsigned int ) (i));
+      i = static_cast<int> (DynamicStrings_Index (s, '\\', (unsigned int ) (i)));
     }
   /* s := Assign(s, Mark(ConCat(d, Mark(Slice(s, j, 0))))) ;    dont Mark(s) in the Slice as we Assign contents  */
-  s = DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_Slice (DynamicStrings_Mark (s), j, 0)));
+  s = static_cast<DynamicStrings_String> (DynamicStrings_ConCat (d, DynamicStrings_Mark (DynamicStrings_Slice (DynamicStrings_Mark (s), j, 0))));
   DSdbExit (s);
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
 
-void _M2_FormatStrings_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_FormatStrings_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_FormatStrings_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_FormatStrings_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GFormatStrings.h b/gcc/m2/mc-boot/GFormatStrings.h
index 1a8b248ad8e..82ce715ea2f 100644
--- a/gcc/m2/mc-boot/GFormatStrings.h
+++ b/gcc/m2/mc-boot/GFormatStrings.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_FormatStrings_H)
 #   define _FormatStrings_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
@@ -62,25 +62,25 @@ EXTERN DynamicStrings_String FormatStrings_Sprintf0 (DynamicStrings_String fmt);
               entity, w. It only formats the first %s or %d with n.
 */
 
-EXTERN DynamicStrings_String FormatStrings_Sprintf1 (DynamicStrings_String fmt, unsigned char *w_, unsigned int _w_high);
+EXTERN DynamicStrings_String FormatStrings_Sprintf1 (DynamicStrings_String fmt, const unsigned char *w_, unsigned int _w_high);
 
 /*
    Sprintf2 - returns a string, fmt, which has been formatted.
 */
 
-EXTERN DynamicStrings_String FormatStrings_Sprintf2 (DynamicStrings_String fmt, unsigned char *w1_, unsigned int _w1_high, unsigned char *w2_, unsigned int _w2_high);
+EXTERN DynamicStrings_String FormatStrings_Sprintf2 (DynamicStrings_String fmt, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high);
 
 /*
    Sprintf3 - returns a string, fmt, which has been formatted.
 */
 
-EXTERN DynamicStrings_String FormatStrings_Sprintf3 (DynamicStrings_String fmt, unsigned char *w1_, unsigned int _w1_high, unsigned char *w2_, unsigned int _w2_high, unsigned char *w3_, unsigned int _w3_high);
+EXTERN DynamicStrings_String FormatStrings_Sprintf3 (DynamicStrings_String fmt, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high);
 
 /*
    Sprintf4 - returns a string, fmt, which has been formatted.
 */
 
-EXTERN DynamicStrings_String FormatStrings_Sprintf4 (DynamicStrings_String fmt, unsigned char *w1_, unsigned int _w1_high, unsigned char *w2_, unsigned int _w2_high, unsigned char *w3_, unsigned int _w3_high, unsigned char *w4_, unsigned int _w4_high);
+EXTERN DynamicStrings_String FormatStrings_Sprintf4 (DynamicStrings_String fmt, const unsigned char *w1_, unsigned int _w1_high, const unsigned char *w2_, unsigned int _w2_high, const unsigned char *w3_, unsigned int _w3_high, const unsigned char *w4_, unsigned int _w4_high);
 
 /*
    HandleEscape - translates \a, \b, \e, \f, 
diff --git a/gcc/m2/mc-boot/GFpuIO.c b/gcc/m2/mc-boot/GFpuIO.c
index 2d603fc84ee..fab409088fe 100644
--- a/gcc/m2/mc-boot/GFpuIO.c
+++ b/gcc/m2/mc-boot/GFpuIO.c
@@ -51,80 +51,80 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #   include "GStringConvert.h"
 
 #   define MaxLineLength 100
-void FpuIO_ReadReal (double *x);
+extern "C" void FpuIO_ReadReal (double *x);
 
 /*
    WriteReal - converts a REAL number, x, which has a, TotalWidth, and
                FractionWidth into, string, a.
 */
 
-void FpuIO_WriteReal (double x, unsigned int TotalWidth, unsigned int FractionWidth);
+extern "C" void FpuIO_WriteReal (double x, unsigned int TotalWidth, unsigned int FractionWidth);
 
 /*
    WriteReal - converts a REAL number, x, which has a, TotalWidth, and
                FractionWidth into, string, a.
 */
 
-void FpuIO_StrToReal (char *a_, unsigned int _a_high, double *x);
+extern "C" void FpuIO_StrToReal (const char *a_, unsigned int _a_high, double *x);
 
 /*
    RealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
                FractionWidth into a string.
 */
 
-void FpuIO_RealToStr (double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high);
-void FpuIO_ReadLongReal (long double *x);
+extern "C" void FpuIO_RealToStr (double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high);
+extern "C" void FpuIO_ReadLongReal (long double *x);
 
 /*
    WriteLongReal - converts a LONGREAL number, x, which has a, TotalWidth, and
                    FractionWidth into a string.
 */
 
-void FpuIO_WriteLongReal (long double x, unsigned int TotalWidth, unsigned int FractionWidth);
+extern "C" void FpuIO_WriteLongReal (long double x, unsigned int TotalWidth, unsigned int FractionWidth);
 
 /*
    WriteLongReal - converts a LONGREAL number, x, which has a, TotalWidth, and
                    FractionWidth into a string.
 */
 
-void FpuIO_StrToLongReal (char *a_, unsigned int _a_high, long double *x);
+extern "C" void FpuIO_StrToLongReal (const char *a_, unsigned int _a_high, long double *x);
 
 /*
    LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
                    FractionWidth into a string.
 */
 
-void FpuIO_LongRealToStr (long double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high);
+extern "C" void FpuIO_LongRealToStr (long double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high);
 
 /*
    LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
                    FractionWidth into a string.
 */
 
-void FpuIO_ReadLongInt (long int *x);
+extern "C" void FpuIO_ReadLongInt (long int *x);
 
 /*
    LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
                    FractionWidth into a string.
 */
 
-void FpuIO_WriteLongInt (long int x, unsigned int n);
+extern "C" void FpuIO_WriteLongInt (long int x, unsigned int n);
 
 /*
    LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
                    FractionWidth into a string.
 */
 
-void FpuIO_StrToLongInt (char *a_, unsigned int _a_high, long int *x);
+extern "C" void FpuIO_StrToLongInt (const char *a_, unsigned int _a_high, long int *x);
 
 /*
    LongRealToStr - converts a LONGREAL number, Real, which has, TotalWidth, and
                    FractionWidth into a string.
 */
 
-void FpuIO_LongIntToStr (long int x, unsigned int n, char *a, unsigned int _a_high);
+extern "C" void FpuIO_LongIntToStr (long int x, unsigned int n, char *a, unsigned int _a_high);
 
-void FpuIO_ReadReal (double *x)
+extern "C" void FpuIO_ReadReal (double *x)
 {
   typedef struct _T1_a _T1;
 
@@ -143,7 +143,7 @@ if defined(GM2_DEBUG_FPUIO)
 #endif
   */
   StrIO_ReadString ((char *) &a.array[0], MaxLineLength);
-  FpuIO_StrToReal ((char *) &a.array[0], MaxLineLength, x);
+  FpuIO_StrToReal ((const char *) &a.array[0], MaxLineLength, x);
 }
 
 
@@ -152,7 +152,7 @@ if defined(GM2_DEBUG_FPUIO)
                FractionWidth into, string, a.
 */
 
-void FpuIO_WriteReal (double x, unsigned int TotalWidth, unsigned int FractionWidth)
+extern "C" void FpuIO_WriteReal (double x, unsigned int TotalWidth, unsigned int FractionWidth)
 {
   typedef struct _T2_a _T2;
 
@@ -160,7 +160,7 @@ void FpuIO_WriteReal (double x, unsigned int TotalWidth, unsigned int FractionWi
   _T2 a;
 
   FpuIO_RealToStr (x, TotalWidth, FractionWidth, (char *) &a.array[0], MaxLineLength);
-  StrIO_WriteString ((char *) &a.array[0], MaxLineLength);
+  StrIO_WriteString ((const char *) &a.array[0], MaxLineLength);
 }
 
 
@@ -169,7 +169,7 @@ void FpuIO_WriteReal (double x, unsigned int TotalWidth, unsigned int FractionWi
                FractionWidth into, string, a.
 */
 
-void FpuIO_StrToReal (char *a_, unsigned int _a_high, double *x)
+extern "C" void FpuIO_StrToReal (const char *a_, unsigned int _a_high, double *x)
 {
   long double lr;
   char a[_a_high+1];
@@ -177,7 +177,7 @@ void FpuIO_StrToReal (char *a_, unsigned int _a_high, double *x)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  FpuIO_StrToLongReal ((char *) a, _a_high, &lr);  /* let StrToLongReal do the work and we convert the result back to REAL  */
+  FpuIO_StrToLongReal ((const char *) a, _a_high, &lr);  /* let StrToLongReal do the work and we convert the result back to REAL  */
   (*x) = (double ) (lr);  /* let StrToLongReal do the work and we convert the result back to REAL  */
 }
 
@@ -187,7 +187,7 @@ void FpuIO_StrToReal (char *a_, unsigned int _a_high, double *x)
                FractionWidth into a string.
 */
 
-void FpuIO_RealToStr (double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high)
+extern "C" void FpuIO_RealToStr (double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high)
 {
   long double lr;
 
@@ -195,7 +195,7 @@ void FpuIO_RealToStr (double x, unsigned int TotalWidth, unsigned int FractionWi
   FpuIO_LongRealToStr (lr, TotalWidth, FractionWidth, (char *) a, _a_high);
 }
 
-void FpuIO_ReadLongReal (long double *x)
+extern "C" void FpuIO_ReadLongReal (long double *x)
 {
   typedef struct _T3_a _T3;
 
@@ -203,7 +203,7 @@ void FpuIO_ReadLongReal (long double *x)
   _T3 a;
 
   StrIO_ReadString ((char *) &a.array[0], MaxLineLength);
-  FpuIO_StrToLongReal ((char *) &a.array[0], MaxLineLength, x);
+  FpuIO_StrToLongReal ((const char *) &a.array[0], MaxLineLength, x);
 }
 
 
@@ -212,7 +212,7 @@ void FpuIO_ReadLongReal (long double *x)
                    FractionWidth into a string.
 */
 
-void FpuIO_WriteLongReal (long double x, unsigned int TotalWidth, unsigned int FractionWidth)
+extern "C" void FpuIO_WriteLongReal (long double x, unsigned int TotalWidth, unsigned int FractionWidth)
 {
   typedef struct _T4_a _T4;
 
@@ -220,7 +220,7 @@ void FpuIO_WriteLongReal (long double x, unsigned int TotalWidth, unsigned int F
   _T4 a;
 
   FpuIO_LongRealToStr (x, TotalWidth, FractionWidth, (char *) &a.array[0], MaxLineLength);
-  StrIO_WriteString ((char *) &a.array[0], MaxLineLength);
+  StrIO_WriteString ((const char *) &a.array[0], MaxLineLength);
 }
 
 
@@ -229,7 +229,7 @@ void FpuIO_WriteLongReal (long double x, unsigned int TotalWidth, unsigned int F
                    FractionWidth into a string.
 */
 
-void FpuIO_StrToLongReal (char *a_, unsigned int _a_high, long double *x)
+extern "C" void FpuIO_StrToLongReal (const char *a_, unsigned int _a_high, long double *x)
 {
   unsigned int found;
   DynamicStrings_String s;
@@ -238,9 +238,9 @@ void FpuIO_StrToLongReal (char *a_, unsigned int _a_high, long double *x)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  s = DynamicStrings_InitString ((char *) a, _a_high);
-  (*x) = StringConvert_StringToLongreal (s, &found);
-  s = DynamicStrings_KillString (s);
+  s = static_cast<DynamicStrings_String> (DynamicStrings_InitString ((const char *) a, _a_high));
+  (*x) = static_cast<long double> (StringConvert_StringToLongreal (s, &found));
+  s = static_cast<DynamicStrings_String> (DynamicStrings_KillString (s));
 }
 
 
@@ -249,13 +249,13 @@ void FpuIO_StrToLongReal (char *a_, unsigned int _a_high, long double *x)
                    FractionWidth into a string.
 */
 
-void FpuIO_LongRealToStr (long double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high)
+extern "C" void FpuIO_LongRealToStr (long double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high)
 {
   DynamicStrings_String s;
 
-  s = StringConvert_LongrealToString (x, TotalWidth, FractionWidth);
+  s = static_cast<DynamicStrings_String> (StringConvert_LongrealToString (x, TotalWidth, FractionWidth));
   DynamicStrings_CopyOut ((char *) a, _a_high, s);
-  s = DynamicStrings_KillString (s);
+  s = static_cast<DynamicStrings_String> (DynamicStrings_KillString (s));
 }
 
 
@@ -264,7 +264,7 @@ void FpuIO_LongRealToStr (long double x, unsigned int TotalWidth, unsigned int F
                    FractionWidth into a string.
 */
 
-void FpuIO_ReadLongInt (long int *x)
+extern "C" void FpuIO_ReadLongInt (long int *x)
 {
   typedef struct _T5_a _T5;
 
@@ -272,7 +272,7 @@ void FpuIO_ReadLongInt (long int *x)
   _T5 a;
 
   StrIO_ReadString ((char *) &a.array[0], MaxLineLength);
-  FpuIO_StrToLongInt ((char *) &a.array[0], MaxLineLength, x);
+  FpuIO_StrToLongInt ((const char *) &a.array[0], MaxLineLength, x);
 }
 
 
@@ -281,7 +281,7 @@ void FpuIO_ReadLongInt (long int *x)
                    FractionWidth into a string.
 */
 
-void FpuIO_WriteLongInt (long int x, unsigned int n)
+extern "C" void FpuIO_WriteLongInt (long int x, unsigned int n)
 {
   typedef struct _T6_a _T6;
 
@@ -289,7 +289,7 @@ void FpuIO_WriteLongInt (long int x, unsigned int n)
   _T6 a;
 
   FpuIO_LongIntToStr (x, n, (char *) &a.array[0], MaxLineLength);
-  StrIO_WriteString ((char *) &a.array[0], MaxLineLength);
+  StrIO_WriteString ((const char *) &a.array[0], MaxLineLength);
 }
 
 
@@ -298,7 +298,7 @@ void FpuIO_WriteLongInt (long int x, unsigned int n)
                    FractionWidth into a string.
 */
 
-void FpuIO_StrToLongInt (char *a_, unsigned int _a_high, long int *x)
+extern "C" void FpuIO_StrToLongInt (const char *a_, unsigned int _a_high, long int *x)
 {
   DynamicStrings_String s;
   unsigned int found;
@@ -307,9 +307,9 @@ void FpuIO_StrToLongInt (char *a_, unsigned int _a_high, long int *x)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  s = DynamicStrings_InitString ((char *) a, _a_high);
-  (*x) = StringConvert_StringToLongInteger (s, 10, &found);
-  s = DynamicStrings_KillString (s);
+  s = static_cast<DynamicStrings_String> (DynamicStrings_InitString ((const char *) a, _a_high));
+  (*x) = static_cast<long int> (StringConvert_StringToLongInteger (s, 10, &found));
+  s = static_cast<DynamicStrings_String> (DynamicStrings_KillString (s));
 }
 
 
@@ -318,19 +318,19 @@ void FpuIO_StrToLongInt (char *a_, unsigned int _a_high, long int *x)
                    FractionWidth into a string.
 */
 
-void FpuIO_LongIntToStr (long int x, unsigned int n, char *a, unsigned int _a_high)
+extern "C" void FpuIO_LongIntToStr (long int x, unsigned int n, char *a, unsigned int _a_high)
 {
   DynamicStrings_String s;
 
-  s = StringConvert_LongIntegerToString (x, n, ' ', FALSE, 10, TRUE);
+  s = static_cast<DynamicStrings_String> (StringConvert_LongIntegerToString (x, n, ' ', FALSE, 10, TRUE));
   DynamicStrings_CopyOut ((char *) a, _a_high, s);
-  s = DynamicStrings_KillString (s);
+  s = static_cast<DynamicStrings_String> (DynamicStrings_KillString (s));
 }
 
-void _M2_FpuIO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_FpuIO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_FpuIO_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_FpuIO_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GFpuIO.h b/gcc/m2/mc-boot/GFpuIO.h
index db412a85f59..fd070ee05d8 100644
--- a/gcc/m2/mc-boot/GFpuIO.h
+++ b/gcc/m2/mc-boot/GFpuIO.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_FpuIO_H)
 #   define _FpuIO_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
@@ -49,15 +49,15 @@ extern "C" {
 
 EXTERN void FpuIO_ReadReal (double *x);
 EXTERN void FpuIO_WriteReal (double x, unsigned int TotalWidth, unsigned int FractionWidth);
-EXTERN void FpuIO_StrToReal (char *a_, unsigned int _a_high, double *x);
+EXTERN void FpuIO_StrToReal (const char *a_, unsigned int _a_high, double *x);
 EXTERN void FpuIO_RealToStr (double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high);
 EXTERN void FpuIO_ReadLongReal (long double *x);
 EXTERN void FpuIO_WriteLongReal (long double x, unsigned int TotalWidth, unsigned int FractionWidth);
-EXTERN void FpuIO_StrToLongReal (char *a_, unsigned int _a_high, long double *x);
+EXTERN void FpuIO_StrToLongReal (const char *a_, unsigned int _a_high, long double *x);
 EXTERN void FpuIO_LongRealToStr (long double x, unsigned int TotalWidth, unsigned int FractionWidth, char *a, unsigned int _a_high);
 EXTERN void FpuIO_ReadLongInt (long int *x);
 EXTERN void FpuIO_WriteLongInt (long int x, unsigned int n);
-EXTERN void FpuIO_StrToLongInt (char *a_, unsigned int _a_high, long int *x);
+EXTERN void FpuIO_StrToLongInt (const char *a_, unsigned int _a_high, long int *x);
 EXTERN void FpuIO_LongIntToStr (long int x, unsigned int n, char *a, unsigned int _a_high);
 #   ifdef __cplusplus
 }
diff --git a/gcc/m2/mc-boot/GIO.c b/gcc/m2/mc-boot/GIO.c
index 557300fef72..643fe1ed7e9 100644
--- a/gcc/m2/mc-boot/GIO.c
+++ b/gcc/m2/mc-boot/GIO.c
@@ -69,23 +69,23 @@ static _T1 fdState;
    IsDefaultFd - returns TRUE if, fd, is 0, 1 or 2.
 */
 
-void IO_Read (char *ch);
+extern "C" void IO_Read (char *ch);
 
 /*
    doWrite - performs the write of a single character, ch,
              onto fd or f.
 */
 
-void IO_Write (char ch);
+extern "C" void IO_Write (char ch);
 
 /*
    doWrite - performs the write of a single character, ch,
              onto fd or f.
 */
 
-void IO_Error (char ch);
-void IO_UnBufferedMode (int fd, unsigned int input);
-void IO_BufferedMode (int fd, unsigned int input);
+extern "C" void IO_Error (char ch);
+extern "C" void IO_UnBufferedMode (int fd, unsigned int input);
+extern "C" void IO_BufferedMode (int fd, unsigned int input);
 
 /*
    EchoOn - turns on echoing for file descriptor, fd.  This
@@ -94,7 +94,7 @@ void IO_BufferedMode (int fd, unsigned int input);
             which is attached to a particular piece of hardware.
 */
 
-void IO_EchoOn (int fd, unsigned int input);
+extern "C" void IO_EchoOn (int fd, unsigned int input);
 
 /*
    EchoOff - turns off echoing for file descriptor, fd.  This
@@ -103,7 +103,7 @@ void IO_EchoOn (int fd, unsigned int input);
              which is attached to a particular piece of hardware.
 */
 
-void IO_EchoOff (int fd, unsigned int input);
+extern "C" void IO_EchoOff (int fd, unsigned int input);
 
 /*
    IsDefaultFd - returns TRUE if, fd, is 0, 1 or 2.
@@ -173,7 +173,7 @@ static void doWrite (int fd, FIO_File f, char ch)
         {
           for (;;)
           {
-            r = libc_write (FIO_GetUnixFileDescriptor (f), &ch, (size_t) 1);
+            r = static_cast<int> (libc_write (FIO_GetUnixFileDescriptor (f), &ch, static_cast<size_t> (1)));
             if (r == 1)
               {
                 return;
@@ -181,7 +181,7 @@ static void doWrite (int fd, FIO_File f, char ch)
             else if (r == -1)
               {
                 /* avoid dangling else.  */
-                r = errno_geterrno ();
+                r = static_cast<int> (errno_geterrno ());
                 if ((r != errno_EAGAIN) && (r != errno_EINTR))
                   {
                     fdState.array[fd].IsEof = TRUE;
@@ -225,22 +225,22 @@ static void doraw (termios_TERMIOS term)
     *           termios_p->c_cflag &= ~(CSIZE | PARENB);
     *           termios_p->c_cflag |= CS8;
   */
-  setFlag (term, (termios_Flag) termios_ignbrk, FALSE);
-  setFlag (term, (termios_Flag) termios_ibrkint, FALSE);
-  setFlag (term, (termios_Flag) termios_iparmrk, FALSE);
-  setFlag (term, (termios_Flag) termios_istrip, FALSE);
-  setFlag (term, (termios_Flag) termios_inlcr, FALSE);
-  setFlag (term, (termios_Flag) termios_igncr, FALSE);
-  setFlag (term, (termios_Flag) termios_icrnl, FALSE);
-  setFlag (term, (termios_Flag) termios_ixon, FALSE);
-  setFlag (term, (termios_Flag) termios_opost, FALSE);
-  setFlag (term, (termios_Flag) termios_lecho, FALSE);
-  setFlag (term, (termios_Flag) termios_lechonl, FALSE);
-  setFlag (term, (termios_Flag) termios_licanon, FALSE);
-  setFlag (term, (termios_Flag) termios_lisig, FALSE);
-  setFlag (term, (termios_Flag) termios_liexten, FALSE);
-  setFlag (term, (termios_Flag) termios_parenb, FALSE);
-  setFlag (term, (termios_Flag) termios_cs8, TRUE);
+  setFlag (term, static_cast<termios_Flag> (termios_ignbrk), FALSE);
+  setFlag (term, static_cast<termios_Flag> (termios_ibrkint), FALSE);
+  setFlag (term, static_cast<termios_Flag> (termios_iparmrk), FALSE);
+  setFlag (term, static_cast<termios_Flag> (termios_istrip), FALSE);
+  setFlag (term, static_cast<termios_Flag> (termios_inlcr), FALSE);
+  setFlag (term, static_cast<termios_Flag> (termios_igncr), FALSE);
+  setFlag (term, static_cast<termios_Flag> (termios_icrnl), FALSE);
+  setFlag (term, static_cast<termios_Flag> (termios_ixon), FALSE);
+  setFlag (term, static_cast<termios_Flag> (termios_opost), FALSE);
+  setFlag (term, static_cast<termios_Flag> (termios_lecho), FALSE);
+  setFlag (term, static_cast<termios_Flag> (termios_lechonl), FALSE);
+  setFlag (term, static_cast<termios_Flag> (termios_licanon), FALSE);
+  setFlag (term, static_cast<termios_Flag> (termios_lisig), FALSE);
+  setFlag (term, static_cast<termios_Flag> (termios_liexten), FALSE);
+  setFlag (term, static_cast<termios_Flag> (termios_parenb), FALSE);
+  setFlag (term, static_cast<termios_Flag> (termios_cs8), TRUE);
 }
 
 
@@ -262,20 +262,20 @@ static void dononraw (termios_TERMIOS term)
     *           termios_p->c_cflag &= ~(CSIZE | PARENB);
     *           termios_p->c_cflag |= CS8;
   */
-  setFlag (term, (termios_Flag) termios_ignbrk, TRUE);
-  setFlag (term, (termios_Flag) termios_ibrkint, TRUE);
-  setFlag (term, (termios_Flag) termios_iparmrk, TRUE);
-  setFlag (term, (termios_Flag) termios_istrip, TRUE);
-  setFlag (term, (termios_Flag) termios_inlcr, TRUE);
-  setFlag (term, (termios_Flag) termios_igncr, TRUE);
-  setFlag (term, (termios_Flag) termios_icrnl, TRUE);
-  setFlag (term, (termios_Flag) termios_ixon, TRUE);
-  setFlag (term, (termios_Flag) termios_opost, TRUE);
-  setFlag (term, (termios_Flag) termios_lecho, TRUE);
-  setFlag (term, (termios_Flag) termios_lechonl, TRUE);
-  setFlag (term, (termios_Flag) termios_licanon, TRUE);
-  setFlag (term, (termios_Flag) termios_lisig, TRUE);
-  setFlag (term, (termios_Flag) termios_liexten, TRUE);
+  setFlag (term, static_cast<termios_Flag> (termios_ignbrk), TRUE);
+  setFlag (term, static_cast<termios_Flag> (termios_ibrkint), TRUE);
+  setFlag (term, static_cast<termios_Flag> (termios_iparmrk), TRUE);
+  setFlag (term, static_cast<termios_Flag> (termios_istrip), TRUE);
+  setFlag (term, static_cast<termios_Flag> (termios_inlcr), TRUE);
+  setFlag (term, static_cast<termios_Flag> (termios_igncr), TRUE);
+  setFlag (term, static_cast<termios_Flag> (termios_icrnl), TRUE);
+  setFlag (term, static_cast<termios_Flag> (termios_ixon), TRUE);
+  setFlag (term, static_cast<termios_Flag> (termios_opost), TRUE);
+  setFlag (term, static_cast<termios_Flag> (termios_lecho), TRUE);
+  setFlag (term, static_cast<termios_Flag> (termios_lechonl), TRUE);
+  setFlag (term, static_cast<termios_Flag> (termios_licanon), TRUE);
+  setFlag (term, static_cast<termios_Flag> (termios_lisig), TRUE);
+  setFlag (term, static_cast<termios_Flag> (termios_liexten), TRUE);
 }
 
 
@@ -298,7 +298,7 @@ static void Init (void)
    IsDefaultFd - returns TRUE if, fd, is 0, 1 or 2.
 */
 
-void IO_Read (char *ch)
+extern "C" void IO_Read (char *ch)
 {
   int r;
 
@@ -308,13 +308,13 @@ void IO_Read (char *ch)
     {
       if (fdState.array[0].IsEof)
         {
-          (*ch) = ASCII_eof;
+          (*ch) = static_cast<char> (ASCII_eof);
         }
       else
         {
           for (;;)
           {
-            r = libc_read (FIO_GetUnixFileDescriptor (FIO_StdIn), ch, (size_t) 1);
+            r = static_cast<int> (libc_read (FIO_GetUnixFileDescriptor (FIO_StdIn), ch, static_cast<size_t> (1)));
             if (r == 1)
               {
                 return;
@@ -322,7 +322,7 @@ void IO_Read (char *ch)
             else if (r == -1)
               {
                 /* avoid dangling else.  */
-                r = errno_geterrno ();
+                r = static_cast<int> (errno_geterrno ());
                 if (r != errno_EAGAIN)
                   {
                     fdState.array[0].IsEof = TRUE;
@@ -335,7 +335,7 @@ void IO_Read (char *ch)
     }
   else
     {
-      (*ch) = FIO_ReadChar (FIO_StdIn);
+      (*ch) = static_cast<char> (FIO_ReadChar (FIO_StdIn));
     }
 }
 
@@ -345,7 +345,7 @@ void IO_Read (char *ch)
              onto fd or f.
 */
 
-void IO_Write (char ch)
+extern "C" void IO_Write (char ch)
 {
   doWrite (1, FIO_StdOut, ch);
 }
@@ -356,12 +356,12 @@ void IO_Write (char ch)
              onto fd or f.
 */
 
-void IO_Error (char ch)
+extern "C" void IO_Error (char ch)
 {
   doWrite (2, FIO_StdErr, ch);
 }
 
-void IO_UnBufferedMode (int fd, unsigned int input)
+extern "C" void IO_UnBufferedMode (int fd, unsigned int input)
 {
   termios_TERMIOS term;
   int result;
@@ -370,23 +370,23 @@ void IO_UnBufferedMode (int fd, unsigned int input)
     {
       fdState.array[fd].IsRaw = TRUE;
     }
-  term = termios_InitTermios ();
+  term = static_cast<termios_TERMIOS> (termios_InitTermios ());
   if ((termios_tcgetattr (fd, term)) == 0)
     {
       doraw (term);
       if (input)
         {
-          result = termios_tcsetattr (fd, termios_tcsflush (), term);
+          result = static_cast<int> (termios_tcsetattr (fd, termios_tcsflush (), term));
         }
       else
         {
-          result = termios_tcsetattr (fd, termios_tcsdrain (), term);
+          result = static_cast<int> (termios_tcsetattr (fd, termios_tcsdrain (), term));
         }
     }
-  term = termios_KillTermios (term);
+  term = static_cast<termios_TERMIOS> (termios_KillTermios (term));
 }
 
-void IO_BufferedMode (int fd, unsigned int input)
+extern "C" void IO_BufferedMode (int fd, unsigned int input)
 {
   termios_TERMIOS term;
   int r;
@@ -395,20 +395,20 @@ void IO_BufferedMode (int fd, unsigned int input)
     {
       fdState.array[fd].IsRaw = FALSE;
     }
-  term = termios_InitTermios ();
+  term = static_cast<termios_TERMIOS> (termios_InitTermios ());
   if ((termios_tcgetattr (fd, term)) == 0)
     {
       dononraw (term);
       if (input)
         {
-          r = termios_tcsetattr (fd, termios_tcsflush (), term);
+          r = static_cast<int> (termios_tcsetattr (fd, termios_tcsflush (), term));
         }
       else
         {
-          r = termios_tcsetattr (fd, termios_tcsdrain (), term);
+          r = static_cast<int> (termios_tcsetattr (fd, termios_tcsdrain (), term));
         }
     }
-  term = termios_KillTermios (term);
+  term = static_cast<termios_TERMIOS> (termios_KillTermios (term));
 }
 
 
@@ -419,25 +419,25 @@ void IO_BufferedMode (int fd, unsigned int input)
             which is attached to a particular piece of hardware.
 */
 
-void IO_EchoOn (int fd, unsigned int input)
+extern "C" void IO_EchoOn (int fd, unsigned int input)
 {
   termios_TERMIOS term;
   int result;
 
-  term = termios_InitTermios ();
+  term = static_cast<termios_TERMIOS> (termios_InitTermios ());
   if ((termios_tcgetattr (fd, term)) == 0)
     {
-      setFlag (term, (termios_Flag) termios_lecho, TRUE);
+      setFlag (term, static_cast<termios_Flag> (termios_lecho), TRUE);
       if (input)
         {
-          result = termios_tcsetattr (fd, termios_tcsflush (), term);
+          result = static_cast<int> (termios_tcsetattr (fd, termios_tcsflush (), term));
         }
       else
         {
-          result = termios_tcsetattr (fd, termios_tcsdrain (), term);
+          result = static_cast<int> (termios_tcsetattr (fd, termios_tcsdrain (), term));
         }
     }
-  term = termios_KillTermios (term);
+  term = static_cast<termios_TERMIOS> (termios_KillTermios (term));
 }
 
 
@@ -448,32 +448,32 @@ void IO_EchoOn (int fd, unsigned int input)
              which is attached to a particular piece of hardware.
 */
 
-void IO_EchoOff (int fd, unsigned int input)
+extern "C" void IO_EchoOff (int fd, unsigned int input)
 {
   termios_TERMIOS term;
   int result;
 
-  term = termios_InitTermios ();
+  term = static_cast<termios_TERMIOS> (termios_InitTermios ());
   if ((termios_tcgetattr (fd, term)) == 0)
     {
-      setFlag (term, (termios_Flag) termios_lecho, FALSE);
+      setFlag (term, static_cast<termios_Flag> (termios_lecho), FALSE);
       if (input)
         {
-          result = termios_tcsetattr (fd, termios_tcsflush (), term);
+          result = static_cast<int> (termios_tcsetattr (fd, termios_tcsflush (), term));
         }
       else
         {
-          result = termios_tcsetattr (fd, termios_tcsdrain (), term);
+          result = static_cast<int> (termios_tcsetattr (fd, termios_tcsdrain (), term));
         }
     }
-  term = termios_KillTermios (term);
+  term = static_cast<termios_TERMIOS> (termios_KillTermios (term));
 }
 
-void _M2_IO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_IO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
   Init ();
 }
 
-void _M2_IO_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_IO_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GIO.h b/gcc/m2/mc-boot/GIO.h
index 80cae08c5df..dc40066bd51 100644
--- a/gcc/m2/mc-boot/GIO.h
+++ b/gcc/m2/mc-boot/GIO.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_IO_H)
 #   define _IO_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GIndexing.c b/gcc/m2/mc-boot/GIndexing.c
index 6bad5812c03..2d95069fae7 100644
--- a/gcc/m2/mc-boot/GIndexing.c
+++ b/gcc/m2/mc-boot/GIndexing.c
@@ -1,6 +1,6 @@
 /* do not edit automatically generated by mc from Indexing.  */
 /* Indexing provides a dynamic array of pointers.
-   Copyright (C) 2015-2019 Free Software Foundation, Inc.
+   Copyright (C) 2015-2022 Free Software Foundation, Inc.
 
 This file is part of GNU Modula-2.
 
@@ -53,18 +53,18 @@ Boston, MA 02110-1301, USA.  */
 typedef struct Indexing_IndexProcedure_p Indexing_IndexProcedure;
 
 #   define MinSize 128
-typedef struct _T1_r _T1;
+typedef struct _T2_r _T2;
 
 typedef void * *PtrToAddress;
 
-typedef _T1 *Indexing_Index;
+typedef _T2 *Indexing_Index;
 
 typedef unsigned char *PtrToByte;
 
 typedef void (*Indexing_IndexProcedure_t) (void *);
 struct Indexing_IndexProcedure_p { Indexing_IndexProcedure_t proc; };
 
-struct _T1_r {
+struct _T2_r {
                void *ArrayStart;
                unsigned int ArraySize;
                unsigned int Used;
@@ -79,99 +79,99 @@ struct _T1_r {
    InitIndex - creates and returns an Index.
 */
 
-Indexing_Index Indexing_InitIndex (unsigned int low);
+extern "C" Indexing_Index Indexing_InitIndex (unsigned int low);
 
 /*
    KillIndex - returns Index to free storage.
 */
 
-Indexing_Index Indexing_KillIndex (Indexing_Index i);
+extern "C" Indexing_Index Indexing_KillIndex (Indexing_Index i);
 
 /*
    DebugIndex - turns on debugging within an index.
 */
 
-Indexing_Index Indexing_DebugIndex (Indexing_Index i);
+extern "C" Indexing_Index Indexing_DebugIndex (Indexing_Index i);
 
 /*
    InBounds - returns TRUE if indice, n, is within the bounds
               of the dynamic array.
 */
 
-unsigned int Indexing_InBounds (Indexing_Index i, unsigned int n);
+extern "C" unsigned int Indexing_InBounds (Indexing_Index i, unsigned int n);
 
 /*
    HighIndice - returns the last legally accessible indice of this array.
 */
 
-unsigned int Indexing_HighIndice (Indexing_Index i);
+extern "C" unsigned int Indexing_HighIndice (Indexing_Index i);
 
 /*
    LowIndice - returns the first legally accessible indice of this array.
 */
 
-unsigned int Indexing_LowIndice (Indexing_Index i);
+extern "C" unsigned int Indexing_LowIndice (Indexing_Index i);
 
 /*
    PutIndice - places, a, into the dynamic array at position i[n]
 */
 
-void Indexing_PutIndice (Indexing_Index i, unsigned int n, void * a);
+extern "C" void Indexing_PutIndice (Indexing_Index i, unsigned int n, void * a);
 
 /*
    GetIndice - retrieves, element i[n] from the dynamic array.
 */
 
-void * Indexing_GetIndice (Indexing_Index i, unsigned int n);
+extern "C" void * Indexing_GetIndice (Indexing_Index i, unsigned int n);
 
 /*
    IsIndiceInIndex - returns TRUE if, a, is in the index, i.
 */
 
-unsigned int Indexing_IsIndiceInIndex (Indexing_Index i, void * a);
+extern "C" unsigned int Indexing_IsIndiceInIndex (Indexing_Index i, void * a);
 
 /*
    RemoveIndiceFromIndex - removes, a, from Index, i.
 */
 
-void Indexing_RemoveIndiceFromIndex (Indexing_Index i, void * a);
+extern "C" void Indexing_RemoveIndiceFromIndex (Indexing_Index i, void * a);
 
 /*
    DeleteIndice - delete i[j] from the array.
 */
 
-void Indexing_DeleteIndice (Indexing_Index i, unsigned int j);
+extern "C" void Indexing_DeleteIndice (Indexing_Index i, unsigned int j);
 
 /*
    IncludeIndiceIntoIndex - if the indice is not in the index, then
                             add it at the end.
 */
 
-void Indexing_IncludeIndiceIntoIndex (Indexing_Index i, void * a);
+extern "C" void Indexing_IncludeIndiceIntoIndex (Indexing_Index i, void * a);
 
 /*
    ForeachIndiceInIndexDo - for each j indice of i, call procedure p(i[j])
 */
 
-void Indexing_ForeachIndiceInIndexDo (Indexing_Index i, Indexing_IndexProcedure p);
+extern "C" void Indexing_ForeachIndiceInIndexDo (Indexing_Index i, Indexing_IndexProcedure p);
 
 
 /*
    InitIndex - creates and returns an Index.
 */
 
-Indexing_Index Indexing_InitIndex (unsigned int low)
+extern "C" Indexing_Index Indexing_InitIndex (unsigned int low)
 {
   Indexing_Index i;
 
-  Storage_ALLOCATE ((void **) &i, sizeof (_T1));
+  Storage_ALLOCATE ((void **) &i, sizeof (_T2));
   i->Low = low;
-  i->High = 0;
-  i->ArraySize = MinSize;
+  i->High = static_cast<unsigned int> (0);
+  i->ArraySize = static_cast<unsigned int> (MinSize);
   Storage_ALLOCATE (&i->ArrayStart, MinSize);
-  i->ArrayStart = libc_memset (i->ArrayStart, 0, (size_t) i->ArraySize);
+  i->ArrayStart = reinterpret_cast<void *> (libc_memset (i->ArrayStart, 0, static_cast<size_t> (i->ArraySize)));
   i->Debug = FALSE;
-  i->Used = 0;
+  i->Used = static_cast<unsigned int> (0);
   i->Map = (unsigned int) 0;
   return i;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -183,11 +183,11 @@ Indexing_Index Indexing_InitIndex (unsigned int low)
    KillIndex - returns Index to free storage.
 */
 
-Indexing_Index Indexing_KillIndex (Indexing_Index i)
+extern "C" Indexing_Index Indexing_KillIndex (Indexing_Index i)
 {
   Storage_DEALLOCATE (&i->ArrayStart, i->ArraySize);
-  Storage_DEALLOCATE ((void **) &i, sizeof (_T1));
-  return NULL;
+  Storage_DEALLOCATE ((void **) &i, sizeof (_T2));
+  return static_cast<Indexing_Index> (NULL);
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -197,7 +197,7 @@ Indexing_Index Indexing_KillIndex (Indexing_Index i)
    DebugIndex - turns on debugging within an index.
 */
 
-Indexing_Index Indexing_DebugIndex (Indexing_Index i)
+extern "C" Indexing_Index Indexing_DebugIndex (Indexing_Index i)
 {
   i->Debug = TRUE;
   return i;
@@ -211,7 +211,7 @@ Indexing_Index Indexing_DebugIndex (Indexing_Index i)
               of the dynamic array.
 */
 
-unsigned int Indexing_InBounds (Indexing_Index i, unsigned int n)
+extern "C" unsigned int Indexing_InBounds (Indexing_Index i, unsigned int n)
 {
   if (i == NULL)
     {
@@ -231,7 +231,7 @@ unsigned int Indexing_InBounds (Indexing_Index i, unsigned int n)
    HighIndice - returns the last legally accessible indice of this array.
 */
 
-unsigned int Indexing_HighIndice (Indexing_Index i)
+extern "C" unsigned int Indexing_HighIndice (Indexing_Index i)
 {
   if (i == NULL)
     {
@@ -251,7 +251,7 @@ unsigned int Indexing_HighIndice (Indexing_Index i)
    LowIndice - returns the first legally accessible indice of this array.
 */
 
-unsigned int Indexing_LowIndice (Indexing_Index i)
+extern "C" unsigned int Indexing_LowIndice (Indexing_Index i)
 {
   if (i == NULL)
     {
@@ -271,11 +271,13 @@ unsigned int Indexing_LowIndice (Indexing_Index i)
    PutIndice - places, a, into the dynamic array at position i[n]
 */
 
-void Indexing_PutIndice (Indexing_Index i, unsigned int n, void * a)
+extern "C" void Indexing_PutIndice (Indexing_Index i, unsigned int n, void * a)
 {
+  typedef unsigned int * *_T1;
+
   unsigned int oldSize;
   void * b;
-  unsigned int * * p;
+  _T1 p;
 
   if (! (Indexing_InBounds (i, n)))
     {
@@ -290,7 +292,7 @@ void Indexing_PutIndice (Indexing_Index i, unsigned int n, void * a)
           oldSize = i->ArraySize;
           while (((n-i->Low)*sizeof (void *)) >= i->ArraySize)
             {
-              i->ArraySize = i->ArraySize*2;
+              i->ArraySize = static_cast<unsigned int> (i->ArraySize*2);
             }
           if (oldSize != i->ArraySize)
             {
@@ -305,16 +307,16 @@ void Indexing_PutIndice (Indexing_Index i, unsigned int n, void * a)
               Storage_REALLOCATE (&i->ArrayStart, i->ArraySize);
               /* and initialize the remainder of the array to NIL  */
               b = i->ArrayStart;
-              b += oldSize;
-              b = libc_memset (b, 0, (size_t) i->ArraySize-oldSize);
+              b = reinterpret_cast<void *> (reinterpret_cast<char *> (b)+oldSize);
+              b = reinterpret_cast<void *> (libc_memset (b, 0, static_cast<size_t> (i->ArraySize-oldSize)));
             }
           i->High = n;
         }
     }
   b = i->ArrayStart;
-  b += (n-i->Low)*sizeof (void *);
-  p = b;
-  (*p) = a;
+  b = reinterpret_cast<void *> (reinterpret_cast<char *> (b)+(n-i->Low)*sizeof (void *));
+  p = static_cast<_T1> (b);
+  (*p) = reinterpret_cast<unsigned int *> (a);
   i->Used += 1;
   if (i->Debug)
     {
@@ -330,7 +332,7 @@ void Indexing_PutIndice (Indexing_Index i, unsigned int n, void * a)
    GetIndice - retrieves, element i[n] from the dynamic array.
 */
 
-void * Indexing_GetIndice (Indexing_Index i, unsigned int n)
+extern "C" void * Indexing_GetIndice (Indexing_Index i, unsigned int n)
 {
   PtrToByte b;
   PtrToAddress p;
@@ -340,7 +342,7 @@ void * Indexing_GetIndice (Indexing_Index i, unsigned int n)
       M2RTS_HALT (-1);
       __builtin_unreachable ();
     }
-  b = i->ArrayStart;
+  b = static_cast<PtrToByte> (i->ArrayStart);
   b += (n-i->Low)*sizeof (void *);
   p = (PtrToAddress) (b);
   if (i->Debug)
@@ -361,14 +363,14 @@ void * Indexing_GetIndice (Indexing_Index i, unsigned int n)
    IsIndiceInIndex - returns TRUE if, a, is in the index, i.
 */
 
-unsigned int Indexing_IsIndiceInIndex (Indexing_Index i, void * a)
+extern "C" unsigned int Indexing_IsIndiceInIndex (Indexing_Index i, void * a)
 {
   unsigned int j;
   PtrToByte b;
   PtrToAddress p;
 
   j = i->Low;
-  b = i->ArrayStart;
+  b = static_cast<PtrToByte> (i->ArrayStart);
   while (j <= i->High)
     {
       p = (PtrToAddress) (b);
@@ -390,7 +392,7 @@ unsigned int Indexing_IsIndiceInIndex (Indexing_Index i, void * a)
    RemoveIndiceFromIndex - removes, a, from Index, i.
 */
 
-void Indexing_RemoveIndiceFromIndex (Indexing_Index i, void * a)
+extern "C" void Indexing_RemoveIndiceFromIndex (Indexing_Index i, void * a)
 {
   unsigned int j;
   unsigned int k;
@@ -398,7 +400,7 @@ void Indexing_RemoveIndiceFromIndex (Indexing_Index i, void * a)
   PtrToByte b;
 
   j = i->Low;
-  b = i->ArrayStart;
+  b = static_cast<PtrToByte> (i->ArrayStart);
   while (j <= i->High)
     {
       p = (PtrToAddress) (b);
@@ -416,18 +418,18 @@ void Indexing_RemoveIndiceFromIndex (Indexing_Index i, void * a)
    DeleteIndice - delete i[j] from the array.
 */
 
-void Indexing_DeleteIndice (Indexing_Index i, unsigned int j)
+extern "C" void Indexing_DeleteIndice (Indexing_Index i, unsigned int j)
 {
   PtrToAddress p;
   PtrToByte b;
 
   if (Indexing_InBounds (i, j))
     {
-      b = i->ArrayStart;
+      b = static_cast<PtrToByte> (i->ArrayStart);
       b += sizeof (void *)*(j-i->Low);
       p = (PtrToAddress) (b);
       b += sizeof (void *);
-      p = libc_memmove ((void *) p, (void *) b, (size_t) (i->High-j)*sizeof (void *));
+      p = static_cast<PtrToAddress> (libc_memmove (reinterpret_cast<void *> (p), reinterpret_cast<void *> (b), static_cast<size_t> ((i->High-j)*sizeof (void *))));
       i->High -= 1;
       i->Used -= 1;
     }
@@ -444,7 +446,7 @@ void Indexing_DeleteIndice (Indexing_Index i, unsigned int j)
                             add it at the end.
 */
 
-void Indexing_IncludeIndiceIntoIndex (Indexing_Index i, void * a)
+extern "C" void Indexing_IncludeIndiceIntoIndex (Indexing_Index i, void * a)
 {
   if (! (Indexing_IsIndiceInIndex (i, a)))
     {
@@ -465,12 +467,12 @@ void Indexing_IncludeIndiceIntoIndex (Indexing_Index i, void * a)
    ForeachIndiceInIndexDo - for each j indice of i, call procedure p(i[j])
 */
 
-void Indexing_ForeachIndiceInIndexDo (Indexing_Index i, Indexing_IndexProcedure p)
+extern "C" void Indexing_ForeachIndiceInIndexDo (Indexing_Index i, Indexing_IndexProcedure p)
 {
   unsigned int j;
   Indexing_IndexProcedure q;
 
-  j = Indexing_LowIndice (i);
+  j = static_cast<unsigned int> (Indexing_LowIndice (i));
   q = p;
   while (j <= (Indexing_HighIndice (i)))
     {
@@ -480,10 +482,10 @@ void Indexing_ForeachIndiceInIndexDo (Indexing_Index i, Indexing_IndexProcedure
     }
 }
 
-void _M2_Indexing_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_Indexing_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_Indexing_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_Indexing_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GIndexing.h b/gcc/m2/mc-boot/GIndexing.h
index 9a7ae8ce54e..56145407d9e 100644
--- a/gcc/m2/mc-boot/GIndexing.h
+++ b/gcc/m2/mc-boot/GIndexing.h
@@ -1,7 +1,7 @@
 /* do not edit automatically generated by mc from Indexing.  */
 /* Indexing.def provides a dynamic indexing mechanism.
 
-Copyright (C) 2015-2021 Free Software Foundation, Inc.
+Copyright (C) 2015-2022 Free Software Foundation, Inc.
 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
 
 This file is part of GNU Modula-2.
@@ -24,11 +24,11 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 #if !defined (_Indexing_H)
 #   define _Indexing_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GM2EXCEPTION.c b/gcc/m2/mc-boot/GM2EXCEPTION.c
index 89ff8356e0a..0be2cbe21d7 100644
--- a/gcc/m2/mc-boot/GM2EXCEPTION.c
+++ b/gcc/m2/mc-boot/GM2EXCEPTION.c
@@ -42,10 +42,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 typedef enum {M2EXCEPTION_indexException, M2EXCEPTION_rangeException, M2EXCEPTION_caseSelectException, M2EXCEPTION_invalidLocation, M2EXCEPTION_functionException, M2EXCEPTION_wholeValueException, M2EXCEPTION_wholeDivException, M2EXCEPTION_realValueException, M2EXCEPTION_realDivException, M2EXCEPTION_complexValueException, M2EXCEPTION_complexDivException, M2EXCEPTION_protException, M2EXCEPTION_sysException, M2EXCEPTION_coException, M2EXCEPTION_exException} M2EXCEPTION_M2Exceptions;
 
-M2EXCEPTION_M2Exceptions M2EXCEPTION_M2Exception (void);
-unsigned int M2EXCEPTION_IsM2Exception (void);
+extern "C" M2EXCEPTION_M2Exceptions M2EXCEPTION_M2Exception (void);
+extern "C" unsigned int M2EXCEPTION_IsM2Exception (void);
 
-M2EXCEPTION_M2Exceptions M2EXCEPTION_M2Exception (void)
+extern "C" M2EXCEPTION_M2Exceptions M2EXCEPTION_M2Exception (void)
 {
   RTExceptions_EHBlock e;
   unsigned int n;
@@ -53,11 +53,11 @@ M2EXCEPTION_M2Exceptions M2EXCEPTION_M2Exception (void)
   /* If the program or coroutine is in the exception state then return the enumeration
    value representing the exception cause.  If it is not in the exception state then
    raises and exception (exException).  */
-  e = RTExceptions_GetExceptionBlock ();
-  n = RTExceptions_GetNumber (e);
+  e = static_cast<RTExceptions_EHBlock> (RTExceptions_GetExceptionBlock ());
+  n = static_cast<unsigned int> (RTExceptions_GetNumber (e));
   if (n == (UINT_MAX))
     {
-      RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_exException)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/M2EXCEPTION.mod", 47, 6, "M2Exception", "current coroutine is not in the exceptional execution state");
+      RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_exException)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/M2EXCEPTION.mod")), 47, 6, const_cast<void*> (reinterpret_cast<const void*>("M2Exception")), const_cast<void*> (reinterpret_cast<const void*>("current coroutine is not in the exceptional execution state")));
     }
   else
     {
@@ -67,23 +67,23 @@ M2EXCEPTION_M2Exceptions M2EXCEPTION_M2Exception (void)
   __builtin_unreachable ();
 }
 
-unsigned int M2EXCEPTION_IsM2Exception (void)
+extern "C" unsigned int M2EXCEPTION_IsM2Exception (void)
 {
   RTExceptions_EHBlock e;
 
   /* Returns TRUE if the program or coroutine is in the exception state.
    Returns FALSE if the program or coroutine is not in the exception state.  */
-  e = RTExceptions_GetExceptionBlock ();
+  e = static_cast<RTExceptions_EHBlock> (RTExceptions_GetExceptionBlock ());
   return (RTExceptions_GetNumber (e)) != (UINT_MAX);
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
 
-void _M2_M2EXCEPTION_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_M2EXCEPTION_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
   RTExceptions_SetExceptionBlock (RTExceptions_InitExceptionBlock ());
 }
 
-void _M2_M2EXCEPTION_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_M2EXCEPTION_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GM2EXCEPTION.h b/gcc/m2/mc-boot/GM2EXCEPTION.h
index b6a639183ac..7289c2b3761 100644
--- a/gcc/m2/mc-boot/GM2EXCEPTION.h
+++ b/gcc/m2/mc-boot/GM2EXCEPTION.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_M2EXCEPTION_H)
 #   define _M2EXCEPTION_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GM2RTS.c b/gcc/m2/mc-boot/GM2RTS.c
index 4a911e97802..e6b2ec077eb 100644
--- a/gcc/m2/mc-boot/GM2RTS.c
+++ b/gcc/m2/mc-boot/GM2RTS.c
@@ -69,7 +69,7 @@ static unsigned int CallExit;
                                   in reverse order.
 */
 
-void M2RTS_ExecuteTerminationProcedures (void);
+extern "C" void M2RTS_ExecuteTerminationProcedures (void);
 
 /*
    InstallTerminationProcedure - installs a procedure, p, which will
@@ -79,21 +79,21 @@ void M2RTS_ExecuteTerminationProcedures (void);
                                  procedure is installed.
 */
 
-unsigned int M2RTS_InstallTerminationProcedure (PROC p);
+extern "C" unsigned int M2RTS_InstallTerminationProcedure (PROC p);
 
 /*
    ExecuteInitialProcedures - executes the initial procedures installed by
                               InstallInitialProcedure.
 */
 
-void M2RTS_ExecuteInitialProcedures (void);
+extern "C" void M2RTS_ExecuteInitialProcedures (void);
 
 /*
    InstallInitialProcedure - installs a procedure to be executed just before the
                              BEGIN code section of the main program module.
 */
 
-unsigned int M2RTS_InstallInitialProcedure (PROC p);
+extern "C" unsigned int M2RTS_InstallInitialProcedure (PROC p);
 
 /*
    Terminate - provides compatibility for pim.  It call exit with
@@ -102,7 +102,7 @@ unsigned int M2RTS_InstallInitialProcedure (PROC p);
                not call ExecuteTerminationProcedures.
 */
 
-void M2RTS_Terminate (void) __attribute__ ((noreturn));
+extern "C" void M2RTS_Terminate (void) __attribute__ ((noreturn));
 
 /*
    HALT - terminate the current program.  The procedure
@@ -115,26 +115,26 @@ void M2RTS_Terminate (void) __attribute__ ((noreturn));
           then calling HALT with no parameter.
 */
 
-void M2RTS_HALT (int exitcode) __attribute__ ((noreturn));
+extern "C" void M2RTS_HALT (int exitcode) __attribute__ ((noreturn));
 
 /*
    Halt - provides a more user friendly version of HALT, which takes
           four parameters to aid debugging.
 */
 
-void M2RTS_Halt (char *file_, unsigned int _file_high, unsigned int line, char *function_, unsigned int _function_high, char *description_, unsigned int _description_high) __attribute__ ((noreturn));
+extern "C" void M2RTS_Halt (const char *file_, unsigned int _file_high, unsigned int line, const char *function_, unsigned int _function_high, const char *description_, unsigned int _description_high) __attribute__ ((noreturn));
 
 /*
    ExitOnHalt - if HALT is executed then call exit with the exit code, e.
 */
 
-void M2RTS_ExitOnHalt (int e);
+extern "C" void M2RTS_ExitOnHalt (int e);
 
 /*
    ErrorMessage - emits an error message to stderr and then calls exit (1).
 */
 
-void M2RTS_ErrorMessage (char *message_, unsigned int _message_high, char *file_, unsigned int _file_high, unsigned int line, char *function_, unsigned int _function_high) __attribute__ ((noreturn));
+extern "C" void M2RTS_ErrorMessage (const char *message_, unsigned int _message_high, const char *file_, unsigned int _file_high, unsigned int line, const char *function_, unsigned int _function_high) __attribute__ ((noreturn));
 
 /*
    Length - returns the length of a string, a. This is called whenever
@@ -142,44 +142,44 @@ void M2RTS_ErrorMessage (char *message_, unsigned int _message_high, char *file_
             at compile time.
 */
 
-unsigned int M2RTS_Length (char *a_, unsigned int _a_high);
-void M2RTS_AssignmentException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_ReturnException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_IncException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_DecException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_InclException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_ExclException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_ShiftException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_RotateException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_StaticArraySubscriptException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_DynamicArraySubscriptException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_ForLoopBeginException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_ForLoopToException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_ForLoopEndException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_PointerNilException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_NoReturnException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_CaseException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_WholeNonPosDivException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_WholeNonPosModException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_WholeZeroDivException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_WholeZeroRemException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_WholeValueException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_RealValueException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_ParameterException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
-void M2RTS_NoException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" unsigned int M2RTS_Length (const char *a_, unsigned int _a_high);
+extern "C" void M2RTS_AssignmentException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_ReturnException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_IncException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_DecException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_InclException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_ExclException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_ShiftException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_RotateException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_StaticArraySubscriptException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_DynamicArraySubscriptException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_ForLoopBeginException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_ForLoopToException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_ForLoopEndException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_PointerNilException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_NoReturnException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_CaseException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_WholeNonPosDivException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_WholeNonPosModException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_WholeZeroDivException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_WholeZeroRemException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_WholeValueException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_RealValueException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_ParameterException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
+extern "C" void M2RTS_NoException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
 
 /*
    ErrorString - writes a string to stderr.
 */
 
-static void ErrorString (char *a_, unsigned int _a_high);
+static void ErrorString (const char *a_, unsigned int _a_high);
 
 
 /*
    ErrorString - writes a string to stderr.
 */
 
-static void ErrorString (char *a_, unsigned int _a_high)
+static void ErrorString (const char *a_, unsigned int _a_high)
 {
   int n;
   char a[_a_high+1];
@@ -187,7 +187,7 @@ static void ErrorString (char *a_, unsigned int _a_high)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  n = libc_write (2, &a, (size_t) StrLib_StrLen ((char *) a, _a_high));
+  n = static_cast<int> (libc_write (2, &a, static_cast<size_t> (StrLib_StrLen ((const char *) a, _a_high))));
 }
 
 
@@ -196,7 +196,7 @@ static void ErrorString (char *a_, unsigned int _a_high)
                                   in reverse order.
 */
 
-void M2RTS_ExecuteTerminationProcedures (void)
+extern "C" void M2RTS_ExecuteTerminationProcedures (void)
 {
   unsigned int i;
 
@@ -217,7 +217,7 @@ void M2RTS_ExecuteTerminationProcedures (void)
                                  procedure is installed.
 */
 
-unsigned int M2RTS_InstallTerminationProcedure (PROC p)
+extern "C" unsigned int M2RTS_InstallTerminationProcedure (PROC p)
 {
   if (tPtr > MaxProcedures)
     {
@@ -239,7 +239,7 @@ unsigned int M2RTS_InstallTerminationProcedure (PROC p)
                               InstallInitialProcedure.
 */
 
-void M2RTS_ExecuteInitialProcedures (void)
+extern "C" void M2RTS_ExecuteInitialProcedures (void)
 {
   unsigned int i;
 
@@ -257,7 +257,7 @@ void M2RTS_ExecuteInitialProcedures (void)
                              BEGIN code section of the main program module.
 */
 
-unsigned int M2RTS_InstallInitialProcedure (PROC p)
+extern "C" unsigned int M2RTS_InstallInitialProcedure (PROC p)
 {
   if (iPtr > MaxProcedures)
     {
@@ -281,7 +281,7 @@ unsigned int M2RTS_InstallInitialProcedure (PROC p)
                not call ExecuteTerminationProcedures.
 */
 
-void M2RTS_Terminate (void)
+extern "C" void M2RTS_Terminate (void)
 {
   libc_exit (ExitValue);
 }
@@ -298,7 +298,7 @@ void M2RTS_Terminate (void)
           then calling HALT with no parameter.
 */
 
-void M2RTS_HALT (int exitcode)
+extern "C" void M2RTS_HALT (int exitcode)
 {
   if (exitcode != -1)
     {
@@ -331,7 +331,7 @@ void M2RTS_HALT (int exitcode)
           four parameters to aid debugging.
 */
 
-void M2RTS_Halt (char *file_, unsigned int _file_high, unsigned int line, char *function_, unsigned int _function_high, char *description_, unsigned int _description_high)
+extern "C" void M2RTS_Halt (const char *file_, unsigned int _file_high, unsigned int line, const char *function_, unsigned int _function_high, const char *description_, unsigned int _description_high)
 {
   char file[_file_high+1];
   char function[_function_high+1];
@@ -342,7 +342,7 @@ void M2RTS_Halt (char *file_, unsigned int _file_high, unsigned int line, char *
   memcpy (function, function_, _function_high+1);
   memcpy (description, description_, _description_high+1);
 
-  M2RTS_ErrorMessage ((char *) description, _description_high, (char *) file, _file_high, line, (char *) function, _function_high);
+  M2RTS_ErrorMessage ((const char *) description, _description_high, (const char *) file, _file_high, line, (const char *) function, _function_high);
   M2RTS_HALT (-1);
   __builtin_unreachable ();
 }
@@ -352,7 +352,7 @@ void M2RTS_Halt (char *file_, unsigned int _file_high, unsigned int line, char *
    ExitOnHalt - if HALT is executed then call exit with the exit code, e.
 */
 
-void M2RTS_ExitOnHalt (int e)
+extern "C" void M2RTS_ExitOnHalt (int e)
 {
   ExitValue = e;
   CallExit = TRUE;
@@ -363,7 +363,7 @@ void M2RTS_ExitOnHalt (int e)
    ErrorMessage - emits an error message to stderr and then calls exit (1).
 */
 
-void M2RTS_ErrorMessage (char *message_, unsigned int _message_high, char *file_, unsigned int _file_high, unsigned int line, char *function_, unsigned int _function_high)
+extern "C" void M2RTS_ErrorMessage (const char *message_, unsigned int _message_high, const char *file_, unsigned int _file_high, unsigned int line, const char *function_, unsigned int _function_high)
 {
   typedef struct _T2_a _T2;
 
@@ -378,21 +378,21 @@ void M2RTS_ErrorMessage (char *message_, unsigned int _message_high, char *file_
   memcpy (file, file_, _file_high+1);
   memcpy (function, function_, _function_high+1);
 
-  ErrorString ((char *) file, _file_high);
-  ErrorString ((char *) ":", 1);
+  ErrorString ((const char *) file, _file_high);
+  ErrorString ((const char *) ":", 1);
   NumberIO_CardToStr (line, 0, (char *) &LineNo.array[0], 10);
-  ErrorString ((char *) &LineNo.array[0], 10);
-  ErrorString ((char *) ":", 1);
-  if (! (StrLib_StrEqual ((char *) function, _function_high, (char *) "", 0)))
+  ErrorString ((const char *) &LineNo.array[0], 10);
+  ErrorString ((const char *) ":", 1);
+  if (! (StrLib_StrEqual ((const char *) function, _function_high, (const char *) "", 0)))
     {
-      ErrorString ((char *) "in ", 3);
-      ErrorString ((char *) function, _function_high);
-      ErrorString ((char *) " has caused ", 12);
+      ErrorString ((const char *) "in ", 3);
+      ErrorString ((const char *) function, _function_high);
+      ErrorString ((const char *) " has caused ", 12);
     }
-  ErrorString ((char *) message, _message_high);
-  LineNo.array[0] = ASCII_nl;
-  LineNo.array[1] = ASCII_nul;
-  ErrorString ((char *) &LineNo.array[0], 10);
+  ErrorString ((const char *) message, _message_high);
+  LineNo.array[0] = static_cast<char> (ASCII_nl);
+  LineNo.array[1] = static_cast<char> (ASCII_nul);
+  ErrorString ((const char *) &LineNo.array[0], 10);
   libc_exit (1);
 }
 
@@ -403,7 +403,7 @@ void M2RTS_ErrorMessage (char *message_, unsigned int _message_high, char *file_
             at compile time.
 */
 
-unsigned int M2RTS_Length (char *a_, unsigned int _a_high)
+extern "C" unsigned int M2RTS_Length (const char *a_, unsigned int _a_high)
 {
   unsigned int l;
   unsigned int h;
@@ -412,7 +412,7 @@ unsigned int M2RTS_Length (char *a_, unsigned int _a_high)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  l = 0;
+  l = static_cast<unsigned int> (0);
   h = _a_high;
   while ((l <= h) && (a[l] != ASCII_nul))
     {
@@ -423,7 +423,7 @@ unsigned int M2RTS_Length (char *a_, unsigned int _a_high)
   __builtin_unreachable ();
 }
 
-void M2RTS_AssignmentException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_AssignmentException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   /* 
    The following are the runtime exception handler routines.
@@ -431,130 +431,130 @@ void M2RTS_AssignmentException (void * filename, unsigned int line, unsigned int
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message);
 }
 
-void M2RTS_ReturnException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_ReturnException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message);
 }
 
-void M2RTS_IncException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_IncException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message);
 }
 
-void M2RTS_DecException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_DecException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message);
 }
 
-void M2RTS_InclException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_InclException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message);
 }
 
-void M2RTS_ExclException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_ExclException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message);
 }
 
-void M2RTS_ShiftException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_ShiftException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message);
 }
 
-void M2RTS_RotateException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_RotateException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message);
 }
 
-void M2RTS_StaticArraySubscriptException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_StaticArraySubscriptException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_indexException)), filename, line, column, scope, message);
 }
 
-void M2RTS_DynamicArraySubscriptException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_DynamicArraySubscriptException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_indexException)), filename, line, column, scope, message);
 }
 
-void M2RTS_ForLoopBeginException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_ForLoopBeginException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message);
 }
 
-void M2RTS_ForLoopToException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_ForLoopToException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message);
 }
 
-void M2RTS_ForLoopEndException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_ForLoopEndException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message);
 }
 
-void M2RTS_PointerNilException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_PointerNilException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_invalidLocation)), filename, line, column, scope, message);
 }
 
-void M2RTS_NoReturnException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_NoReturnException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_functionException)), filename, line, column, scope, message);
 }
 
-void M2RTS_CaseException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_CaseException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_caseSelectException)), filename, line, column, scope, message);
 }
 
-void M2RTS_WholeNonPosDivException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_WholeNonPosDivException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeDivException)), filename, line, column, scope, message);
 }
 
-void M2RTS_WholeNonPosModException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_WholeNonPosModException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeDivException)), filename, line, column, scope, message);
 }
 
-void M2RTS_WholeZeroDivException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_WholeZeroDivException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeDivException)), filename, line, column, scope, message);
 }
 
-void M2RTS_WholeZeroRemException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_WholeZeroRemException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeDivException)), filename, line, column, scope, message);
 }
 
-void M2RTS_WholeValueException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_WholeValueException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeValueException)), filename, line, column, scope, message);
 }
 
-void M2RTS_RealValueException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_RealValueException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_realValueException)), filename, line, column, scope, message);
 }
 
-void M2RTS_ParameterException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_ParameterException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message);
 }
 
-void M2RTS_NoException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
+extern "C" void M2RTS_NoException (void * filename, unsigned int line, unsigned int column, void * scope, void * message)
 {
   RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_exException)), filename, line, column, scope, message);
 }
 
-void _M2_M2RTS_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_M2RTS_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
-  iPtr = 0;
-  tPtr = 0;
-  ExitValue = 0;
+  iPtr = static_cast<unsigned int> (0);
+  tPtr = static_cast<unsigned int> (0);
+  ExitValue = static_cast<int> (0);
   isHalting = FALSE;
   CallExit = FALSE;  /* default by calling abort  */
 }
 
-void _M2_M2RTS_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_M2RTS_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GM2RTS.h b/gcc/m2/mc-boot/GM2RTS.h
index 74792ab9d2c..53428b8fdec 100644
--- a/gcc/m2/mc-boot/GM2RTS.h
+++ b/gcc/m2/mc-boot/GM2RTS.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_M2RTS_H)
 #   define _M2RTS_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
@@ -107,7 +107,7 @@ EXTERN void M2RTS_HALT (int exitcode) __attribute__ ((noreturn));
           four parameters to aid debugging.
 */
 
-EXTERN void M2RTS_Halt (char *file_, unsigned int _file_high, unsigned int line, char *function_, unsigned int _function_high, char *description_, unsigned int _description_high) __attribute__ ((noreturn));
+EXTERN void M2RTS_Halt (const char *file_, unsigned int _file_high, unsigned int line, const char *function_, unsigned int _function_high, const char *description_, unsigned int _description_high) __attribute__ ((noreturn));
 
 /*
    ExitOnHalt - if HALT is executed then call exit with the exit code, e.
@@ -119,7 +119,7 @@ EXTERN void M2RTS_ExitOnHalt (int e);
    ErrorMessage - emits an error message to stderr and then calls exit (1).
 */
 
-EXTERN void M2RTS_ErrorMessage (char *message_, unsigned int _message_high, char *file_, unsigned int _file_high, unsigned int line, char *function_, unsigned int _function_high) __attribute__ ((noreturn));
+EXTERN void M2RTS_ErrorMessage (const char *message_, unsigned int _message_high, const char *file_, unsigned int _file_high, unsigned int line, const char *function_, unsigned int _function_high) __attribute__ ((noreturn));
 
 /*
    Length - returns the length of a string, a. This is called whenever
@@ -127,7 +127,7 @@ EXTERN void M2RTS_ErrorMessage (char *message_, unsigned int _message_high, char
             at compile time.
 */
 
-EXTERN unsigned int M2RTS_Length (char *a_, unsigned int _a_high);
+EXTERN unsigned int M2RTS_Length (const char *a_, unsigned int _a_high);
 EXTERN void M2RTS_AssignmentException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
 EXTERN void M2RTS_ReturnException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
 EXTERN void M2RTS_IncException (void * filename, unsigned int line, unsigned int column, void * scope, void * message);
diff --git a/gcc/m2/mc-boot/GMemUtils.c b/gcc/m2/mc-boot/GMemUtils.c
index dd711f47a32..798899786ca 100644
--- a/gcc/m2/mc-boot/GMemUtils.c
+++ b/gcc/m2/mc-boot/GMemUtils.c
@@ -43,42 +43,46 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    MemCopy - copys a region of memory to the required destination.
 */
 
-void MemUtils_MemCopy (void * from, unsigned int length, void * to);
+extern "C" void MemUtils_MemCopy (void * from, unsigned int length, void * to);
 
 /*
    MemZero - sets a region of memory: a..a+length to zero.
 */
 
-void MemUtils_MemZero (void * a, unsigned int length);
+extern "C" void MemUtils_MemZero (void * a, unsigned int length);
 
 
 /*
    MemCopy - copys a region of memory to the required destination.
 */
 
-void MemUtils_MemCopy (void * from, unsigned int length, void * to)
+extern "C" void MemUtils_MemCopy (void * from, unsigned int length, void * to)
 {
-  unsigned int * pwb;
-  unsigned int * pwa;
-  unsigned char * pbb;
-  unsigned char * pba;
+  typedef unsigned int *_T1;
+
+  typedef unsigned char *_T2;
+
+  _T1 pwb;
+  _T1 pwa;
+  _T2 pbb;
+  _T2 pba;
 
   while (length >= sizeof (unsigned int ))
     {
-      pwa = from;
-      pwb = to;
+      pwa = static_cast<_T1> (from);
+      pwb = static_cast<_T1> (to);
       (*pwb) = (*pwa);
-      from += sizeof (unsigned int );
-      to += sizeof (unsigned int );
+      from = reinterpret_cast<void *> (reinterpret_cast<char *> (from)+sizeof (unsigned int ));
+      to = reinterpret_cast<void *> (reinterpret_cast<char *> (to)+sizeof (unsigned int ));
       length -= sizeof (unsigned int );
     }
   while (length > 0)
     {
-      pba = from;
-      pbb = to;
+      pba = static_cast<_T2> (from);
+      pbb = static_cast<_T2> (to);
       (*pbb) = (*pba);
-      from += sizeof (unsigned char );
-      to += sizeof (unsigned char );
+      from = reinterpret_cast<void *> (reinterpret_cast<char *> (from)+sizeof (unsigned char ));
+      to = reinterpret_cast<void *> (reinterpret_cast<char *> (to)+sizeof (unsigned char ));
       length -= sizeof (unsigned char );
     }
 }
@@ -88,19 +92,23 @@ void MemUtils_MemCopy (void * from, unsigned int length, void * to)
    MemZero - sets a region of memory: a..a+length to zero.
 */
 
-void MemUtils_MemZero (void * a, unsigned int length)
+extern "C" void MemUtils_MemZero (void * a, unsigned int length)
 {
-  unsigned int * pwa;
-  unsigned char * pba;
+  typedef unsigned int *_T3;
+
+  typedef unsigned char *_T4;
+
+  _T3 pwa;
+  _T4 pba;
 
-  pwa = a;
+  pwa = static_cast<_T3> (a);
   while (length >= sizeof (unsigned int ))
     {
       (*pwa) = (unsigned int ) (0);
       pwa += sizeof (unsigned int );
       length -= sizeof (unsigned int );
     }
-  pba = (void *) (pwa);
+  pba = static_cast<_T4> ((void *) (pwa));
   while (length >= sizeof (unsigned char ))
     {
       (*pba) = (unsigned char ) (0);
@@ -109,10 +117,10 @@ void MemUtils_MemZero (void * a, unsigned int length)
     }
 }
 
-void _M2_MemUtils_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_MemUtils_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_MemUtils_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_MemUtils_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GMemUtils.h b/gcc/m2/mc-boot/GMemUtils.h
index ee4d823af67..3258234d6a5 100644
--- a/gcc/m2/mc-boot/GMemUtils.h
+++ b/gcc/m2/mc-boot/GMemUtils.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_MemUtils_H)
 #   define _MemUtils_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GNumberIO.c b/gcc/m2/mc-boot/GNumberIO.c
index 030d7b60f93..8da60acf8eb 100644
--- a/gcc/m2/mc-boot/GNumberIO.c
+++ b/gcc/m2/mc-boot/GNumberIO.c
@@ -54,31 +54,31 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #   define MaxHexDigits 20
 #   define MaxOctDigits 40
 #   define MaxBits 64
-void NumberIO_ReadCard (unsigned int *x);
-void NumberIO_WriteCard (unsigned int x, unsigned int n);
-void NumberIO_ReadHex (unsigned int *x);
-void NumberIO_WriteHex (unsigned int x, unsigned int n);
-void NumberIO_ReadInt (int *x);
-void NumberIO_WriteInt (int x, unsigned int n);
-void NumberIO_CardToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high);
-void NumberIO_StrToCard (char *a_, unsigned int _a_high, unsigned int *x);
-void NumberIO_HexToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high);
-void NumberIO_StrToHex (char *a_, unsigned int _a_high, unsigned int *x);
-void NumberIO_IntToStr (int x, unsigned int n, char *a, unsigned int _a_high);
-void NumberIO_StrToInt (char *a_, unsigned int _a_high, int *x);
-void NumberIO_ReadOct (unsigned int *x);
-void NumberIO_WriteOct (unsigned int x, unsigned int n);
-void NumberIO_OctToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high);
-void NumberIO_StrToOct (char *a_, unsigned int _a_high, unsigned int *x);
-void NumberIO_ReadBin (unsigned int *x);
-void NumberIO_WriteBin (unsigned int x, unsigned int n);
-void NumberIO_BinToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high);
-void NumberIO_StrToBin (char *a_, unsigned int _a_high, unsigned int *x);
-void NumberIO_StrToBinInt (char *a_, unsigned int _a_high, int *x);
-void NumberIO_StrToHexInt (char *a_, unsigned int _a_high, int *x);
-void NumberIO_StrToOctInt (char *a_, unsigned int _a_high, int *x);
-
-void NumberIO_ReadCard (unsigned int *x)
+extern "C" void NumberIO_ReadCard (unsigned int *x);
+extern "C" void NumberIO_WriteCard (unsigned int x, unsigned int n);
+extern "C" void NumberIO_ReadHex (unsigned int *x);
+extern "C" void NumberIO_WriteHex (unsigned int x, unsigned int n);
+extern "C" void NumberIO_ReadInt (int *x);
+extern "C" void NumberIO_WriteInt (int x, unsigned int n);
+extern "C" void NumberIO_CardToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high);
+extern "C" void NumberIO_StrToCard (const char *a_, unsigned int _a_high, unsigned int *x);
+extern "C" void NumberIO_HexToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high);
+extern "C" void NumberIO_StrToHex (const char *a_, unsigned int _a_high, unsigned int *x);
+extern "C" void NumberIO_IntToStr (int x, unsigned int n, char *a, unsigned int _a_high);
+extern "C" void NumberIO_StrToInt (const char *a_, unsigned int _a_high, int *x);
+extern "C" void NumberIO_ReadOct (unsigned int *x);
+extern "C" void NumberIO_WriteOct (unsigned int x, unsigned int n);
+extern "C" void NumberIO_OctToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high);
+extern "C" void NumberIO_StrToOct (const char *a_, unsigned int _a_high, unsigned int *x);
+extern "C" void NumberIO_ReadBin (unsigned int *x);
+extern "C" void NumberIO_WriteBin (unsigned int x, unsigned int n);
+extern "C" void NumberIO_BinToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high);
+extern "C" void NumberIO_StrToBin (const char *a_, unsigned int _a_high, unsigned int *x);
+extern "C" void NumberIO_StrToBinInt (const char *a_, unsigned int _a_high, int *x);
+extern "C" void NumberIO_StrToHexInt (const char *a_, unsigned int _a_high, int *x);
+extern "C" void NumberIO_StrToOctInt (const char *a_, unsigned int _a_high, int *x);
+
+extern "C" void NumberIO_ReadCard (unsigned int *x)
 {
   typedef struct _T1_a _T1;
 
@@ -86,10 +86,10 @@ void NumberIO_ReadCard (unsigned int *x)
   _T1 a;
 
   StrIO_ReadString ((char *) &a.array[0], MaxLineLength);
-  NumberIO_StrToCard ((char *) &a.array[0], MaxLineLength, x);
+  NumberIO_StrToCard ((const char *) &a.array[0], MaxLineLength, x);
 }
 
-void NumberIO_WriteCard (unsigned int x, unsigned int n)
+extern "C" void NumberIO_WriteCard (unsigned int x, unsigned int n)
 {
   typedef struct _T2_a _T2;
 
@@ -97,10 +97,10 @@ void NumberIO_WriteCard (unsigned int x, unsigned int n)
   _T2 a;
 
   NumberIO_CardToStr (x, n, (char *) &a.array[0], MaxLineLength);
-  StrIO_WriteString ((char *) &a.array[0], MaxLineLength);
+  StrIO_WriteString ((const char *) &a.array[0], MaxLineLength);
 }
 
-void NumberIO_ReadHex (unsigned int *x)
+extern "C" void NumberIO_ReadHex (unsigned int *x)
 {
   typedef struct _T3_a _T3;
 
@@ -108,10 +108,10 @@ void NumberIO_ReadHex (unsigned int *x)
   _T3 a;
 
   StrIO_ReadString ((char *) &a.array[0], MaxLineLength);
-  NumberIO_StrToHex ((char *) &a.array[0], MaxLineLength, x);
+  NumberIO_StrToHex ((const char *) &a.array[0], MaxLineLength, x);
 }
 
-void NumberIO_WriteHex (unsigned int x, unsigned int n)
+extern "C" void NumberIO_WriteHex (unsigned int x, unsigned int n)
 {
   typedef struct _T4_a _T4;
 
@@ -119,10 +119,10 @@ void NumberIO_WriteHex (unsigned int x, unsigned int n)
   _T4 a;
 
   NumberIO_HexToStr (x, n, (char *) &a.array[0], MaxLineLength);
-  StrIO_WriteString ((char *) &a.array[0], MaxLineLength);
+  StrIO_WriteString ((const char *) &a.array[0], MaxLineLength);
 }
 
-void NumberIO_ReadInt (int *x)
+extern "C" void NumberIO_ReadInt (int *x)
 {
   typedef struct _T5_a _T5;
 
@@ -130,10 +130,10 @@ void NumberIO_ReadInt (int *x)
   _T5 a;
 
   StrIO_ReadString ((char *) &a.array[0], MaxLineLength);
-  NumberIO_StrToInt ((char *) &a.array[0], MaxLineLength, x);
+  NumberIO_StrToInt ((const char *) &a.array[0], MaxLineLength, x);
 }
 
-void NumberIO_WriteInt (int x, unsigned int n)
+extern "C" void NumberIO_WriteInt (int x, unsigned int n)
 {
   typedef struct _T6_a _T6;
 
@@ -141,10 +141,10 @@ void NumberIO_WriteInt (int x, unsigned int n)
   _T6 a;
 
   NumberIO_IntToStr (x, n, (char *) &a.array[0], MaxLineLength);
-  StrIO_WriteString ((char *) &a.array[0], MaxLineLength);
+  StrIO_WriteString ((const char *) &a.array[0], MaxLineLength);
 }
 
-void NumberIO_CardToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high)
+extern "C" void NumberIO_CardToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high)
 {
   typedef struct _T7_a _T7;
 
@@ -154,20 +154,20 @@ void NumberIO_CardToStr (unsigned int x, unsigned int n, char *a, unsigned int _
   unsigned int Higha;
   _T7 buf;
 
-  i = 0;
+  i = static_cast<unsigned int> (0);
   do {
     i += 1;
     if (i > MaxDigits)
       {
-        StrIO_WriteString ((char *) "NumberIO - increase MaxDigits", 29);
+        StrIO_WriteString ((const char *) "NumberIO - increase MaxDigits", 29);
         StrIO_WriteLn ();
         M2RTS_HALT (-1);
         __builtin_unreachable ();
       }
-    buf.array[i-1] = x % 10;
-    x = x / 10;
+    buf.array[i-1] = static_cast<unsigned int> (x % 10);
+    x = static_cast<unsigned int> (x / 10);
   } while (! (x == 0));
-  j = 0;
+  j = static_cast<unsigned int> (0);
   Higha = _a_high;
   while ((n > i) && (j <= Higha))
     {
@@ -183,11 +183,11 @@ void NumberIO_CardToStr (unsigned int x, unsigned int n, char *a, unsigned int _
     }
   if (j <= Higha)
     {
-      a[j] = ASCII_nul;
+      a[j] = static_cast<char> (ASCII_nul);
     }
 }
 
-void NumberIO_StrToCard (char *a_, unsigned int _a_high, unsigned int *x)
+extern "C" void NumberIO_StrToCard (const char *a_, unsigned int _a_high, unsigned int *x)
 {
   unsigned int i;
   unsigned int ok;
@@ -197,9 +197,9 @@ void NumberIO_StrToCard (char *a_, unsigned int _a_high, unsigned int *x)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  StrLib_StrRemoveWhitePrefix ((char *) a, _a_high, (char *) a, _a_high);
-  higha = StrLib_StrLen ((char *) a, _a_high);
-  i = 0;
+  StrLib_StrRemoveWhitePrefix ((const char *) a, _a_high, (char *) a, _a_high);
+  higha = static_cast<unsigned int> (StrLib_StrLen ((const char *) a, _a_high));
+  i = static_cast<unsigned int> (0);
   ok = TRUE;
   while (ok)
     {
@@ -219,12 +219,12 @@ void NumberIO_StrToCard (char *a_, unsigned int _a_high, unsigned int *x)
           ok = FALSE;
         }
     }
-  (*x) = 0;
+  (*x) = static_cast<unsigned int> (0);
   if (i < higha)
     {
       ok = TRUE;
       do {
-        (*x) = (10*(*x))+( ((unsigned int) (a[i]))- ((unsigned int) ('0')));
+        (*x) = static_cast<unsigned int> ((10*(*x))+( ((unsigned int) (a[i]))- ((unsigned int) ('0'))));
         if (i < higha)
           {
             /* avoid dangling else.  */
@@ -242,7 +242,7 @@ void NumberIO_StrToCard (char *a_, unsigned int _a_high, unsigned int *x)
     }
 }
 
-void NumberIO_HexToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high)
+extern "C" void NumberIO_HexToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high)
 {
   typedef struct _T8_a _T8;
 
@@ -252,20 +252,20 @@ void NumberIO_HexToStr (unsigned int x, unsigned int n, char *a, unsigned int _a
   unsigned int Higha;
   _T8 buf;
 
-  i = 0;
+  i = static_cast<unsigned int> (0);
   do {
     i += 1;
     if (i > MaxHexDigits)
       {
-        StrIO_WriteString ((char *) "NumberIO - increase MaxDigits", 29);
+        StrIO_WriteString ((const char *) "NumberIO - increase MaxDigits", 29);
         StrIO_WriteLn ();
         M2RTS_HALT (-1);
         __builtin_unreachable ();
       }
-    buf.array[i-1] = x % 0x010;
-    x = x / 0x010;
+    buf.array[i-1] = static_cast<unsigned int> (x % 0x010);
+    x = static_cast<unsigned int> (x / 0x010);
   } while (! (x == 0));
-  j = 0;
+  j = static_cast<unsigned int> (0);
   Higha = _a_high;
   while ((n > i) && (j <= Higha))
     {
@@ -292,7 +292,7 @@ void NumberIO_HexToStr (unsigned int x, unsigned int n, char *a, unsigned int _a
     }
 }
 
-void NumberIO_StrToHex (char *a_, unsigned int _a_high, unsigned int *x)
+extern "C" void NumberIO_StrToHex (const char *a_, unsigned int _a_high, unsigned int *x)
 {
   int i;
   char a[_a_high+1];
@@ -300,11 +300,11 @@ void NumberIO_StrToHex (char *a_, unsigned int _a_high, unsigned int *x)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  NumberIO_StrToHexInt ((char *) a, _a_high, &i);
+  NumberIO_StrToHexInt ((const char *) a, _a_high, &i);
   (*x) = (unsigned int ) (i);
 }
 
-void NumberIO_IntToStr (int x, unsigned int n, char *a, unsigned int _a_high)
+extern "C" void NumberIO_IntToStr (int x, unsigned int n, char *a, unsigned int _a_high)
 {
   typedef struct _T9_a _T9;
 
@@ -320,7 +320,7 @@ void NumberIO_IntToStr (int x, unsigned int n, char *a, unsigned int _a_high)
     {
       /* avoid dangling else.  */
       Negative = TRUE;
-      c = ((unsigned int ) (abs (x+1)))+1;
+      c = static_cast<unsigned int> (((unsigned int ) (abs (x+1)))+1);
       if (n > 0)
         {
           n -= 1;
@@ -328,23 +328,23 @@ void NumberIO_IntToStr (int x, unsigned int n, char *a, unsigned int _a_high)
     }
   else
     {
-      c = x;
+      c = static_cast<unsigned int> (x);
       Negative = FALSE;
     }
-  i = 0;
+  i = static_cast<unsigned int> (0);
   do {
     i += 1;
     if (i > MaxDigits)
       {
-        StrIO_WriteString ((char *) "NumberIO - increase MaxDigits", 29);
+        StrIO_WriteString ((const char *) "NumberIO - increase MaxDigits", 29);
         StrIO_WriteLn ();
         M2RTS_HALT (-1);
         __builtin_unreachable ();
       }
-    buf.array[i-1] = c % 10;
-    c = c / 10;
+    buf.array[i-1] = static_cast<unsigned int> (c % 10);
+    c = static_cast<unsigned int> (c / 10);
   } while (! (c == 0));
-  j = 0;
+  j = static_cast<unsigned int> (0);
   Higha = _a_high;
   while ((n > i) && (j <= Higha))
     {
@@ -369,7 +369,7 @@ void NumberIO_IntToStr (int x, unsigned int n, char *a, unsigned int _a_high)
     }
 }
 
-void NumberIO_StrToInt (char *a_, unsigned int _a_high, int *x)
+extern "C" void NumberIO_StrToInt (const char *a_, unsigned int _a_high, int *x)
 {
   unsigned int i;
   unsigned int ok;
@@ -380,9 +380,9 @@ void NumberIO_StrToInt (char *a_, unsigned int _a_high, int *x)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  StrLib_StrRemoveWhitePrefix ((char *) a, _a_high, (char *) a, _a_high);
-  higha = StrLib_StrLen ((char *) a, _a_high);
-  i = 0;
+  StrLib_StrRemoveWhitePrefix ((const char *) a, _a_high, (char *) a, _a_high);
+  higha = static_cast<unsigned int> (StrLib_StrLen ((const char *) a, _a_high));
+  i = static_cast<unsigned int> (0);
   Negative = FALSE;
   ok = TRUE;
   while (ok)
@@ -410,18 +410,18 @@ void NumberIO_StrToInt (char *a_, unsigned int _a_high, int *x)
           ok = FALSE;
         }
     }
-  (*x) = 0;
+  (*x) = static_cast<int> (0);
   if (i < higha)
     {
       ok = TRUE;
       do {
         if (Negative)
           {
-            (*x) = (10*(*x))-((int ) ( ((unsigned int) (a[i]))- ((unsigned int) ('0'))));
+            (*x) = static_cast<int> ((10*(*x))-((int ) ( ((unsigned int) (a[i]))- ((unsigned int) ('0')))));
           }
         else
           {
-            (*x) = (10*(*x))+((int ) ( ((unsigned int) (a[i]))- ((unsigned int) ('0'))));
+            (*x) = static_cast<int> ((10*(*x))+((int ) ( ((unsigned int) (a[i]))- ((unsigned int) ('0')))));
           }
         if (i < higha)
           {
@@ -440,7 +440,7 @@ void NumberIO_StrToInt (char *a_, unsigned int _a_high, int *x)
     }
 }
 
-void NumberIO_ReadOct (unsigned int *x)
+extern "C" void NumberIO_ReadOct (unsigned int *x)
 {
   typedef struct _T10_a _T10;
 
@@ -448,10 +448,10 @@ void NumberIO_ReadOct (unsigned int *x)
   _T10 a;
 
   StrIO_ReadString ((char *) &a.array[0], MaxLineLength);
-  NumberIO_StrToOct ((char *) &a.array[0], MaxLineLength, x);
+  NumberIO_StrToOct ((const char *) &a.array[0], MaxLineLength, x);
 }
 
-void NumberIO_WriteOct (unsigned int x, unsigned int n)
+extern "C" void NumberIO_WriteOct (unsigned int x, unsigned int n)
 {
   typedef struct _T11_a _T11;
 
@@ -459,10 +459,10 @@ void NumberIO_WriteOct (unsigned int x, unsigned int n)
   _T11 a;
 
   NumberIO_OctToStr (x, n, (char *) &a.array[0], MaxLineLength);
-  StrIO_WriteString ((char *) &a.array[0], MaxLineLength);
+  StrIO_WriteString ((const char *) &a.array[0], MaxLineLength);
 }
 
-void NumberIO_OctToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high)
+extern "C" void NumberIO_OctToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high)
 {
   typedef struct _T12_a _T12;
 
@@ -472,20 +472,20 @@ void NumberIO_OctToStr (unsigned int x, unsigned int n, char *a, unsigned int _a
   unsigned int Higha;
   _T12 buf;
 
-  i = 0;
+  i = static_cast<unsigned int> (0);
   do {
     i += 1;
     if (i > MaxOctDigits)
       {
-        StrIO_WriteString ((char *) "NumberIO - increase MaxDigits", 29);
+        StrIO_WriteString ((const char *) "NumberIO - increase MaxDigits", 29);
         StrIO_WriteLn ();
         M2RTS_HALT (-1);
         __builtin_unreachable ();
       }
-    buf.array[i-1] = x % 8;
-    x = x / 8;
+    buf.array[i-1] = static_cast<unsigned int> (x % 8);
+    x = static_cast<unsigned int> (x / 8);
   } while (! (x == 0));
-  j = 0;
+  j = static_cast<unsigned int> (0);
   Higha = _a_high;
   while ((n > i) && (j <= Higha))
     {
@@ -505,7 +505,7 @@ void NumberIO_OctToStr (unsigned int x, unsigned int n, char *a, unsigned int _a
     }
 }
 
-void NumberIO_StrToOct (char *a_, unsigned int _a_high, unsigned int *x)
+extern "C" void NumberIO_StrToOct (const char *a_, unsigned int _a_high, unsigned int *x)
 {
   int i;
   char a[_a_high+1];
@@ -513,11 +513,11 @@ void NumberIO_StrToOct (char *a_, unsigned int _a_high, unsigned int *x)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  NumberIO_StrToOctInt ((char *) a, _a_high, &i);
+  NumberIO_StrToOctInt ((const char *) a, _a_high, &i);
   (*x) = (unsigned int ) (i);
 }
 
-void NumberIO_ReadBin (unsigned int *x)
+extern "C" void NumberIO_ReadBin (unsigned int *x)
 {
   typedef struct _T13_a _T13;
 
@@ -525,10 +525,10 @@ void NumberIO_ReadBin (unsigned int *x)
   _T13 a;
 
   StrIO_ReadString ((char *) &a.array[0], MaxLineLength);
-  NumberIO_StrToBin ((char *) &a.array[0], MaxLineLength, x);
+  NumberIO_StrToBin ((const char *) &a.array[0], MaxLineLength, x);
 }
 
-void NumberIO_WriteBin (unsigned int x, unsigned int n)
+extern "C" void NumberIO_WriteBin (unsigned int x, unsigned int n)
 {
   typedef struct _T14_a _T14;
 
@@ -536,10 +536,10 @@ void NumberIO_WriteBin (unsigned int x, unsigned int n)
   _T14 a;
 
   NumberIO_BinToStr (x, n, (char *) &a.array[0], MaxLineLength);
-  StrIO_WriteString ((char *) &a.array[0], MaxLineLength);
+  StrIO_WriteString ((const char *) &a.array[0], MaxLineLength);
 }
 
-void NumberIO_BinToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high)
+extern "C" void NumberIO_BinToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high)
 {
   typedef struct _T15_a _T15;
 
@@ -549,20 +549,20 @@ void NumberIO_BinToStr (unsigned int x, unsigned int n, char *a, unsigned int _a
   unsigned int Higha;
   _T15 buf;
 
-  i = 0;
+  i = static_cast<unsigned int> (0);
   do {
     i += 1;
     if (i > MaxBits)
       {
-        StrIO_WriteString ((char *) "NumberIO - increase MaxBits", 27);
+        StrIO_WriteString ((const char *) "NumberIO - increase MaxBits", 27);
         StrIO_WriteLn ();
         M2RTS_HALT (-1);
         __builtin_unreachable ();
       }
-    buf.array[i-1] = x % 2;
-    x = x / 2;
+    buf.array[i-1] = static_cast<unsigned int> (x % 2);
+    x = static_cast<unsigned int> (x / 2);
   } while (! (x == 0));
-  j = 0;
+  j = static_cast<unsigned int> (0);
   Higha = _a_high;
   while ((n > i) && (j <= Higha))
     {
@@ -582,7 +582,7 @@ void NumberIO_BinToStr (unsigned int x, unsigned int n, char *a, unsigned int _a
     }
 }
 
-void NumberIO_StrToBin (char *a_, unsigned int _a_high, unsigned int *x)
+extern "C" void NumberIO_StrToBin (const char *a_, unsigned int _a_high, unsigned int *x)
 {
   int i;
   char a[_a_high+1];
@@ -590,11 +590,11 @@ void NumberIO_StrToBin (char *a_, unsigned int _a_high, unsigned int *x)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  NumberIO_StrToBinInt ((char *) a, _a_high, &i);
+  NumberIO_StrToBinInt ((const char *) a, _a_high, &i);
   (*x) = (unsigned int ) (i);
 }
 
-void NumberIO_StrToBinInt (char *a_, unsigned int _a_high, int *x)
+extern "C" void NumberIO_StrToBinInt (const char *a_, unsigned int _a_high, int *x)
 {
   unsigned int i;
   unsigned int ok;
@@ -604,9 +604,9 @@ void NumberIO_StrToBinInt (char *a_, unsigned int _a_high, int *x)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  StrLib_StrRemoveWhitePrefix ((char *) a, _a_high, (char *) a, _a_high);
-  higha = StrLib_StrLen ((char *) a, _a_high);
-  i = 0;
+  StrLib_StrRemoveWhitePrefix ((const char *) a, _a_high, (char *) a, _a_high);
+  higha = static_cast<unsigned int> (StrLib_StrLen ((const char *) a, _a_high));
+  i = static_cast<unsigned int> (0);
   ok = TRUE;
   while (ok)
     {
@@ -626,12 +626,12 @@ void NumberIO_StrToBinInt (char *a_, unsigned int _a_high, int *x)
           ok = FALSE;
         }
     }
-  (*x) = 0;
+  (*x) = static_cast<int> (0);
   if (i < higha)
     {
       ok = TRUE;
       do {
-        (*x) = (2*(*x))+((int ) ( ((unsigned int) (a[i]))- ((unsigned int) ('0'))));
+        (*x) = static_cast<int> ((2*(*x))+((int ) ( ((unsigned int) (a[i]))- ((unsigned int) ('0')))));
         if (i < higha)
           {
             /* avoid dangling else.  */
@@ -649,7 +649,7 @@ void NumberIO_StrToBinInt (char *a_, unsigned int _a_high, int *x)
     }
 }
 
-void NumberIO_StrToHexInt (char *a_, unsigned int _a_high, int *x)
+extern "C" void NumberIO_StrToHexInt (const char *a_, unsigned int _a_high, int *x)
 {
   unsigned int i;
   unsigned int ok;
@@ -659,9 +659,9 @@ void NumberIO_StrToHexInt (char *a_, unsigned int _a_high, int *x)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  StrLib_StrRemoveWhitePrefix ((char *) a, _a_high, (char *) a, _a_high);
-  higha = StrLib_StrLen ((char *) a, _a_high);
-  i = 0;
+  StrLib_StrRemoveWhitePrefix ((const char *) a, _a_high, (char *) a, _a_high);
+  higha = static_cast<unsigned int> (StrLib_StrLen ((const char *) a, _a_high));
+  i = static_cast<unsigned int> (0);
   ok = TRUE;
   while (ok)
     {
@@ -681,19 +681,19 @@ void NumberIO_StrToHexInt (char *a_, unsigned int _a_high, int *x)
           ok = FALSE;
         }
     }
-  (*x) = 0;
+  (*x) = static_cast<int> (0);
   if (i < higha)
     {
       ok = TRUE;
       do {
         if ((a[i] >= '0') && (a[i] <= '9'))
           {
-            (*x) = (0x010*(*x))+((int ) ( ((unsigned int) (a[i]))- ((unsigned int) ('0'))));
+            (*x) = static_cast<int> ((0x010*(*x))+((int ) ( ((unsigned int) (a[i]))- ((unsigned int) ('0')))));
           }
         else if ((a[i] >= 'A') && (a[i] <= 'F'))
           {
             /* avoid dangling else.  */
-            (*x) = (0x010*(*x))+((int ) (( ((unsigned int) (a[i]))- ((unsigned int) ('A')))+10));
+            (*x) = static_cast<int> ((0x010*(*x))+((int ) (( ((unsigned int) (a[i]))- ((unsigned int) ('A')))+10)));
           }
         if (i < higha)
           {
@@ -712,7 +712,7 @@ void NumberIO_StrToHexInt (char *a_, unsigned int _a_high, int *x)
     }
 }
 
-void NumberIO_StrToOctInt (char *a_, unsigned int _a_high, int *x)
+extern "C" void NumberIO_StrToOctInt (const char *a_, unsigned int _a_high, int *x)
 {
   unsigned int i;
   unsigned int ok;
@@ -722,9 +722,9 @@ void NumberIO_StrToOctInt (char *a_, unsigned int _a_high, int *x)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  StrLib_StrRemoveWhitePrefix ((char *) a, _a_high, (char *) a, _a_high);
-  higha = StrLib_StrLen ((char *) a, _a_high);
-  i = 0;
+  StrLib_StrRemoveWhitePrefix ((const char *) a, _a_high, (char *) a, _a_high);
+  higha = static_cast<unsigned int> (StrLib_StrLen ((const char *) a, _a_high));
+  i = static_cast<unsigned int> (0);
   ok = TRUE;
   while (ok)
     {
@@ -744,12 +744,12 @@ void NumberIO_StrToOctInt (char *a_, unsigned int _a_high, int *x)
           ok = FALSE;
         }
     }
-  (*x) = 0;
+  (*x) = static_cast<int> (0);
   if (i < higha)
     {
       ok = TRUE;
       do {
-        (*x) = (8*(*x))+((int ) ( ((unsigned int) (a[i]))- ((unsigned int) ('0'))));
+        (*x) = static_cast<int> ((8*(*x))+((int ) ( ((unsigned int) (a[i]))- ((unsigned int) ('0')))));
         if (i < higha)
           {
             /* avoid dangling else.  */
@@ -767,10 +767,10 @@ void NumberIO_StrToOctInt (char *a_, unsigned int _a_high, int *x)
     }
 }
 
-void _M2_NumberIO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_NumberIO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_NumberIO_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_NumberIO_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GNumberIO.h b/gcc/m2/mc-boot/GNumberIO.h
index 8729183181f..efebe4ee793 100644
--- a/gcc/m2/mc-boot/GNumberIO.h
+++ b/gcc/m2/mc-boot/GNumberIO.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_NumberIO_H)
 #   define _NumberIO_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
@@ -54,22 +54,22 @@ EXTERN void NumberIO_WriteHex (unsigned int x, unsigned int n);
 EXTERN void NumberIO_ReadInt (int *x);
 EXTERN void NumberIO_WriteInt (int x, unsigned int n);
 EXTERN void NumberIO_CardToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high);
-EXTERN void NumberIO_StrToCard (char *a_, unsigned int _a_high, unsigned int *x);
+EXTERN void NumberIO_StrToCard (const char *a_, unsigned int _a_high, unsigned int *x);
 EXTERN void NumberIO_HexToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high);
-EXTERN void NumberIO_StrToHex (char *a_, unsigned int _a_high, unsigned int *x);
+EXTERN void NumberIO_StrToHex (const char *a_, unsigned int _a_high, unsigned int *x);
 EXTERN void NumberIO_IntToStr (int x, unsigned int n, char *a, unsigned int _a_high);
-EXTERN void NumberIO_StrToInt (char *a_, unsigned int _a_high, int *x);
+EXTERN void NumberIO_StrToInt (const char *a_, unsigned int _a_high, int *x);
 EXTERN void NumberIO_ReadOct (unsigned int *x);
 EXTERN void NumberIO_WriteOct (unsigned int x, unsigned int n);
 EXTERN void NumberIO_OctToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high);
-EXTERN void NumberIO_StrToOct (char *a_, unsigned int _a_high, unsigned int *x);
+EXTERN void NumberIO_StrToOct (const char *a_, unsigned int _a_high, unsigned int *x);
 EXTERN void NumberIO_ReadBin (unsigned int *x);
 EXTERN void NumberIO_WriteBin (unsigned int x, unsigned int n);
 EXTERN void NumberIO_BinToStr (unsigned int x, unsigned int n, char *a, unsigned int _a_high);
-EXTERN void NumberIO_StrToBin (char *a_, unsigned int _a_high, unsigned int *x);
-EXTERN void NumberIO_StrToBinInt (char *a_, unsigned int _a_high, int *x);
-EXTERN void NumberIO_StrToHexInt (char *a_, unsigned int _a_high, int *x);
-EXTERN void NumberIO_StrToOctInt (char *a_, unsigned int _a_high, int *x);
+EXTERN void NumberIO_StrToBin (const char *a_, unsigned int _a_high, unsigned int *x);
+EXTERN void NumberIO_StrToBinInt (const char *a_, unsigned int _a_high, int *x);
+EXTERN void NumberIO_StrToHexInt (const char *a_, unsigned int _a_high, int *x);
+EXTERN void NumberIO_StrToOctInt (const char *a_, unsigned int _a_high, int *x);
 #   ifdef __cplusplus
 }
 #   endif
diff --git a/gcc/m2/mc-boot/GPushBackInput.c b/gcc/m2/mc-boot/GPushBackInput.c
index f5219200729..df6fd0d92cb 100644
--- a/gcc/m2/mc-boot/GPushBackInput.c
+++ b/gcc/m2/mc-boot/GPushBackInput.c
@@ -56,14 +56,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #   define MaxPushBackStack 8192
 #   define MaxFileName 4096
-typedef struct _T1_a _T1;
-
 typedef struct _T2_a _T2;
 
-struct _T1_a { char array[MaxFileName+1]; };
-struct _T2_a { char array[MaxPushBackStack+1]; };
-static _T1 FileName;
-static _T2 CharStack;
+typedef struct _T3_a _T3;
+
+struct _T2_a { char array[MaxFileName+1]; };
+struct _T3_a { char array[MaxPushBackStack+1]; };
+static _T2 FileName;
+static _T3 CharStack;
 static unsigned int ExitStatus;
 static unsigned int Column;
 static unsigned int StackPtr;
@@ -74,40 +74,40 @@ static unsigned int Debugging;
    Open - opens a file for reading.
 */
 
-FIO_File PushBackInput_Open (char *a_, unsigned int _a_high);
+extern "C" FIO_File PushBackInput_Open (const char *a_, unsigned int _a_high);
 
 /*
    GetCh - gets a character from either the push back stack or
            from file, f.
 */
 
-char PushBackInput_GetCh (FIO_File f);
+extern "C" char PushBackInput_GetCh (FIO_File f);
 
 /*
    PutCh - pushes a character onto the push back stack, it also
            returns the character which has been pushed.
 */
 
-char PushBackInput_PutCh (char ch);
+extern "C" char PushBackInput_PutCh (char ch);
 
 /*
    PutString - pushes a string onto the push back stack.
 */
 
-void PushBackInput_PutString (char *a_, unsigned int _a_high);
+extern "C" void PushBackInput_PutString (const char *a_, unsigned int _a_high);
 
 /*
    PutStr - pushes a dynamic string onto the push back stack.
             The string, s, is not deallocated.
 */
 
-void PushBackInput_PutStr (DynamicStrings_String s);
+extern "C" void PushBackInput_PutStr (DynamicStrings_String s);
 
 /*
    Error - emits an error message with the appropriate file, line combination.
 */
 
-void PushBackInput_Error (char *a_, unsigned int _a_high);
+extern "C" void PushBackInput_Error (const char *a_, unsigned int _a_high);
 
 /*
    WarnError - emits an error message with the appropriate file, line combination.
@@ -115,7 +115,7 @@ void PushBackInput_Error (char *a_, unsigned int _a_high);
                1 will be issued.
 */
 
-void PushBackInput_WarnError (char *a_, unsigned int _a_high);
+extern "C" void PushBackInput_WarnError (const char *a_, unsigned int _a_high);
 
 /*
    WarnString - emits an error message with the appropriate file, line combination.
@@ -123,37 +123,37 @@ void PushBackInput_WarnError (char *a_, unsigned int _a_high);
                 1 will be issued.
 */
 
-void PushBackInput_WarnString (DynamicStrings_String s);
+extern "C" void PushBackInput_WarnString (DynamicStrings_String s);
 
 /*
    Close - closes the opened file.
 */
 
-void PushBackInput_Close (FIO_File f);
+extern "C" void PushBackInput_Close (FIO_File f);
 
 /*
    GetExitStatus - returns the exit status which will be 1 if any warnings were issued.
 */
 
-unsigned int PushBackInput_GetExitStatus (void);
+extern "C" unsigned int PushBackInput_GetExitStatus (void);
 
 /*
    SetDebug - sets the debug flag on or off.
 */
 
-void PushBackInput_SetDebug (unsigned int d);
+extern "C" void PushBackInput_SetDebug (unsigned int d);
 
 /*
    GetColumnPosition - returns the column position of the current character.
 */
 
-unsigned int PushBackInput_GetColumnPosition (void);
+extern "C" unsigned int PushBackInput_GetColumnPosition (void);
 
 /*
    GetCurrentLine - returns the current line number.
 */
 
-unsigned int PushBackInput_GetCurrentLine (void);
+extern "C" unsigned int PushBackInput_GetCurrentLine (void);
 
 /*
    ErrChar - writes a char, ch, to stderr.
@@ -184,10 +184,10 @@ static void ErrChar (char ch)
 
 static void Init (void)
 {
-  ExitStatus = 0;
-  StackPtr = 0;
-  LineNo = 1;
-  Column = 0;
+  ExitStatus = static_cast<unsigned int> (0);
+  StackPtr = static_cast<unsigned int> (0);
+  LineNo = static_cast<unsigned int> (1);
+  Column = static_cast<unsigned int> (0);
 }
 
 
@@ -195,7 +195,7 @@ static void Init (void)
    Open - opens a file for reading.
 */
 
-FIO_File PushBackInput_Open (char *a_, unsigned int _a_high)
+extern "C" FIO_File PushBackInput_Open (const char *a_, unsigned int _a_high)
 {
   char a[_a_high+1];
 
@@ -203,8 +203,8 @@ FIO_File PushBackInput_Open (char *a_, unsigned int _a_high)
   memcpy (a, a_, _a_high+1);
 
   Init ();
-  StrLib_StrCopy ((char *) a, _a_high, (char *) &FileName.array[0], MaxFileName);
-  return FIO_OpenToRead ((char *) a, _a_high);
+  StrLib_StrCopy ((const char *) a, _a_high, (char *) &FileName.array[0], MaxFileName);
+  return static_cast<FIO_File> (FIO_OpenToRead ((const char *) a, _a_high));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -215,7 +215,7 @@ FIO_File PushBackInput_Open (char *a_, unsigned int _a_high)
            from file, f.
 */
 
-char PushBackInput_GetCh (FIO_File f)
+extern "C" char PushBackInput_GetCh (FIO_File f)
 {
   char ch;
 
@@ -232,16 +232,16 @@ char PushBackInput_GetCh (FIO_File f)
     {
       if ((FIO_EOF (f)) || (! (FIO_IsNoError (f))))
         {
-          ch = ASCII_nul;
+          ch = static_cast<char> (ASCII_nul);
         }
       else
         {
           do {
-            ch = FIO_ReadChar (f);
+            ch = static_cast<char> (FIO_ReadChar (f));
           } while (! (((ch != ASCII_cr) || (FIO_EOF (f))) || (! (FIO_IsNoError (f)))));
           if (ch == ASCII_lf)
             {
-              Column = 0;
+              Column = static_cast<unsigned int> (0);
               LineNo += 1;
             }
           else
@@ -265,7 +265,7 @@ char PushBackInput_GetCh (FIO_File f)
            returns the character which has been pushed.
 */
 
-char PushBackInput_PutCh (char ch)
+extern "C" char PushBackInput_PutCh (char ch)
 {
   if (StackPtr < MaxPushBackStack)
     {
@@ -274,7 +274,7 @@ char PushBackInput_PutCh (char ch)
     }
   else
     {
-      Debug_Halt ((char *) "max push back stack exceeded, increase MaxPushBackStack", 55, 150, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/PushBackInput.mod", 85);
+      Debug_Halt ((const char *) "max push back stack exceeded, increase MaxPushBackStack", 55, 150, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/PushBackInput.mod", 85);
     }
   return ch;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -286,7 +286,7 @@ char PushBackInput_PutCh (char ch)
    PutString - pushes a string onto the push back stack.
 */
 
-void PushBackInput_PutString (char *a_, unsigned int _a_high)
+extern "C" void PushBackInput_PutString (const char *a_, unsigned int _a_high)
 {
   unsigned int l;
   char a[_a_high+1];
@@ -294,13 +294,13 @@ void PushBackInput_PutString (char *a_, unsigned int _a_high)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  l = StrLib_StrLen ((char *) a, _a_high);
+  l = static_cast<unsigned int> (StrLib_StrLen ((const char *) a, _a_high));
   while (l > 0)
     {
       l -= 1;
       if ((PushBackInput_PutCh (a[l])) != a[l])
         {
-          Debug_Halt ((char *) "assert failed", 13, 132, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/PushBackInput.mod", 85);
+          Debug_Halt ((const char *) "assert failed", 13, 132, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/PushBackInput.mod", 85);
         }
     }
 }
@@ -311,17 +311,17 @@ void PushBackInput_PutString (char *a_, unsigned int _a_high)
             The string, s, is not deallocated.
 */
 
-void PushBackInput_PutStr (DynamicStrings_String s)
+extern "C" void PushBackInput_PutStr (DynamicStrings_String s)
 {
   unsigned int i;
 
-  i = DynamicStrings_Length (s);
+  i = static_cast<unsigned int> (DynamicStrings_Length (s));
   while (i > 0)
     {
       i -= 1;
-      if ((PushBackInput_PutCh (DynamicStrings_char (s, (int) i))) != (DynamicStrings_char (s, (int) i)))
+      if ((PushBackInput_PutCh (DynamicStrings_char (s, static_cast<int> (i)))) != (DynamicStrings_char (s, static_cast<int> (i))))
         {
-          Debug_Halt ((char *) "assert failed", 13, 113, (char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/PushBackInput.mod", 85);
+          Debug_Halt ((const char *) "assert failed", 13, 113, (const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/PushBackInput.mod", 85);
         }
     }
 }
@@ -331,7 +331,7 @@ void PushBackInput_PutStr (DynamicStrings_String s)
    Error - emits an error message with the appropriate file, line combination.
 */
 
-void PushBackInput_Error (char *a_, unsigned int _a_high)
+extern "C" void PushBackInput_Error (const char *a_, unsigned int _a_high)
 {
   char a[_a_high+1];
 
@@ -339,11 +339,11 @@ void PushBackInput_Error (char *a_, unsigned int _a_high)
   memcpy (a, a_, _a_high+1);
 
   StdIO_PushOutput ((StdIO_ProcWrite) {(StdIO_ProcWrite_t) ErrChar});
-  StrIO_WriteString ((char *) &FileName.array[0], MaxFileName);
+  StrIO_WriteString ((const char *) &FileName.array[0], MaxFileName);
   StdIO_Write (':');
   NumberIO_WriteCard (LineNo, 0);
   StdIO_Write (':');
-  StrIO_WriteString ((char *) a, _a_high);
+  StrIO_WriteString ((const char *) a, _a_high);
   StrIO_WriteLn ();
   StdIO_PopOutput ();
   FIO_Close (FIO_StdErr);
@@ -357,7 +357,7 @@ void PushBackInput_Error (char *a_, unsigned int _a_high)
                1 will be issued.
 */
 
-void PushBackInput_WarnError (char *a_, unsigned int _a_high)
+extern "C" void PushBackInput_WarnError (const char *a_, unsigned int _a_high)
 {
   char a[_a_high+1];
 
@@ -365,14 +365,14 @@ void PushBackInput_WarnError (char *a_, unsigned int _a_high)
   memcpy (a, a_, _a_high+1);
 
   StdIO_PushOutput ((StdIO_ProcWrite) {(StdIO_ProcWrite_t) ErrChar});
-  StrIO_WriteString ((char *) &FileName.array[0], MaxFileName);
+  StrIO_WriteString ((const char *) &FileName.array[0], MaxFileName);
   StdIO_Write (':');
   NumberIO_WriteCard (LineNo, 0);
   StdIO_Write (':');
-  StrIO_WriteString ((char *) a, _a_high);
+  StrIO_WriteString ((const char *) a, _a_high);
   StrIO_WriteLn ();
   StdIO_PopOutput ();
-  ExitStatus = 1;
+  ExitStatus = static_cast<unsigned int> (1);
 }
 
 
@@ -382,12 +382,14 @@ void PushBackInput_WarnError (char *a_, unsigned int _a_high)
                 1 will be issued.
 */
 
-void PushBackInput_WarnString (DynamicStrings_String s)
+extern "C" void PushBackInput_WarnString (DynamicStrings_String s)
 {
-  char * p;
+  typedef char *_T1;
+
+  _T1 p;
 
-  p = DynamicStrings_string (s);
-  StrIO_WriteString ((char *) &FileName.array[0], MaxFileName);
+  p = static_cast<_T1> (DynamicStrings_string (s));
+  StrIO_WriteString ((const char *) &FileName.array[0], MaxFileName);
   StdIO_Write (':');
   NumberIO_WriteCard (LineNo, 0);
   StdIO_Write (':');
@@ -397,7 +399,7 @@ void PushBackInput_WarnString (DynamicStrings_String s)
         if ((*p) == ASCII_lf)
           {
             StrIO_WriteLn ();
-            StrIO_WriteString ((char *) &FileName.array[0], MaxFileName);
+            StrIO_WriteString ((const char *) &FileName.array[0], MaxFileName);
             StdIO_Write (':');
             NumberIO_WriteCard (LineNo, 0);
             StdIO_Write (':');
@@ -409,7 +411,7 @@ void PushBackInput_WarnString (DynamicStrings_String s)
         p += 1;
       }
   } while (! ((p == NULL) || ((*p) == ASCII_nul)));
-  ExitStatus = 1;
+  ExitStatus = static_cast<unsigned int> (1);
 }
 
 
@@ -417,7 +419,7 @@ void PushBackInput_WarnString (DynamicStrings_String s)
    Close - closes the opened file.
 */
 
-void PushBackInput_Close (FIO_File f)
+extern "C" void PushBackInput_Close (FIO_File f)
 {
   FIO_Close (f);
 }
@@ -427,7 +429,7 @@ void PushBackInput_Close (FIO_File f)
    GetExitStatus - returns the exit status which will be 1 if any warnings were issued.
 */
 
-unsigned int PushBackInput_GetExitStatus (void)
+extern "C" unsigned int PushBackInput_GetExitStatus (void)
 {
   return ExitStatus;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -439,7 +441,7 @@ unsigned int PushBackInput_GetExitStatus (void)
    SetDebug - sets the debug flag on or off.
 */
 
-void PushBackInput_SetDebug (unsigned int d)
+extern "C" void PushBackInput_SetDebug (unsigned int d)
 {
   Debugging = d;
 }
@@ -449,15 +451,15 @@ void PushBackInput_SetDebug (unsigned int d)
    GetColumnPosition - returns the column position of the current character.
 */
 
-unsigned int PushBackInput_GetColumnPosition (void)
+extern "C" unsigned int PushBackInput_GetColumnPosition (void)
 {
   if (StackPtr > Column)
     {
-      return 0;
+      return static_cast<unsigned int> (0);
     }
   else
     {
-      return Column-StackPtr;
+      return static_cast<unsigned int> (Column-StackPtr);
     }
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
@@ -468,19 +470,19 @@ unsigned int PushBackInput_GetColumnPosition (void)
    GetCurrentLine - returns the current line number.
 */
 
-unsigned int PushBackInput_GetCurrentLine (void)
+extern "C" unsigned int PushBackInput_GetCurrentLine (void)
 {
   return LineNo;
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
 
-void _M2_PushBackInput_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_PushBackInput_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
   PushBackInput_SetDebug (FALSE);
   Init ();
 }
 
-void _M2_PushBackInput_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_PushBackInput_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GPushBackInput.h b/gcc/m2/mc-boot/GPushBackInput.h
index 3fef75a3995..68ab44bf2dd 100644
--- a/gcc/m2/mc-boot/GPushBackInput.h
+++ b/gcc/m2/mc-boot/GPushBackInput.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_PushBackInput_H)
 #   define _PushBackInput_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
@@ -54,7 +54,7 @@ extern "C" {
    Open - opens a file for reading.
 */
 
-EXTERN FIO_File PushBackInput_Open (char *a_, unsigned int _a_high);
+EXTERN FIO_File PushBackInput_Open (const char *a_, unsigned int _a_high);
 
 /*
    GetCh - gets a character from either the push back stack or
@@ -74,7 +74,7 @@ EXTERN char PushBackInput_PutCh (char ch);
    PutString - pushes a string onto the push back stack.
 */
 
-EXTERN void PushBackInput_PutString (char *a_, unsigned int _a_high);
+EXTERN void PushBackInput_PutString (const char *a_, unsigned int _a_high);
 
 /*
    PutStr - pushes a dynamic string onto the push back stack.
@@ -87,7 +87,7 @@ EXTERN void PushBackInput_PutStr (DynamicStrings_String s);
    Error - emits an error message with the appropriate file, line combination.
 */
 
-EXTERN void PushBackInput_Error (char *a_, unsigned int _a_high);
+EXTERN void PushBackInput_Error (const char *a_, unsigned int _a_high);
 
 /*
    WarnError - emits an error message with the appropriate file, line combination.
@@ -95,7 +95,7 @@ EXTERN void PushBackInput_Error (char *a_, unsigned int _a_high);
                1 will be issued.
 */
 
-EXTERN void PushBackInput_WarnError (char *a_, unsigned int _a_high);
+EXTERN void PushBackInput_WarnError (const char *a_, unsigned int _a_high);
 
 /*
    WarnString - emits an error message with the appropriate file, line combination.
diff --git a/gcc/m2/mc-boot/GRTExceptions.c b/gcc/m2/mc-boot/GRTExceptions.c
index 1e26c71fd06..e6421568b72 100644
--- a/gcc/m2/mc-boot/GRTExceptions.c
+++ b/gcc/m2/mc-boot/GRTExceptions.c
@@ -104,63 +104,63 @@ static void * currentSource;
            and message in the EHBlock for later use.
 */
 
-void RTExceptions_Raise (unsigned int number, void * file, unsigned int line, unsigned int column, void * function, void * message);
+extern "C" void RTExceptions_Raise (unsigned int number, void * file, unsigned int line, unsigned int column, void * function, void * message);
 
 /*
    SetExceptionBlock - sets, source, as the active EHB.
 */
 
-void RTExceptions_SetExceptionBlock (RTExceptions_EHBlock source);
+extern "C" void RTExceptions_SetExceptionBlock (RTExceptions_EHBlock source);
 
 /*
    GetExceptionBlock - returns the active EHB.
 */
 
-RTExceptions_EHBlock RTExceptions_GetExceptionBlock (void);
+extern "C" RTExceptions_EHBlock RTExceptions_GetExceptionBlock (void);
 
 /*
    GetTextBuffer - returns the address of the EHB buffer.
 */
 
-void * RTExceptions_GetTextBuffer (RTExceptions_EHBlock e);
+extern "C" void * RTExceptions_GetTextBuffer (RTExceptions_EHBlock e);
 
 /*
    GetTextBufferSize - return the size of the EHB text buffer.
 */
 
-unsigned int RTExceptions_GetTextBufferSize (RTExceptions_EHBlock e);
+extern "C" unsigned int RTExceptions_GetTextBufferSize (RTExceptions_EHBlock e);
 
 /*
    GetNumber - return the exception number associated with,
                source.
 */
 
-unsigned int RTExceptions_GetNumber (RTExceptions_EHBlock source);
+extern "C" unsigned int RTExceptions_GetNumber (RTExceptions_EHBlock source);
 
 /*
    InitExceptionBlock - creates and returns a new exception block.
 */
 
-RTExceptions_EHBlock RTExceptions_InitExceptionBlock (void);
+extern "C" RTExceptions_EHBlock RTExceptions_InitExceptionBlock (void);
 
 /*
    KillExceptionBlock - destroys the EHB, e, and all its handlers.
 */
 
-RTExceptions_EHBlock RTExceptions_KillExceptionBlock (RTExceptions_EHBlock e);
+extern "C" RTExceptions_EHBlock RTExceptions_KillExceptionBlock (RTExceptions_EHBlock e);
 
 /*
    PushHandler - install a handler in EHB, e.
 */
 
-void RTExceptions_PushHandler (RTExceptions_EHBlock e, unsigned int number, RTExceptions_ProcedureHandler p);
+extern "C" void RTExceptions_PushHandler (RTExceptions_EHBlock e, unsigned int number, RTExceptions_ProcedureHandler p);
 
 /*
    PopHandler - removes the handler associated with, number, from
                 EHB, e.
 */
 
-void RTExceptions_PopHandler (RTExceptions_EHBlock e, unsigned int number);
+extern "C" void RTExceptions_PopHandler (RTExceptions_EHBlock e, unsigned int number);
 
 /*
    DefaultErrorCatch - displays the current error message in
@@ -168,7 +168,7 @@ void RTExceptions_PopHandler (RTExceptions_EHBlock e, unsigned int number);
                        calls HALT.
 */
 
-void RTExceptions_DefaultErrorCatch (void);
+extern "C" void RTExceptions_DefaultErrorCatch (void);
 
 /*
    BaseExceptionsThrow - configures the Modula-2 exceptions to call
@@ -178,14 +178,14 @@ void RTExceptions_DefaultErrorCatch (void);
                          error message routine and then HALT.
 */
 
-void RTExceptions_BaseExceptionsThrow (void);
+extern "C" void RTExceptions_BaseExceptionsThrow (void);
 
 /*
    IsInExceptionState - returns TRUE if the program is currently
                         in the exception state.
 */
 
-unsigned int RTExceptions_IsInExceptionState (void);
+extern "C" unsigned int RTExceptions_IsInExceptionState (void);
 
 /*
    SetExceptionState - returns the current exception state and
@@ -193,7 +193,7 @@ unsigned int RTExceptions_IsInExceptionState (void);
                        to.
 */
 
-unsigned int RTExceptions_SetExceptionState (unsigned int to);
+extern "C" unsigned int RTExceptions_SetExceptionState (unsigned int to);
 
 /*
    SwitchExceptionState - assigns, from, with the current exception
@@ -201,32 +201,32 @@ unsigned int RTExceptions_SetExceptionState (unsigned int to);
                           to, to.
 */
 
-void RTExceptions_SwitchExceptionState (unsigned int *from, unsigned int to);
+extern "C" void RTExceptions_SwitchExceptionState (unsigned int *from, unsigned int to);
 
 /*
    GetBaseExceptionBlock - returns the initial language exception block
                            created.
 */
 
-RTExceptions_EHBlock RTExceptions_GetBaseExceptionBlock (void);
+extern "C" RTExceptions_EHBlock RTExceptions_GetBaseExceptionBlock (void);
 
 /*
    SetExceptionSource - sets the current exception source to, source.
 */
 
-void RTExceptions_SetExceptionSource (void * source);
+extern "C" void RTExceptions_SetExceptionSource (void * source);
 
 /*
    GetExceptionSource - returns the current exception source.
 */
 
-void * RTExceptions_GetExceptionSource (void);
+extern "C" void * RTExceptions_GetExceptionSource (void);
 
 /*
    ErrorString - writes a string to stderr.
 */
 
-static void ErrorString (char *a_, unsigned int _a_high);
+static void ErrorString (const char *a_, unsigned int _a_high);
 
 /*
    findHandler -
@@ -430,7 +430,7 @@ static void TidyUp (void);
    ErrorString - writes a string to stderr.
 */
 
-static void ErrorString (char *a_, unsigned int _a_high)
+static void ErrorString (const char *a_, unsigned int _a_high)
 {
   int n;
   char a[_a_high+1];
@@ -438,7 +438,7 @@ static void ErrorString (char *a_, unsigned int _a_high)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  n = libc_write (2, &a, (size_t) StrLib_StrLen ((char *) a, _a_high));
+  n = static_cast<int> (libc_write (2, &a, static_cast<size_t> (StrLib_StrLen ((const char *) a, _a_high))));
 }
 
 
@@ -457,7 +457,7 @@ static Handler findHandler (RTExceptions_EHBlock e, unsigned int number)
     }
   if (h == e->handlers)
     {
-      return NULL;
+      return static_cast<Handler> (NULL);
     }
   else
     {
@@ -477,7 +477,7 @@ static void InvokeHandler (void)
 {
   Handler h;
 
-  h = findHandler (currentEHB, currentEHB->number);
+  h = static_cast<Handler> (findHandler (currentEHB, currentEHB->number));
   if (h == NULL)
     {
       throw (RTExceptions_GetNumber (RTExceptions_GetExceptionBlock ()));
@@ -523,8 +523,8 @@ static void * stripPath (void * s)
   PtrToChar f;
   PtrToChar p;
 
-  p = s;
-  f = s;
+  p = static_cast<PtrToChar> (s);
+  f = static_cast<PtrToChar> (s);
   while ((*p) != ASCII_nul)
     {
       if ((*p) == '/')
@@ -537,7 +537,7 @@ static void * stripPath (void * s)
           p += 1;
         }
     }
-  return f;
+  return reinterpret_cast<void *> (f);
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -552,7 +552,7 @@ static void addFile (void * s, unsigned int *i)
 {
   PtrToChar p;
 
-  p = stripPath (s);
+  p = static_cast<PtrToChar> (stripPath (s));
   while ((p != NULL) && ((*p) != ASCII_nul))
     {
       addChar ((*p), i);
@@ -570,7 +570,7 @@ static void addStr (void * s, unsigned int *i)
 {
   PtrToChar p;
 
-  p = s;
+  p = static_cast<PtrToChar> (s);
   while ((p != NULL) && ((*p) != ASCII_nul))
     {
       addChar ((*p), i);
@@ -652,7 +652,7 @@ static Handler KillHandler (Handler h)
 {
   h->right = freeHandler;
   freeHandler = h;
-  return NULL;
+  return static_cast<Handler> (NULL);
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -666,7 +666,7 @@ static Handler KillHandlers (Handler h)
 {
   h->left->right = freeHandler;
   freeHandler = h;
-  return NULL;
+  return static_cast<Handler> (NULL);
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -719,7 +719,7 @@ static void AddHandler (RTExceptions_EHBlock e, Handler h)
 
 static void indexf (void * a)
 {
-  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_indexException)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 612, 9, "indexf", "array index out of bounds");
+  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_indexException)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod")), 612, 9, const_cast<void*> (reinterpret_cast<const void*>("indexf")), const_cast<void*> (reinterpret_cast<const void*>("array index out of bounds")));
 }
 
 
@@ -729,7 +729,7 @@ static void indexf (void * a)
 
 static void range (void * a)
 {
-  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 624, 9, "range", "assignment out of range");
+  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod")), 624, 9, const_cast<void*> (reinterpret_cast<const void*>("range")), const_cast<void*> (reinterpret_cast<const void*>("assignment out of range")));
 }
 
 
@@ -739,7 +739,7 @@ static void range (void * a)
 
 static void casef (void * a)
 {
-  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_caseSelectException)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 636, 9, "casef", "case selector out of range");
+  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_caseSelectException)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod")), 636, 9, const_cast<void*> (reinterpret_cast<const void*>("casef")), const_cast<void*> (reinterpret_cast<const void*>("case selector out of range")));
 }
 
 
@@ -749,7 +749,7 @@ static void casef (void * a)
 
 static void invalidloc (void * a)
 {
-  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_invalidLocation)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 648, 9, "invalidloc", "invalid address referenced");
+  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_invalidLocation)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod")), 648, 9, const_cast<void*> (reinterpret_cast<const void*>("invalidloc")), const_cast<void*> (reinterpret_cast<const void*>("invalid address referenced")));
 }
 
 
@@ -759,7 +759,7 @@ static void invalidloc (void * a)
 
 static void function (void * a)
 {
-  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_functionException)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 660, 9, "function", "... function ... ");  /* --fixme-- what has happened ?  */
+  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_functionException)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod")), 660, 9, const_cast<void*> (reinterpret_cast<const void*>("function")), const_cast<void*> (reinterpret_cast<const void*>("... function ... ")));  /* --fixme-- what has happened ?  */
 }
 
 
@@ -769,7 +769,7 @@ static void function (void * a)
 
 static void wholevalue (void * a)
 {
-  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeValueException)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 672, 9, "wholevalue", "illegal whole value exception");
+  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeValueException)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod")), 672, 9, const_cast<void*> (reinterpret_cast<const void*>("wholevalue")), const_cast<void*> (reinterpret_cast<const void*>("illegal whole value exception")));
 }
 
 
@@ -779,7 +779,7 @@ static void wholevalue (void * a)
 
 static void wholediv (void * a)
 {
-  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeDivException)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 684, 9, "wholediv", "illegal whole value exception");
+  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeDivException)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod")), 684, 9, const_cast<void*> (reinterpret_cast<const void*>("wholediv")), const_cast<void*> (reinterpret_cast<const void*>("illegal whole value exception")));
 }
 
 
@@ -789,7 +789,7 @@ static void wholediv (void * a)
 
 static void realvalue (void * a)
 {
-  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_realValueException)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 696, 9, "realvalue", "illegal real value exception");
+  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_realValueException)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod")), 696, 9, const_cast<void*> (reinterpret_cast<const void*>("realvalue")), const_cast<void*> (reinterpret_cast<const void*>("illegal real value exception")));
 }
 
 
@@ -799,7 +799,7 @@ static void realvalue (void * a)
 
 static void realdiv (void * a)
 {
-  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_realDivException)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 708, 9, "realdiv", "real number division by zero exception");
+  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_realDivException)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod")), 708, 9, const_cast<void*> (reinterpret_cast<const void*>("realdiv")), const_cast<void*> (reinterpret_cast<const void*>("real number division by zero exception")));
 }
 
 
@@ -809,7 +809,7 @@ static void realdiv (void * a)
 
 static void complexvalue (void * a)
 {
-  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_complexValueException)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 720, 9, "complexvalue", "illegal complex value exception");
+  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_complexValueException)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod")), 720, 9, const_cast<void*> (reinterpret_cast<const void*>("complexvalue")), const_cast<void*> (reinterpret_cast<const void*>("illegal complex value exception")));
 }
 
 
@@ -819,7 +819,7 @@ static void complexvalue (void * a)
 
 static void complexdiv (void * a)
 {
-  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_complexDivException)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 732, 9, "complexdiv", "complex number division by zero exception");
+  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_complexDivException)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod")), 732, 9, const_cast<void*> (reinterpret_cast<const void*>("complexdiv")), const_cast<void*> (reinterpret_cast<const void*>("complex number division by zero exception")));
 }
 
 
@@ -829,7 +829,7 @@ static void complexdiv (void * a)
 
 static void protection (void * a)
 {
-  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_protException)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 744, 9, "protection", "protection exception");
+  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_protException)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod")), 744, 9, const_cast<void*> (reinterpret_cast<const void*>("protection")), const_cast<void*> (reinterpret_cast<const void*>("protection exception")));
 }
 
 
@@ -839,7 +839,7 @@ static void protection (void * a)
 
 static void systemf (void * a)
 {
-  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_sysException)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 756, 9, "systemf", "system exception");
+  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_sysException)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod")), 756, 9, const_cast<void*> (reinterpret_cast<const void*>("systemf")), const_cast<void*> (reinterpret_cast<const void*>("system exception")));
 }
 
 
@@ -849,7 +849,7 @@ static void systemf (void * a)
 
 static void coroutine (void * a)
 {
-  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_coException)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 768, 9, "coroutine", "coroutine exception");
+  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_coException)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod")), 768, 9, const_cast<void*> (reinterpret_cast<const void*>("coroutine")), const_cast<void*> (reinterpret_cast<const void*>("coroutine exception")));
 }
 
 
@@ -859,7 +859,7 @@ static void coroutine (void * a)
 
 static void exception (void * a)
 {
-  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_exException)), "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 780, 9, "exception", "exception exception");
+  RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_exException)), const_cast<void*> (reinterpret_cast<const void*>("/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod")), 780, 9, const_cast<void*> (reinterpret_cast<const void*>("exception")), const_cast<void*> (reinterpret_cast<const void*>("exception exception")));
 }
 
 
@@ -870,9 +870,9 @@ static void exception (void * a)
 static void Init (void)
 {
   inException = FALSE;
-  freeHandler = NULL;
-  freeEHB = NULL;
-  currentEHB = RTExceptions_InitExceptionBlock ();
+  freeHandler = static_cast<Handler> (NULL);
+  freeEHB = static_cast<RTExceptions_EHBlock> (NULL);
+  currentEHB = static_cast<RTExceptions_EHBlock> (RTExceptions_InitExceptionBlock ());
   currentSource = NULL;
   RTExceptions_BaseExceptionsThrow ();
   SysExceptions_InitExceptionHandlers ((SysExceptions_PROCEXCEPTION) {(SysExceptions_PROCEXCEPTION_t) indexf}, (SysExceptions_PROCEXCEPTION) {(SysExceptions_PROCEXCEPTION_t) range}, (SysExceptions_PROCEXCEPTION) {(SysExceptions_PROCEXCEPTION_t) casef}, (SysExceptions_PROCEXCEPTION) {(SysExceptions_PROCEXCEPTION_t) invalidloc}, (SysExceptions_PROCEXCEPTION) {(SysExceptions_PROCEXCEPTION_t) function}, (SysExceptions_PROCEXCEPTION) {(SysExceptions_PROCEXCEPTION_t) wholevalue}, (SysExceptions_PROCEXCEPTION) {(SysExceptions_PROCEXCEPTION_t) wholediv}, (SysExceptions_PROCEXCEPTION) {(SysExceptions_PROCEXCEPTION_t) realvalue}, (SysExceptions_PROCEXCEPTION) {(SysExceptions_PROCEXCEPTION_t) realdiv}, (SysExceptions_PROCEXCEPTION) {(SysExceptions_PROCEXCEPTION_t) complexvalue}, (SysExceptions_PROCEXCEPTION) {(SysExceptions_PROCEXCEPTION_t) complexdiv}, (SysExceptions_PROCEXCEPTION) {(SysExceptions_PROCEXCEPTION_t) protection}, (SysExceptions_PROCEXCEPTION) {(SysExceptions_PROCEXCEPTION_t) systemf}, (SysExceptions_PROCEXCEPTION) {(SysExceptions_PROCEXCEPTION_t) coroutine}, (SysExceptions_PROCEXCEPTION) {(SysExceptions_PROCEXCEPTION_t) exception});
@@ -890,7 +890,7 @@ static void TidyUp (void)
 
   if (currentEHB != NULL)
     {
-      currentEHB = RTExceptions_KillExceptionBlock (currentEHB);
+      currentEHB = static_cast<RTExceptions_EHBlock> (RTExceptions_KillExceptionBlock (currentEHB));
     }
   while (freeHandler != NULL)
     {
@@ -913,12 +913,12 @@ static void TidyUp (void)
            and message in the EHBlock for later use.
 */
 
-void RTExceptions_Raise (unsigned int number, void * file, unsigned int line, unsigned int column, void * function, void * message)
+extern "C" void RTExceptions_Raise (unsigned int number, void * file, unsigned int line, unsigned int column, void * function, void * message)
 {
   unsigned int i;
 
   currentEHB->number = number;
-  i = 0;
+  i = static_cast<unsigned int> (0);
   addFile (file, &i);
   addChar (':', &i);
   addNum (line, &i);
@@ -948,7 +948,7 @@ void RTExceptions_Raise (unsigned int number, void * file, unsigned int line, un
    SetExceptionBlock - sets, source, as the active EHB.
 */
 
-void RTExceptions_SetExceptionBlock (RTExceptions_EHBlock source)
+extern "C" void RTExceptions_SetExceptionBlock (RTExceptions_EHBlock source)
 {
   currentEHB = source;
 }
@@ -958,7 +958,7 @@ void RTExceptions_SetExceptionBlock (RTExceptions_EHBlock source)
    GetExceptionBlock - returns the active EHB.
 */
 
-RTExceptions_EHBlock RTExceptions_GetExceptionBlock (void)
+extern "C" RTExceptions_EHBlock RTExceptions_GetExceptionBlock (void)
 {
   return currentEHB;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -970,7 +970,7 @@ RTExceptions_EHBlock RTExceptions_GetExceptionBlock (void)
    GetTextBuffer - returns the address of the EHB buffer.
 */
 
-void * RTExceptions_GetTextBuffer (RTExceptions_EHBlock e)
+extern "C" void * RTExceptions_GetTextBuffer (RTExceptions_EHBlock e)
 {
   return &e->buffer;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -982,7 +982,7 @@ void * RTExceptions_GetTextBuffer (RTExceptions_EHBlock e)
    GetTextBufferSize - return the size of the EHB text buffer.
 */
 
-unsigned int RTExceptions_GetTextBufferSize (RTExceptions_EHBlock e)
+extern "C" unsigned int RTExceptions_GetTextBufferSize (RTExceptions_EHBlock e)
 {
   return sizeof (e->buffer);
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -995,7 +995,7 @@ unsigned int RTExceptions_GetTextBufferSize (RTExceptions_EHBlock e)
                source.
 */
 
-unsigned int RTExceptions_GetNumber (RTExceptions_EHBlock source)
+extern "C" unsigned int RTExceptions_GetNumber (RTExceptions_EHBlock source)
 {
   return source->number;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -1007,13 +1007,13 @@ unsigned int RTExceptions_GetNumber (RTExceptions_EHBlock source)
    InitExceptionBlock - creates and returns a new exception block.
 */
 
-RTExceptions_EHBlock RTExceptions_InitExceptionBlock (void)
+extern "C" RTExceptions_EHBlock RTExceptions_InitExceptionBlock (void)
 {
   RTExceptions_EHBlock e;
 
-  e = New ();
-  e->number = UINT_MAX;
-  e->handlers = NewHandler ();  /* add the dummy onto the head  */
+  e = static_cast<RTExceptions_EHBlock> (New ());
+  e->number = static_cast<unsigned int> (UINT_MAX);
+  e->handlers = static_cast<Handler> (NewHandler ());  /* add the dummy onto the head  */
   e->handlers->right = e->handlers;  /* add the dummy onto the head  */
   e->handlers->left = e->handlers;
   e->right = e;
@@ -1027,12 +1027,12 @@ RTExceptions_EHBlock RTExceptions_InitExceptionBlock (void)
    KillExceptionBlock - destroys the EHB, e, and all its handlers.
 */
 
-RTExceptions_EHBlock RTExceptions_KillExceptionBlock (RTExceptions_EHBlock e)
+extern "C" RTExceptions_EHBlock RTExceptions_KillExceptionBlock (RTExceptions_EHBlock e)
 {
-  e->handlers = KillHandlers (e->handlers);
+  e->handlers = static_cast<Handler> (KillHandlers (e->handlers));
   e->right = freeEHB;
   freeEHB = e;
-  return NULL;
+  return static_cast<RTExceptions_EHBlock> (NULL);
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -1042,22 +1042,22 @@ RTExceptions_EHBlock RTExceptions_KillExceptionBlock (RTExceptions_EHBlock e)
    PushHandler - install a handler in EHB, e.
 */
 
-void RTExceptions_PushHandler (RTExceptions_EHBlock e, unsigned int number, RTExceptions_ProcedureHandler p)
+extern "C" void RTExceptions_PushHandler (RTExceptions_EHBlock e, unsigned int number, RTExceptions_ProcedureHandler p)
 {
   Handler h;
   Handler i;
 
-  h = findHandler (e, number);
+  h = static_cast<Handler> (findHandler (e, number));
   if (h == NULL)
     {
-      i = InitHandler (NewHandler (), (Handler) NULL, (Handler) NULL, (Handler) NULL, number, p);
+      i = static_cast<Handler> (InitHandler (NewHandler (), reinterpret_cast<Handler> (NULL), reinterpret_cast<Handler> (NULL), reinterpret_cast<Handler> (NULL), number, p));
     }
   else
     {
       /* remove, h,  */
       SubHandler (h);
       /* stack it onto a new handler  */
-      i = InitHandler (NewHandler (), (Handler) NULL, (Handler) NULL, h, number, p);
+      i = static_cast<Handler> (InitHandler (NewHandler (), reinterpret_cast<Handler> (NULL), reinterpret_cast<Handler> (NULL), h, number, p));
     }
   /* add new handler  */
   AddHandler (e, i);
@@ -1069,12 +1069,12 @@ void RTExceptions_PushHandler (RTExceptions_EHBlock e, unsigned int number, RTEx
                 EHB, e.
 */
 
-void RTExceptions_PopHandler (RTExceptions_EHBlock e, unsigned int number)
+extern "C" void RTExceptions_PopHandler (RTExceptions_EHBlock e, unsigned int number)
 {
   Handler h;
   Handler i;
 
-  h = findHandler (e, number);
+  h = static_cast<Handler> (findHandler (e, number));
   if (h != NULL)
     {
       /* remove, h,  */
@@ -1083,7 +1083,7 @@ void RTExceptions_PopHandler (RTExceptions_EHBlock e, unsigned int number)
         {
           AddHandler (e, h->stack);
         }
-      h = KillHandler (h);
+      h = static_cast<Handler> (KillHandler (h));
     }
 }
 
@@ -1094,13 +1094,13 @@ void RTExceptions_PopHandler (RTExceptions_EHBlock e, unsigned int number)
                        calls HALT.
 */
 
-void RTExceptions_DefaultErrorCatch (void)
+extern "C" void RTExceptions_DefaultErrorCatch (void)
 {
   RTExceptions_EHBlock e;
   int n;
 
-  e = RTExceptions_GetExceptionBlock ();
-  n = libc_write (2, RTExceptions_GetTextBuffer (e), libc_strlen (RTExceptions_GetTextBuffer (e)));
+  e = static_cast<RTExceptions_EHBlock> (RTExceptions_GetExceptionBlock ());
+  n = static_cast<int> (libc_write (2, RTExceptions_GetTextBuffer (e), libc_strlen (RTExceptions_GetTextBuffer (e))));
   M2RTS_HALT (-1);
   __builtin_unreachable ();
 }
@@ -1114,11 +1114,11 @@ void RTExceptions_DefaultErrorCatch (void)
                          error message routine and then HALT.
 */
 
-void RTExceptions_BaseExceptionsThrow (void)
+extern "C" void RTExceptions_BaseExceptionsThrow (void)
 {
   M2EXCEPTION_M2Exceptions i;
 
-  for (i=M2EXCEPTION_indexException; i<=M2EXCEPTION_exException; i++)
+  for (i=M2EXCEPTION_indexException; i<=M2EXCEPTION_exException; i= static_cast<M2EXCEPTION_M2Exceptions>(static_cast<int>(i+1)))
     {
       RTExceptions_PushHandler (RTExceptions_GetExceptionBlock (), (unsigned int ) (i), (RTExceptions_ProcedureHandler) {(RTExceptions_ProcedureHandler_t) DoThrow});
     }
@@ -1130,7 +1130,7 @@ void RTExceptions_BaseExceptionsThrow (void)
                         in the exception state.
 */
 
-unsigned int RTExceptions_IsInExceptionState (void)
+extern "C" unsigned int RTExceptions_IsInExceptionState (void)
 {
   return inException;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -1144,7 +1144,7 @@ unsigned int RTExceptions_IsInExceptionState (void)
                        to.
 */
 
-unsigned int RTExceptions_SetExceptionState (unsigned int to)
+extern "C" unsigned int RTExceptions_SetExceptionState (unsigned int to)
 {
   unsigned int old;
 
@@ -1162,7 +1162,7 @@ unsigned int RTExceptions_SetExceptionState (unsigned int to)
                           to, to.
 */
 
-void RTExceptions_SwitchExceptionState (unsigned int *from, unsigned int to)
+extern "C" void RTExceptions_SwitchExceptionState (unsigned int *from, unsigned int to)
 {
   (*from) = inException;
   inException = to;
@@ -1174,11 +1174,11 @@ void RTExceptions_SwitchExceptionState (unsigned int *from, unsigned int to)
                            created.
 */
 
-RTExceptions_EHBlock RTExceptions_GetBaseExceptionBlock (void)
+extern "C" RTExceptions_EHBlock RTExceptions_GetBaseExceptionBlock (void)
 {
   if (currentEHB == NULL)
     {
-      M2RTS_Halt ((char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 84, 598, (char *) "GetBaseExceptionBlock", 21, (char *) "currentEHB has not been initialized yet", 39);
+      M2RTS_Halt ((const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTExceptions.mod", 84, 598, (const char *) "GetBaseExceptionBlock", 21, (const char *) "currentEHB has not been initialized yet", 39);
     }
   else
     {
@@ -1193,7 +1193,7 @@ RTExceptions_EHBlock RTExceptions_GetBaseExceptionBlock (void)
    SetExceptionSource - sets the current exception source to, source.
 */
 
-void RTExceptions_SetExceptionSource (void * source)
+extern "C" void RTExceptions_SetExceptionSource (void * source)
 {
   currentSource = source;
 }
@@ -1203,19 +1203,19 @@ void RTExceptions_SetExceptionSource (void * source)
    GetExceptionSource - returns the current exception source.
 */
 
-void * RTExceptions_GetExceptionSource (void)
+extern "C" void * RTExceptions_GetExceptionSource (void)
 {
   return currentSource;
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
 
-void _M2_RTExceptions_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_RTExceptions_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
   Init ();
 }
 
-void _M2_RTExceptions_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_RTExceptions_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
   TidyUp ();
 }
diff --git a/gcc/m2/mc-boot/GRTExceptions.h b/gcc/m2/mc-boot/GRTExceptions.h
index ce026f99068..6a00a981b90 100644
--- a/gcc/m2/mc-boot/GRTExceptions.h
+++ b/gcc/m2/mc-boot/GRTExceptions.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_RTExceptions_H)
 #   define _RTExceptions_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GRTco.h b/gcc/m2/mc-boot/GRTco.h
index e8266f57224..858d48a4431 100644
--- a/gcc/m2/mc-boot/GRTco.h
+++ b/gcc/m2/mc-boot/GRTco.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_RTco_H)
 #   define _RTco_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GRTint.c b/gcc/m2/mc-boot/GRTint.c
index 5533d5f0e13..82b08392ce8 100644
--- a/gcc/m2/mc-boot/GRTint.c
+++ b/gcc/m2/mc-boot/GRTint.c
@@ -99,28 +99,28 @@ static unsigned int initialized;
                      with the file descriptor, fd.
 */
 
-unsigned int RTint_InitInputVector (int fd, unsigned int pri);
+extern "C" unsigned int RTint_InitInputVector (int fd, unsigned int pri);
 
 /*
    InitOutputVector - returns an interrupt vector which is associated
                       with the file descriptor, fd.
 */
 
-unsigned int RTint_InitOutputVector (int fd, unsigned int pri);
+extern "C" unsigned int RTint_InitOutputVector (int fd, unsigned int pri);
 
 /*
    InitTimeVector - returns an interrupt vector associated with
                     the relative time.
 */
 
-unsigned int RTint_InitTimeVector (unsigned int micro, unsigned int secs, unsigned int pri);
+extern "C" unsigned int RTint_InitTimeVector (unsigned int micro, unsigned int secs, unsigned int pri);
 
 /*
    ReArmTimeVector - reprimes the vector, vec, to deliver an interrupt
                      at the new relative time.
 */
 
-void RTint_ReArmTimeVector (unsigned int vec, unsigned int micro, unsigned int secs);
+extern "C" void RTint_ReArmTimeVector (unsigned int vec, unsigned int micro, unsigned int secs);
 
 /*
    GetTimeVector - assigns, micro, and, secs, with the remaining
@@ -129,7 +129,7 @@ void RTint_ReArmTimeVector (unsigned int vec, unsigned int micro, unsigned int s
                    occurs.
 */
 
-void RTint_GetTimeVector (unsigned int vec, unsigned int *micro, unsigned int *secs);
+extern "C" void RTint_GetTimeVector (unsigned int vec, unsigned int *micro, unsigned int *secs);
 
 /*
    AttachVector - adds the pointer, p, to be associated with the interrupt
@@ -137,21 +137,21 @@ void RTint_GetTimeVector (unsigned int vec, unsigned int *micro, unsigned int *s
                   vector.
 */
 
-void * RTint_AttachVector (unsigned int vec, void * p);
+extern "C" void * RTint_AttachVector (unsigned int vec, void * p);
 
 /*
    IncludeVector - includes, vec, into the dispatcher list of
                    possible interrupt causes.
 */
 
-void RTint_IncludeVector (unsigned int vec);
+extern "C" void RTint_IncludeVector (unsigned int vec);
 
 /*
    ExcludeVector - excludes, vec, from the dispatcher list of
                    possible interrupt causes.
 */
 
-void RTint_ExcludeVector (unsigned int vec);
+extern "C" void RTint_ExcludeVector (unsigned int vec);
 
 /*
    Listen - will either block indefinitely (until an interrupt)
@@ -162,13 +162,13 @@ void RTint_ExcludeVector (unsigned int vec);
             It only listens for interrupts > pri.
 */
 
-void RTint_Listen (unsigned int untilInterrupt, RTint_DispatchVector call, unsigned int pri);
+extern "C" void RTint_Listen (unsigned int untilInterrupt, RTint_DispatchVector call, unsigned int pri);
 
 /*
    Init -
 */
 
-void RTint_Init (void);
+extern "C" void RTint_Init (void);
 
 /*
    Max - returns the maximum: i or j.
@@ -299,7 +299,7 @@ static Vector FindVector (int fd, VectorType t)
         }
       v = v->exists;
     }
-  return NULL;
+  return static_cast<Vector> (NULL);
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -345,7 +345,7 @@ static Vector FindPendingVector (unsigned int vec)
           return v;
         }
     }
-  return NULL;
+  return static_cast<Vector> (NULL);
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -357,10 +357,10 @@ static Vector FindPendingVector (unsigned int vec)
 
 static void AddFd (Selective_SetOfFd *s, int *max, int fd)
 {
-  (*max) = Max (fd, (*max));
+  (*max) = static_cast<int> (Max (fd, (*max)));
   if ((*s) == NULL)
     {
-      (*s) = Selective_InitSet ();
+      (*s) = static_cast<Selective_SetOfFd> (Selective_InitSet ());
       Selective_FdZero ((*s));
     }
   /* printf('%d, ', fd)  */
@@ -379,27 +379,27 @@ static void DumpPendingQueue (void)
   unsigned int s;
   unsigned int m;
 
-  libc_printf ((char *) "Pending queue\\n", 15);
+  libc_printf ((const char *) "Pending queue\\n", 15);
   for (p=COROUTINES_UnassignedPriority; p<=7; p++)
     {
-      libc_printf ((char *) "[%d]  ", 6, p);
+      libc_printf ((const char *) "[%d]  ", 6, p);
       v = Pending.array[p-(COROUTINES_UnassignedPriority)];
       while (v != NULL)
         {
           if ((v->type == input) || (v->type == output))
             {
-              libc_printf ((char *) "(fd=%d) (vec=%d)", 16, v->File, v->no);
+              libc_printf ((const char *) "(fd=%d) (vec=%d)", 16, v->File, v->no);
             }
           else if (v->type == time_)
             {
               /* avoid dangling else.  */
               Selective_GetTime (v->rel, &s, &m);
               Assertion_Assert (m < Microseconds);
-              libc_printf ((char *) "time (%u.%06u secs) (arg = 0x%x)\\n", 34, s, m, v->arg);
+              libc_printf ((const char *) "time (%u.%06u secs) (arg = 0x%x)\\n", 34, s, m, v->arg);
             }
           v = v->pending;
         }
-      libc_printf ((char *) " \\n", 3);
+      libc_printf ((const char *) " \\n", 3);
     }
 }
 
@@ -477,24 +477,24 @@ static void SubTime (unsigned int *s, unsigned int *m, Selective_Timeval a, Sele
   Assertion_Assert (bm < Microseconds);
   if (IsGreaterEqual (a, b))
     {
-      (*s) = as-bs;
+      (*s) = static_cast<unsigned int> (as-bs);
       if (am >= bm)
         {
-          (*m) = am-bm;
+          (*m) = static_cast<unsigned int> (am-bm);
           Assertion_Assert ((*m) < Microseconds);
         }
       else
         {
           Assertion_Assert ((*s) > 0);
           (*s) -= 1;
-          (*m) = (Microseconds+am)-bm;
+          (*m) = static_cast<unsigned int> ((Microseconds+am)-bm);
           Assertion_Assert ((*m) < Microseconds);
         }
     }
   else
     {
-      (*s) = 0;
-      (*m) = 0;
+      (*s) = static_cast<unsigned int> (0);
+      (*m) = static_cast<unsigned int> (0);
     }
 }
 
@@ -516,7 +516,7 @@ static unsigned int activatePending (unsigned int untilInterrupt, RTint_Dispatch
   unsigned int m;
 
   RTco_wait (lock);
-  p = 7;
+  p = static_cast<unsigned int> (7);
   while (p > pri)
     {
       v = Pending.array[p-(COROUTINES_UnassignedPriority)];
@@ -529,7 +529,7 @@ static unsigned int activatePending (unsigned int untilInterrupt, RTint_Dispatch
                   {
                     if (Debugging)
                       {
-                        libc_printf ((char *) "read (fd=%d) is ready (vec=%d)\\n", 32, v->File, v->no);
+                        libc_printf ((const char *) "read (fd=%d) is ready (vec=%d)\\n", 32, v->File, v->no);
                         DumpPendingQueue ();
                       }
                     Selective_FdClr (v->File, (*i));  /* so we dont activate this again from our select.  */
@@ -544,7 +544,7 @@ static unsigned int activatePending (unsigned int untilInterrupt, RTint_Dispatch
                   {
                     if (Debugging)
                       {
-                        libc_printf ((char *) "write (fd=%d) is ready (vec=%d)\\n", 33, v->File, v->no);
+                        libc_printf ((const char *) "write (fd=%d) is ready (vec=%d)\\n", 33, v->File, v->no);
                         DumpPendingQueue ();
                       }
                     Selective_FdClr (v->File, (*o));  /* so we dont activate this again from our select.  */
@@ -557,7 +557,7 @@ static unsigned int activatePending (unsigned int untilInterrupt, RTint_Dispatch
               case time_:
                 if (untilInterrupt && ((*t) != NULL))
                   {
-                    r = Selective_GetTimeOfDay (after);
+                    r = static_cast<int> (Selective_GetTimeOfDay (after));
                     Assertion_Assert (r == 0);
                     if (Debugging)
                       {
@@ -567,20 +567,20 @@ static unsigned int activatePending (unsigned int untilInterrupt, RTint_Dispatch
                         Assertion_Assert (afm < Microseconds);
                         Selective_GetTime (b4, &b4s, &b4m);
                         Assertion_Assert (b4m < Microseconds);
-                        libc_printf ((char *) "waited %u.%06u + %u.%06u now is %u.%06u\\n", 41, s, m, b4s, b4m, afs, afm);
+                        libc_printf ((const char *) "waited %u.%06u + %u.%06u now is %u.%06u\\n", 41, s, m, b4s, b4m, afs, afm);
                       }
                     if (IsGreaterEqual (after, v->abs_))
                       {
                         if (Debugging)
                           {
                             DumpPendingQueue ();
-                            libc_printf ((char *) "time has expired calling dispatcher\\n", 37);
+                            libc_printf ((const char *) "time has expired calling dispatcher\\n", 37);
                           }
-                        (*t) = Selective_KillTime ((*t));  /* so we dont activate this again from our select.  */
+                        (*t) = static_cast<Selective_Timeval> (Selective_KillTime ((*t)));  /* so we dont activate this again from our select.  */
                         RTco_signal (lock);  /* so we dont activate this again from our select.  */
                         if (Debugging)
                           {
-                            libc_printf ((char *) "call (%d, %d, 0x%x)\\n", 21, v->no, v->priority, v->arg);
+                            libc_printf ((const char *) "call (%d, %d, 0x%x)\\n", 21, v->no, v->priority, v->arg);
                           }
                         (*call.proc) (v->no, v->priority, v->arg);
                         return TRUE;
@@ -588,7 +588,7 @@ static unsigned int activatePending (unsigned int untilInterrupt, RTint_Dispatch
                     else if (Debugging)
                       {
                         /* avoid dangling else.  */
-                        libc_printf ((char *) "must wait longer as time has not expired\\n", 42);
+                        libc_printf ((const char *) "must wait longer as time has not expired\\n", 42);
                       }
                   }
                 break;
@@ -617,12 +617,12 @@ static void init (void)
 {
   COROUTINES_PROTECTION p;
 
-  lock = RTco_initSemaphore (1);
+  lock = static_cast<int> (RTco_initSemaphore (1));
   RTco_wait (lock);
-  Exists = NULL;
+  Exists = static_cast<Vector> (NULL);
   for (p=COROUTINES_UnassignedPriority; p<=7; p++)
     {
-      Pending.array[p-(COROUTINES_UnassignedPriority)] = NULL;
+      Pending.array[p-(COROUTINES_UnassignedPriority)] = reinterpret_cast<_T1 *> (NULL);
     }
   initialized = TRUE;
   RTco_signal (lock);
@@ -634,16 +634,16 @@ static void init (void)
                      with the file descriptor, fd.
 */
 
-unsigned int RTint_InitInputVector (int fd, unsigned int pri)
+extern "C" unsigned int RTint_InitInputVector (int fd, unsigned int pri)
 {
   Vector v;
 
   if (Debugging)
     {
-      libc_printf ((char *) "InitInputVector fd = %d priority = %d\\n", 39, fd, pri);
+      libc_printf ((const char *) "InitInputVector fd = %d priority = %d\\n", 39, fd, pri);
     }
   RTco_wait (lock);
-  v = FindVector (fd, (VectorType) input);
+  v = static_cast<Vector> (FindVector (fd, static_cast<VectorType> (input)));
   if (v == NULL)
     {
       Storage_ALLOCATE ((void **) &v, sizeof (_T1));
@@ -651,7 +651,7 @@ unsigned int RTint_InitInputVector (int fd, unsigned int pri)
       v->type = input;
       v->priority = pri;
       v->arg = NULL;
-      v->pending = NULL;
+      v->pending = static_cast<Vector> (NULL);
       v->exists = Exists;
       v->no = VecNo;
       v->File = fd;
@@ -674,12 +674,12 @@ unsigned int RTint_InitInputVector (int fd, unsigned int pri)
                       with the file descriptor, fd.
 */
 
-unsigned int RTint_InitOutputVector (int fd, unsigned int pri)
+extern "C" unsigned int RTint_InitOutputVector (int fd, unsigned int pri)
 {
   Vector v;
 
   RTco_wait (lock);
-  v = FindVector (fd, (VectorType) output);
+  v = static_cast<Vector> (FindVector (fd, static_cast<VectorType> (output)));
   if (v == NULL)
     {
       Storage_ALLOCATE ((void **) &v, sizeof (_T1));
@@ -694,7 +694,7 @@ unsigned int RTint_InitOutputVector (int fd, unsigned int pri)
           v->type = output;
           v->priority = pri;
           v->arg = NULL;
-          v->pending = NULL;
+          v->pending = static_cast<Vector> (NULL);
           v->exists = Exists;
           v->no = VecNo;
           v->File = fd;
@@ -718,7 +718,7 @@ unsigned int RTint_InitOutputVector (int fd, unsigned int pri)
                     the relative time.
 */
 
-unsigned int RTint_InitTimeVector (unsigned int micro, unsigned int secs, unsigned int pri)
+extern "C" unsigned int RTint_InitTimeVector (unsigned int micro, unsigned int secs, unsigned int pri)
 {
   Vector v;
 
@@ -736,11 +736,11 @@ unsigned int RTint_InitTimeVector (unsigned int micro, unsigned int secs, unsign
       v->type = time_;
       v->priority = pri;
       v->arg = NULL;
-      v->pending = NULL;
+      v->pending = static_cast<Vector> (NULL);
       v->exists = Exists;
       v->no = VecNo;
-      v->rel = Selective_InitTime (secs+DebugTime, micro);
-      v->abs_ = Selective_InitTime (0, 0);
+      v->rel = static_cast<Selective_Timeval> (Selective_InitTime (secs+DebugTime, micro));
+      v->abs_ = static_cast<Selective_Timeval> (Selective_InitTime (0, 0));
       v->queued = FALSE;
       Exists = v;
     }
@@ -756,16 +756,16 @@ unsigned int RTint_InitTimeVector (unsigned int micro, unsigned int secs, unsign
                      at the new relative time.
 */
 
-void RTint_ReArmTimeVector (unsigned int vec, unsigned int micro, unsigned int secs)
+extern "C" void RTint_ReArmTimeVector (unsigned int vec, unsigned int micro, unsigned int secs)
 {
   Vector v;
 
   Assertion_Assert (micro < Microseconds);
   RTco_wait (lock);
-  v = FindVectorNo (vec);
+  v = static_cast<Vector> (FindVectorNo (vec));
   if (v == NULL)
     {
-      M2RTS_Halt ((char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTint.mod", 77, 286, (char *) "ReArmTimeVector", 15, (char *) "cannot find vector supplied", 27);
+      M2RTS_Halt ((const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTint.mod", 77, 286, (const char *) "ReArmTimeVector", 15, (const char *) "cannot find vector supplied", 27);
     }
   else
     {
@@ -782,15 +782,15 @@ void RTint_ReArmTimeVector (unsigned int vec, unsigned int micro, unsigned int s
                    occurs.
 */
 
-void RTint_GetTimeVector (unsigned int vec, unsigned int *micro, unsigned int *secs)
+extern "C" void RTint_GetTimeVector (unsigned int vec, unsigned int *micro, unsigned int *secs)
 {
   Vector v;
 
   RTco_wait (lock);
-  v = FindVectorNo (vec);
+  v = static_cast<Vector> (FindVectorNo (vec));
   if (v == NULL)
     {
-      M2RTS_Halt ((char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTint.mod", 77, 312, (char *) "GetTimeVector", 13, (char *) "cannot find vector supplied", 27);
+      M2RTS_Halt ((const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTint.mod", 77, 312, (const char *) "GetTimeVector", 13, (const char *) "cannot find vector supplied", 27);
     }
   else
     {
@@ -807,16 +807,16 @@ void RTint_GetTimeVector (unsigned int vec, unsigned int *micro, unsigned int *s
                   vector.
 */
 
-void * RTint_AttachVector (unsigned int vec, void * p)
+extern "C" void * RTint_AttachVector (unsigned int vec, void * p)
 {
   Vector v;
   void * l;
 
   RTco_wait (lock);
-  v = FindVectorNo (vec);
+  v = static_cast<Vector> (FindVectorNo (vec));
   if (v == NULL)
     {
-      M2RTS_Halt ((char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTint.mod", 77, 339, (char *) "AttachVector", 12, (char *) "cannot find vector supplied", 27);
+      M2RTS_Halt ((const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTint.mod", 77, 339, (const char *) "AttachVector", 12, (const char *) "cannot find vector supplied", 27);
     }
   else
     {
@@ -824,7 +824,7 @@ void * RTint_AttachVector (unsigned int vec, void * p)
       v->arg = p;
       if (Debugging)
         {
-          libc_printf ((char *) "AttachVector %d with 0x%x\\n", 27, vec, p);
+          libc_printf ((const char *) "AttachVector %d with 0x%x\\n", 27, vec, p);
           DumpPendingQueue ();
         }
       RTco_signal (lock);
@@ -840,7 +840,7 @@ void * RTint_AttachVector (unsigned int vec, void * p)
                    possible interrupt causes.
 */
 
-void RTint_IncludeVector (unsigned int vec)
+extern "C" void RTint_IncludeVector (unsigned int vec)
 {
   Vector v;
   unsigned int m;
@@ -848,14 +848,14 @@ void RTint_IncludeVector (unsigned int vec)
   int r;
 
   RTco_wait (lock);
-  v = FindPendingVector (vec);
+  v = static_cast<Vector> (FindPendingVector (vec));
   if (v == NULL)
     {
       /* avoid dangling else.  */
-      v = FindVectorNo (vec);
+      v = static_cast<Vector> (FindVectorNo (vec));
       if (v == NULL)
         {
-          M2RTS_Halt ((char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTint.mod", 77, 372, (char *) "IncludeVector", 13, (char *) "cannot find vector supplied", 27);
+          M2RTS_Halt ((const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTint.mod", 77, 372, (const char *) "IncludeVector", 13, (const char *) "cannot find vector supplied", 27);
         }
       else
         {
@@ -866,7 +866,7 @@ void RTint_IncludeVector (unsigned int vec)
           if ((v->type == time_) && ! v->queued)
             {
               v->queued = TRUE;
-              r = Selective_GetTimeOfDay (v->abs_);
+              r = static_cast<int> (Selective_GetTimeOfDay (v->abs_));
               Assertion_Assert (r == 0);
               Selective_GetTime (v->abs_, &s, &m);
               Assertion_Assert (m < Microseconds);
@@ -880,7 +880,7 @@ void RTint_IncludeVector (unsigned int vec)
     {
       if (Debugging)
         {
-          libc_printf ((char *) "odd vector (%d) type (%d) arg (0x%x) is already attached to the pending queue\\n", 79, vec, v->type, v->arg);
+          libc_printf ((const char *) "odd vector (%d) type (%d) arg (0x%x) is already attached to the pending queue\\n", 79, vec, v->type, v->arg);
         }
       stop ();
     }
@@ -893,16 +893,16 @@ void RTint_IncludeVector (unsigned int vec)
                    possible interrupt causes.
 */
 
-void RTint_ExcludeVector (unsigned int vec)
+extern "C" void RTint_ExcludeVector (unsigned int vec)
 {
   Vector v;
   Vector u;
 
   RTco_wait (lock);
-  v = FindPendingVector (vec);
+  v = static_cast<Vector> (FindPendingVector (vec));
   if (v == NULL)
     {
-      M2RTS_Halt ((char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTint.mod", 77, 415, (char *) "ExcludeVector", 13, (char *) "cannot find pending vector supplied", 35);
+      M2RTS_Halt ((const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTint.mod", 77, 415, (const char *) "ExcludeVector", 13, (const char *) "cannot find pending vector supplied", 35);
     }
   else
     {
@@ -939,7 +939,7 @@ void RTint_ExcludeVector (unsigned int vec)
             It only listens for interrupts > pri.
 */
 
-void RTint_Listen (unsigned int untilInterrupt, RTint_DispatchVector call, unsigned int pri)
+extern "C" void RTint_Listen (unsigned int untilInterrupt, RTint_DispatchVector call, unsigned int pri)
 {
   unsigned int found;
   int r;
@@ -965,12 +965,12 @@ void RTint_Listen (unsigned int untilInterrupt, RTint_DispatchVector call, unsig
         {
           DumpPendingQueue ();
         }
-      maxFd = -1;
+      maxFd = static_cast<int> (-1);
       t = NULL;
       i = NULL;
       o = NULL;
-      t = Selective_InitTime ((unsigned int) INT_MAX, 0);
-      p = 7;
+      t = static_cast<Selective_Timeval> (Selective_InitTime (static_cast<unsigned int> (INT_MAX), 0));
+      p = static_cast<unsigned int> (7);
       found = FALSE;
       while (p > pri)
         {
@@ -994,7 +994,7 @@ void RTint_Listen (unsigned int untilInterrupt, RTint_DispatchVector call, unsig
                         Assertion_Assert (m < Microseconds);
                         if (Debugging)
                           {
-                            libc_printf ((char *) "shortest delay is %u.%06u\\n", 27, s, m);
+                            libc_printf ((const char *) "shortest delay is %u.%06u\\n", 27, s, m);
                           }
                         Selective_SetTime (t, s, m);
                         found = TRUE;
@@ -1016,14 +1016,14 @@ void RTint_Listen (unsigned int untilInterrupt, RTint_DispatchVector call, unsig
         }
       if (((untilInterrupt && (i == NULL)) && (o == NULL)) && ! found)
         {
-          M2RTS_Halt ((char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTint.mod", 77, 731, (char *) "Listen", 6, (char *) "deadlock found, no more processes to run and no interrupts active", 65);
+          M2RTS_Halt ((const char *) "/home/gaius/GM2/graft-combine/gcc-git-devel-modula2/gcc/m2/gm2-libs/RTint.mod", 77, 731, (const char *) "Listen", 6, (const char *) "deadlock found, no more processes to run and no interrupts active", 65);
         }
       /* printf('}
       ') ;  */
       if (((! found && (maxFd == -1)) && (i == NULL)) && (o == NULL))
         {
           /* no file descriptors to be selected upon.  */
-          t = Selective_KillTime (t);
+          t = static_cast<Selective_Timeval> (Selective_KillTime (t));
           RTco_signal (lock);
           return;
         }
@@ -1031,44 +1031,44 @@ void RTint_Listen (unsigned int untilInterrupt, RTint_DispatchVector call, unsig
         {
           Selective_GetTime (t, &s, &m);
           Assertion_Assert (m < Microseconds);
-          b4 = Selective_InitTime (0, 0);
-          after = Selective_InitTime (0, 0);
-          r = Selective_GetTimeOfDay (b4);
+          b4 = static_cast<Selective_Timeval> (Selective_InitTime (0, 0));
+          after = static_cast<Selective_Timeval> (Selective_InitTime (0, 0));
+          r = static_cast<int> (Selective_GetTimeOfDay (b4));
           Assertion_Assert (r == 0);
           SubTime (&s, &m, t, b4);
           Selective_SetTime (t, s, m);
           if (Debugging)
             {
-              libc_printf ((char *) "select waiting for %u.%06u seconds\\n", 36, s, m);
+              libc_printf ((const char *) "select waiting for %u.%06u seconds\\n", 36, s, m);
             }
           RTco_signal (lock);
           do {
             if (Debugging)
               {
-                libc_printf ((char *) "select (.., .., .., %u.%06u)\\n", 30, s, m);
+                libc_printf ((const char *) "select (.., .., .., %u.%06u)\\n", 30, s, m);
               }
-            r = RTco_select (maxFd+1, (void *) i, (void *) o, NULL, (void *) t);
+            r = static_cast<int> (RTco_select (maxFd+1, reinterpret_cast<void *> (i), reinterpret_cast<void *> (o), NULL, reinterpret_cast<void *> (t)));
             if (r == -1)
               {
-                libc_perror ((char *) "select", 6);
-                r = RTco_select (maxFd+1, (void *) i, (void *) o, NULL, NULL);
+                libc_perror ((const char *) "select", 6);
+                r = static_cast<int> (RTco_select (maxFd+1, reinterpret_cast<void *> (i), reinterpret_cast<void *> (o), NULL, NULL));
                 if (r == -1)
                   {
-                    libc_perror ((char *) "select timeout argument is faulty", 33);
+                    libc_perror ((const char *) "select timeout argument is faulty", 33);
                   }
-                r = RTco_select (maxFd+1, (void *) i, NULL, NULL, (void *) t);
+                r = static_cast<int> (RTco_select (maxFd+1, reinterpret_cast<void *> (i), NULL, NULL, reinterpret_cast<void *> (t)));
                 if (r == -1)
                   {
-                    libc_perror ((char *) "select output fd argument is faulty", 35);
+                    libc_perror ((const char *) "select output fd argument is faulty", 35);
                   }
-                r = RTco_select (maxFd+1, NULL, (void *) o, NULL, (void *) t);
+                r = static_cast<int> (RTco_select (maxFd+1, NULL, reinterpret_cast<void *> (o), NULL, reinterpret_cast<void *> (t)));
                 if (r == -1)
                   {
-                    libc_perror ((char *) "select input fd argument is faulty", 34);
+                    libc_perror ((const char *) "select input fd argument is faulty", 34);
                   }
                 else
                   {
-                    libc_perror ((char *) "select maxFD+1 argument is faulty", 33);
+                    libc_perror ((const char *) "select maxFD+1 argument is faulty", 33);
                   }
               }
           } while (! (r != -1));
@@ -1077,23 +1077,23 @@ void RTint_Listen (unsigned int untilInterrupt, RTint_DispatchVector call, unsig
         {}  /* empty.  */
       if (t != NULL)
         {
-          t = Selective_KillTime (t);
+          t = static_cast<Selective_Timeval> (Selective_KillTime (t));
         }
       if (after != NULL)
         {
-          t = Selective_KillTime (after);
+          t = static_cast<Selective_Timeval> (Selective_KillTime (after));
         }
       if (b4 != NULL)
         {
-          t = Selective_KillTime (b4);
+          t = static_cast<Selective_Timeval> (Selective_KillTime (b4));
         }
       if (i != NULL)
         {
-          i = Selective_KillSet (i);
+          i = static_cast<Selective_SetOfFd> (Selective_KillSet (i));
         }
       if (o != NULL)
         {
-          o = Selective_KillSet (o);
+          o = static_cast<Selective_SetOfFd> (Selective_KillSet (o));
         }
     }
   RTco_signal (lock);
@@ -1104,7 +1104,7 @@ void RTint_Listen (unsigned int untilInterrupt, RTint_DispatchVector call, unsig
    Init -
 */
 
-void RTint_Init (void)
+extern "C" void RTint_Init (void)
 {
   if (! initialized)
     {
@@ -1112,11 +1112,11 @@ void RTint_Init (void)
     }
 }
 
-void _M2_RTint_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_RTint_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
   RTint_Init ();
 }
 
-void _M2_RTint_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_RTint_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GRTint.h b/gcc/m2/mc-boot/GRTint.h
index 716e3017d90..7dcceaf2c5b 100644
--- a/gcc/m2/mc-boot/GRTint.h
+++ b/gcc/m2/mc-boot/GRTint.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_RTint_H)
 #   define _RTint_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GSArgs.c b/gcc/m2/mc-boot/GSArgs.c
index facba615ebf..1331651ffc0 100644
--- a/gcc/m2/mc-boot/GSArgs.c
+++ b/gcc/m2/mc-boot/GSArgs.c
@@ -64,14 +64,14 @@ typedef PtrToChar *PtrToPtrToChar;
             new string, otherwise s is set to NIL.
 */
 
-unsigned int SArgs_GetArg (DynamicStrings_String *s, unsigned int i);
+extern "C" unsigned int SArgs_GetArg (DynamicStrings_String *s, unsigned int i);
 
 /*
    Narg - returns the number of arguments available from
           command line.
 */
 
-unsigned int SArgs_Narg (void);
+extern "C" unsigned int SArgs_Narg (void);
 
 
 /*
@@ -81,20 +81,20 @@ unsigned int SArgs_Narg (void);
             new string, otherwise s is set to NIL.
 */
 
-unsigned int SArgs_GetArg (DynamicStrings_String *s, unsigned int i)
+extern "C" unsigned int SArgs_GetArg (DynamicStrings_String *s, unsigned int i)
 {
   PtrToPtrToChar ppc;
 
   if (i < UnixArgs_ArgC)
     {
       /* ppc := ADDRESS (VAL (PtrToPtrToChar, ArgV) + (i * CARDINAL (TSIZE(PtrToChar)))) ;  */
-      ppc = (void *) (((PtrToChar) (UnixArgs_ArgV))+(i*sizeof (PtrToChar)));
-      (*s) = DynamicStrings_InitStringCharStar ((void *) (*ppc));
+      ppc = static_cast<PtrToPtrToChar> ((void *) (((PtrToChar) (UnixArgs_ArgV))+(i*sizeof (PtrToChar))));
+      (*s) = static_cast<DynamicStrings_String> (DynamicStrings_InitStringCharStar (reinterpret_cast<void *> ((*ppc))));
       return TRUE;
     }
   else
     {
-      (*s) = NULL;
+      (*s) = static_cast<DynamicStrings_String> (NULL);
       return FALSE;
     }
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -107,17 +107,17 @@ unsigned int SArgs_GetArg (DynamicStrings_String *s, unsigned int i)
           command line.
 */
 
-unsigned int SArgs_Narg (void)
+extern "C" unsigned int SArgs_Narg (void)
 {
   return UnixArgs_ArgC;
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
 
-void _M2_SArgs_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_SArgs_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_SArgs_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_SArgs_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GSArgs.h b/gcc/m2/mc-boot/GSArgs.h
index 27d4ce0f598..84927190895 100644
--- a/gcc/m2/mc-boot/GSArgs.h
+++ b/gcc/m2/mc-boot/GSArgs.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_SArgs_H)
 #   define _SArgs_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GSFIO.c b/gcc/m2/mc-boot/GSFIO.c
index d597117e2d7..299f0368a60 100644
--- a/gcc/m2/mc-boot/GSFIO.c
+++ b/gcc/m2/mc-boot/GSFIO.c
@@ -49,7 +49,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    Exists - returns TRUE if a file named, fname exists for reading.
 */
 
-unsigned int SFIO_Exists (DynamicStrings_String fname);
+extern "C" unsigned int SFIO_Exists (DynamicStrings_String fname);
 
 /*
    OpenToRead - attempts to open a file, fname, for reading and
@@ -58,7 +58,7 @@ unsigned int SFIO_Exists (DynamicStrings_String fname);
                 calling IsNoError.
 */
 
-FIO_File SFIO_OpenToRead (DynamicStrings_String fname);
+extern "C" FIO_File SFIO_OpenToRead (DynamicStrings_String fname);
 
 /*
    OpenToWrite - attempts to open a file, fname, for write and
@@ -67,7 +67,7 @@ FIO_File SFIO_OpenToRead (DynamicStrings_String fname);
                  calling IsNoError.
 */
 
-FIO_File SFIO_OpenToWrite (DynamicStrings_String fname);
+extern "C" FIO_File SFIO_OpenToWrite (DynamicStrings_String fname);
 
 /*
    OpenForRandom - attempts to open a file, fname, for random access
@@ -81,13 +81,13 @@ FIO_File SFIO_OpenToWrite (DynamicStrings_String fname);
                    and modify an existing file.
 */
 
-FIO_File SFIO_OpenForRandom (DynamicStrings_String fname, unsigned int towrite, unsigned int newfile);
+extern "C" FIO_File SFIO_OpenForRandom (DynamicStrings_String fname, unsigned int towrite, unsigned int newfile);
 
 /*
    WriteS - writes a string, s, to, file. It returns the String, s.
 */
 
-DynamicStrings_String SFIO_WriteS (FIO_File file, DynamicStrings_String s);
+extern "C" DynamicStrings_String SFIO_WriteS (FIO_File file, DynamicStrings_String s);
 
 /*
    ReadS - reads and returns a string from, file.
@@ -96,16 +96,16 @@ DynamicStrings_String SFIO_WriteS (FIO_File file, DynamicStrings_String s);
            this into the returned string.
 */
 
-DynamicStrings_String SFIO_ReadS (FIO_File file);
+extern "C" DynamicStrings_String SFIO_ReadS (FIO_File file);
 
 
 /*
    Exists - returns TRUE if a file named, fname exists for reading.
 */
 
-unsigned int SFIO_Exists (DynamicStrings_String fname)
+extern "C" unsigned int SFIO_Exists (DynamicStrings_String fname)
 {
-  return FIO_exists (DynamicStrings_string (fname), DynamicStrings_Length (fname));
+  return static_cast<unsigned int> (FIO_exists (DynamicStrings_string (fname), DynamicStrings_Length (fname)));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -118,9 +118,9 @@ unsigned int SFIO_Exists (DynamicStrings_String fname)
                 calling IsNoError.
 */
 
-FIO_File SFIO_OpenToRead (DynamicStrings_String fname)
+extern "C" FIO_File SFIO_OpenToRead (DynamicStrings_String fname)
 {
-  return FIO_openToRead (DynamicStrings_string (fname), DynamicStrings_Length (fname));
+  return static_cast<FIO_File> (FIO_openToRead (DynamicStrings_string (fname), DynamicStrings_Length (fname)));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -133,9 +133,9 @@ FIO_File SFIO_OpenToRead (DynamicStrings_String fname)
                  calling IsNoError.
 */
 
-FIO_File SFIO_OpenToWrite (DynamicStrings_String fname)
+extern "C" FIO_File SFIO_OpenToWrite (DynamicStrings_String fname)
 {
-  return FIO_openToWrite (DynamicStrings_string (fname), DynamicStrings_Length (fname));
+  return static_cast<FIO_File> (FIO_openToWrite (DynamicStrings_string (fname), DynamicStrings_Length (fname)));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -153,9 +153,9 @@ FIO_File SFIO_OpenToWrite (DynamicStrings_String fname)
                    and modify an existing file.
 */
 
-FIO_File SFIO_OpenForRandom (DynamicStrings_String fname, unsigned int towrite, unsigned int newfile)
+extern "C" FIO_File SFIO_OpenForRandom (DynamicStrings_String fname, unsigned int towrite, unsigned int newfile)
 {
-  return FIO_openForRandom (DynamicStrings_string (fname), DynamicStrings_Length (fname), towrite, newfile);
+  return static_cast<FIO_File> (FIO_openForRandom (DynamicStrings_string (fname), DynamicStrings_Length (fname), towrite, newfile));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
@@ -165,13 +165,13 @@ FIO_File SFIO_OpenForRandom (DynamicStrings_String fname, unsigned int towrite,
    WriteS - writes a string, s, to, file. It returns the String, s.
 */
 
-DynamicStrings_String SFIO_WriteS (FIO_File file, DynamicStrings_String s)
+extern "C" DynamicStrings_String SFIO_WriteS (FIO_File file, DynamicStrings_String s)
 {
   unsigned int nBytes;
 
   if (s != NULL)
     {
-      nBytes = FIO_WriteNBytes (file, DynamicStrings_Length (s), DynamicStrings_string (s));
+      nBytes = static_cast<unsigned int> (FIO_WriteNBytes (file, DynamicStrings_Length (s), DynamicStrings_string (s)));
     }
   return s;
   /* static analysis guarentees a RETURN statement will be used before here.  */
@@ -186,15 +186,15 @@ DynamicStrings_String SFIO_WriteS (FIO_File file, DynamicStrings_String s)
            this into the returned string.
 */
 
-DynamicStrings_String SFIO_ReadS (FIO_File file)
+extern "C" DynamicStrings_String SFIO_ReadS (FIO_File file)
 {
   DynamicStrings_String s;
   unsigned int c;
 
-  s = DynamicStrings_InitString ((char *) "", 0);
+  s = static_cast<DynamicStrings_String> (DynamicStrings_InitString ((const char *) "", 0));
   while (((! (FIO_EOLN (file))) && (! (FIO_EOF (file)))) && (FIO_IsNoError (file)))
     {
-      s = DynamicStrings_ConCatChar (s, FIO_ReadChar (file));
+      s = static_cast<DynamicStrings_String> (DynamicStrings_ConCatChar (s, FIO_ReadChar (file)));
     }
   if (FIO_EOLN (file))
     {
@@ -207,10 +207,10 @@ DynamicStrings_String SFIO_ReadS (FIO_File file)
   __builtin_unreachable ();
 }
 
-void _M2_SFIO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_SFIO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_SFIO_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_SFIO_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GSFIO.h b/gcc/m2/mc-boot/GSFIO.h
index e939b87f06c..36be78de9fb 100644
--- a/gcc/m2/mc-boot/GSFIO.h
+++ b/gcc/m2/mc-boot/GSFIO.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_SFIO_H)
 #   define _SFIO_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GSYSTEM.h b/gcc/m2/mc-boot/GSYSTEM.h
index 537a098efe3..98968dabfae 100644
--- a/gcc/m2/mc-boot/GSYSTEM.h
+++ b/gcc/m2/mc-boot/GSYSTEM.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_SYSTEM_H)
 #   define _SYSTEM_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GSelective.h b/gcc/m2/mc-boot/GSelective.h
index 24a9426d485..3c29f2847a0 100644
--- a/gcc/m2/mc-boot/GSelective.h
+++ b/gcc/m2/mc-boot/GSelective.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_Selective_H)
 #   define _Selective_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GStdIO.c b/gcc/m2/mc-boot/GStdIO.c
index cb5d19d16f6..50e00023a19 100644
--- a/gcc/m2/mc-boot/GStdIO.c
+++ b/gcc/m2/mc-boot/GStdIO.c
@@ -67,14 +67,14 @@ static unsigned int StackRPtr;
           should use to receive a character.
 */
 
-void StdIO_Read (char *ch);
+extern "C" void StdIO_Read (char *ch);
 
 /*
    Write - is the generic procedure that all higher application layers
            should use to emit a character.
 */
 
-void StdIO_Write (char ch);
+extern "C" void StdIO_Write (char ch);
 
 /*
    PushOutput - pushes the current Write procedure onto a stack,
@@ -82,19 +82,19 @@ void StdIO_Write (char ch);
                 procedure, p.
 */
 
-void StdIO_PushOutput (StdIO_ProcWrite p);
+extern "C" void StdIO_PushOutput (StdIO_ProcWrite p);
 
 /*
    PopOutput - restores Write to use the previous output procedure.
 */
 
-void StdIO_PopOutput (void);
+extern "C" void StdIO_PopOutput (void);
 
 /*
    GetCurrentOutput - returns the current output procedure.
 */
 
-StdIO_ProcWrite StdIO_GetCurrentOutput (void);
+extern "C" StdIO_ProcWrite StdIO_GetCurrentOutput (void);
 
 /*
    PushInput - pushes the current Read procedure onto a stack,
@@ -102,19 +102,19 @@ StdIO_ProcWrite StdIO_GetCurrentOutput (void);
                procedure, p.
 */
 
-void StdIO_PushInput (StdIO_ProcRead p);
+extern "C" void StdIO_PushInput (StdIO_ProcRead p);
 
 /*
    PopInput - restores Write to use the previous output procedure.
 */
 
-void StdIO_PopInput (void);
+extern "C" void StdIO_PopInput (void);
 
 /*
    GetCurrentInput - returns the current input procedure.
 */
 
-StdIO_ProcRead StdIO_GetCurrentInput (void);
+extern "C" StdIO_ProcRead StdIO_GetCurrentInput (void);
 
 
 /*
@@ -122,7 +122,7 @@ StdIO_ProcRead StdIO_GetCurrentInput (void);
           should use to receive a character.
 */
 
-void StdIO_Read (char *ch)
+extern "C" void StdIO_Read (char *ch)
 {
   (*StackR.array[StackRPtr].proc) (ch);
 }
@@ -133,7 +133,7 @@ void StdIO_Read (char *ch)
            should use to emit a character.
 */
 
-void StdIO_Write (char ch)
+extern "C" void StdIO_Write (char ch)
 {
   (*StackW.array[StackWPtr].proc) (ch);
 }
@@ -145,7 +145,7 @@ void StdIO_Write (char ch)
                 procedure, p.
 */
 
-void StdIO_PushOutput (StdIO_ProcWrite p)
+extern "C" void StdIO_PushOutput (StdIO_ProcWrite p)
 {
   if (StackWPtr == MaxStack)
     {
@@ -164,7 +164,7 @@ void StdIO_PushOutput (StdIO_ProcWrite p)
    PopOutput - restores Write to use the previous output procedure.
 */
 
-void StdIO_PopOutput (void)
+extern "C" void StdIO_PopOutput (void)
 {
   if (StackWPtr == 1)
     {
@@ -182,7 +182,7 @@ void StdIO_PopOutput (void)
    GetCurrentOutput - returns the current output procedure.
 */
 
-StdIO_ProcWrite StdIO_GetCurrentOutput (void)
+extern "C" StdIO_ProcWrite StdIO_GetCurrentOutput (void)
 {
   if (StackWPtr > 0)
     {
@@ -204,7 +204,7 @@ StdIO_ProcWrite StdIO_GetCurrentOutput (void)
                procedure, p.
 */
 
-void StdIO_PushInput (StdIO_ProcRead p)
+extern "C" void StdIO_PushInput (StdIO_ProcRead p)
 {
   if (StackRPtr == MaxStack)
     {
@@ -223,7 +223,7 @@ void StdIO_PushInput (StdIO_ProcRead p)
    PopInput - restores Write to use the previous output procedure.
 */
 
-void StdIO_PopInput (void)
+extern "C" void StdIO_PopInput (void)
 {
   if (StackRPtr == 1)
     {
@@ -241,7 +241,7 @@ void StdIO_PopInput (void)
    GetCurrentInput - returns the current input procedure.
 */
 
-StdIO_ProcRead StdIO_GetCurrentInput (void)
+extern "C" StdIO_ProcRead StdIO_GetCurrentInput (void)
 {
   if (StackRPtr > 0)
     {
@@ -256,14 +256,14 @@ StdIO_ProcRead StdIO_GetCurrentInput (void)
   __builtin_unreachable ();
 }
 
-void _M2_StdIO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_StdIO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
-  StackWPtr = 0;
-  StackRPtr = 0;
+  StackWPtr = static_cast<unsigned int> (0);
+  StackRPtr = static_cast<unsigned int> (0);
   StdIO_PushOutput ((StdIO_ProcWrite) {(StdIO_ProcWrite_t) IO_Write});
   StdIO_PushInput ((StdIO_ProcRead) {(StdIO_ProcRead_t) IO_Read});
 }
 
-void _M2_StdIO_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_StdIO_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GStdIO.h b/gcc/m2/mc-boot/GStdIO.h
index 51ba9a4bff0..34a8870c85a 100644
--- a/gcc/m2/mc-boot/GStdIO.h
+++ b/gcc/m2/mc-boot/GStdIO.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_StdIO_H)
 #   define _StdIO_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GStorage.c b/gcc/m2/mc-boot/GStorage.c
index 8519fd2cd51..94c7a0740be 100644
--- a/gcc/m2/mc-boot/GStorage.c
+++ b/gcc/m2/mc-boot/GStorage.c
@@ -38,37 +38,37 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #   include "GSysStorage.h"
 
-void Storage_ALLOCATE (void * *a, unsigned int Size);
-void Storage_DEALLOCATE (void * *a, unsigned int Size);
-void Storage_REALLOCATE (void * *a, unsigned int Size);
-unsigned int Storage_Available (unsigned int Size);
+extern "C" void Storage_ALLOCATE (void * *a, unsigned int Size);
+extern "C" void Storage_DEALLOCATE (void * *a, unsigned int Size);
+extern "C" void Storage_REALLOCATE (void * *a, unsigned int Size);
+extern "C" unsigned int Storage_Available (unsigned int Size);
 
-void Storage_ALLOCATE (void * *a, unsigned int Size)
+extern "C" void Storage_ALLOCATE (void * *a, unsigned int Size)
 {
   SysStorage_ALLOCATE (a, Size);
 }
 
-void Storage_DEALLOCATE (void * *a, unsigned int Size)
+extern "C" void Storage_DEALLOCATE (void * *a, unsigned int Size)
 {
   SysStorage_DEALLOCATE (a, Size);
 }
 
-void Storage_REALLOCATE (void * *a, unsigned int Size)
+extern "C" void Storage_REALLOCATE (void * *a, unsigned int Size)
 {
   SysStorage_REALLOCATE (a, Size);
 }
 
-unsigned int Storage_Available (unsigned int Size)
+extern "C" unsigned int Storage_Available (unsigned int Size)
 {
-  return SysStorage_Available (Size);
+  return static_cast<unsigned int> (SysStorage_Available (Size));
   /* static analysis guarentees a RETURN statement will be used before here.  */
   __builtin_unreachable ();
 }
 
-void _M2_Storage_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_Storage_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_Storage_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_Storage_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GStorage.h b/gcc/m2/mc-boot/GStorage.h
index b304e49cb4a..517f255b236 100644
--- a/gcc/m2/mc-boot/GStorage.h
+++ b/gcc/m2/mc-boot/GStorage.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_Storage_H)
 #   define _Storage_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
diff --git a/gcc/m2/mc-boot/GStrCase.c b/gcc/m2/mc-boot/GStrCase.c
index fa238bb50f6..048eea78852 100644
--- a/gcc/m2/mc-boot/GStrCase.c
+++ b/gcc/m2/mc-boot/GStrCase.c
@@ -45,14 +45,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
                     result in, b.
 */
 
-void StrCase_StrToUpperCase (char *a_, unsigned int _a_high, char *b, unsigned int _b_high);
+extern "C" void StrCase_StrToUpperCase (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high);
 
 /*
    StrToLowerCase - converts string, a, to lowercase returning the
                     result in, b.
 */
 
-void StrCase_StrToLowerCase (char *a_, unsigned int _a_high, char *b, unsigned int _b_high);
+extern "C" void StrCase_StrToLowerCase (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high);
 
 /*
    Cap - converts a lower case character into a capital character.
@@ -60,7 +60,7 @@ void StrCase_StrToLowerCase (char *a_, unsigned int _a_high, char *b, unsigned i
          then the character is simply returned unaltered.
 */
 
-char StrCase_Cap (char ch);
+extern "C" char StrCase_Cap (char ch);
 
 /*
    Lower - converts an upper case character into a lower case character.
@@ -68,7 +68,7 @@ char StrCase_Cap (char ch);
            then the character is simply returned unaltered.
 */
 
-char StrCase_Lower (char ch);
+extern "C" char StrCase_Lower (char ch);
 
 
 /*
@@ -76,7 +76,7 @@ char StrCase_Lower (char ch);
                     result in, b.
 */
 
-void StrCase_StrToUpperCase (char *a_, unsigned int _a_high, char *b, unsigned int _b_high)
+extern "C" void StrCase_StrToUpperCase (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high)
 {
   unsigned int higha;
   unsigned int highb;
@@ -86,12 +86,12 @@ void StrCase_StrToUpperCase (char *a_, unsigned int _a_high, char *b, unsigned i
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  higha = StrLib_StrLen ((char *) a, _a_high);
+  higha = static_cast<unsigned int> (StrLib_StrLen ((const char *) a, _a_high));
   highb = _b_high;
-  i = 0;
+  i = static_cast<unsigned int> (0);
   while (((i < higha) && (a[i] != ASCII_nul)) && (i < highb))
     {
-      b[i] = StrCase_Cap (a[i]);
+      b[i] = static_cast<char> (StrCase_Cap (a[i]));
       i += 1;
     }
   if (i < highb)
@@ -106,7 +106,7 @@ void StrCase_StrToUpperCase (char *a_, unsigned int _a_high, char *b, unsigned i
                     result in, b.
 */
 
-void StrCase_StrToLowerCase (char *a_, unsigned int _a_high, char *b, unsigned int _b_high)
+extern "C" void StrCase_StrToLowerCase (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high)
 {
   unsigned int higha;
   unsigned int highb;
@@ -116,12 +116,12 @@ void StrCase_StrToLowerCase (char *a_, unsigned int _a_high, char *b, unsigned i
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  higha = StrLib_StrLen ((char *) a, _a_high);
+  higha = static_cast<unsigned int> (StrLib_StrLen ((const char *) a, _a_high));
   highb = _b_high;
-  i = 0;
+  i = static_cast<unsigned int> (0);
   while (((i < higha) && (a[i] != ASCII_nul)) && (i < highb))
     {
-      b[i] = StrCase_Lower (a[i]);
+      b[i] = static_cast<char> (StrCase_Lower (a[i]));
       i += 1;
     }
   if (i < highb)
@@ -137,7 +137,7 @@ void StrCase_StrToLowerCase (char *a_, unsigned int _a_high, char *b, unsigned i
          then the character is simply returned unaltered.
 */
 
-char StrCase_Cap (char ch)
+extern "C" char StrCase_Cap (char ch)
 {
   if ((ch >= 'a') && (ch <= 'z'))
     {
@@ -155,7 +155,7 @@ char StrCase_Cap (char ch)
            then the character is simply returned unaltered.
 */
 
-char StrCase_Lower (char ch)
+extern "C" char StrCase_Lower (char ch)
 {
   if ((ch >= 'A') && (ch <= 'Z'))
     {
@@ -166,10 +166,10 @@ char StrCase_Lower (char ch)
   __builtin_unreachable ();
 }
 
-void _M2_StrCase_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_StrCase_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_StrCase_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_StrCase_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GStrCase.h b/gcc/m2/mc-boot/GStrCase.h
index 6cadc743eb7..6294d60c99a 100644
--- a/gcc/m2/mc-boot/GStrCase.h
+++ b/gcc/m2/mc-boot/GStrCase.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_StrCase_H)
 #   define _StrCase_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
@@ -53,14 +53,14 @@ extern "C" {
                     result in, b.
 */
 
-EXTERN void StrCase_StrToUpperCase (char *a_, unsigned int _a_high, char *b, unsigned int _b_high);
+EXTERN void StrCase_StrToUpperCase (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high);
 
 /*
    StrToLowerCase - converts string, a, to lowercase returning the
                     result in, b.
 */
 
-EXTERN void StrCase_StrToLowerCase (char *a_, unsigned int _a_high, char *b, unsigned int _b_high);
+EXTERN void StrCase_StrToLowerCase (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high);
 
 /*
    Cap - converts a lower case character into a capital character.
diff --git a/gcc/m2/mc-boot/GStrIO.c b/gcc/m2/mc-boot/GStrIO.c
index b635d777218..2813b467d0d 100644
--- a/gcc/m2/mc-boot/GStrIO.c
+++ b/gcc/m2/mc-boot/GStrIO.c
@@ -51,7 +51,7 @@ static unsigned int IsATTY;
              character.
 */
 
-void StrIO_WriteLn (void);
+extern "C" void StrIO_WriteLn (void);
 
 /*
    ReadString - reads a sequence of characters into a string.
@@ -59,13 +59,13 @@ void StrIO_WriteLn (void);
                 Ctrl U.
 */
 
-void StrIO_ReadString (char *a, unsigned int _a_high);
+extern "C" void StrIO_ReadString (char *a, unsigned int _a_high);
 
 /*
    WriteString - writes a string to the default output.
 */
 
-void StrIO_WriteString (char *a_, unsigned int _a_high);
+extern "C" void StrIO_WriteString (const char *a_, unsigned int _a_high);
 
 /*
    Erase - writes a backspace, space and backspace to remove the
@@ -132,7 +132,7 @@ static unsigned int AlphaNum (char ch)
              character.
 */
 
-void StrIO_WriteLn (void)
+extern "C" void StrIO_WriteLn (void)
 {
   Echo (ASCII_cr);
   StdIO_Write (ASCII_lf);
@@ -145,14 +145,14 @@ void StrIO_WriteLn (void)
                 Ctrl U.
 */
 
-void StrIO_ReadString (char *a, unsigned int _a_high)
+extern "C" void StrIO_ReadString (char *a, unsigned int _a_high)
 {
   unsigned int n;
   unsigned int high;
   char ch;
 
   high = _a_high;
-  n = 0;
+  n = static_cast<unsigned int> (0);
   do {
     StdIO_Read (&ch);
     if ((ch == ASCII_del) || (ch == ASCII_bs))
@@ -203,7 +203,7 @@ void StrIO_ReadString (char *a, unsigned int _a_high)
         /* avoid dangling else.  */
         if ((ch == ASCII_cr) || (ch == ASCII_lf))
           {
-            a[n] = ASCII_nul;
+            a[n] = static_cast<char> (ASCII_nul);
             n += 1;
           }
         else if (ch == ASCII_ff)
@@ -248,7 +248,7 @@ void StrIO_ReadString (char *a, unsigned int _a_high)
    WriteString - writes a string to the default output.
 */
 
-void StrIO_WriteString (char *a_, unsigned int _a_high)
+extern "C" void StrIO_WriteString (const char *a_, unsigned int _a_high)
 {
   unsigned int n;
   unsigned int high;
@@ -258,7 +258,7 @@ void StrIO_WriteString (char *a_, unsigned int _a_high)
   memcpy (a, a_, _a_high+1);
 
   high = _a_high;
-  n = 0;
+  n = static_cast<unsigned int> (0);
   while ((n <= high) && (a[n] != ASCII_nul))
     {
       StdIO_Write (a[n]);
@@ -266,12 +266,12 @@ void StrIO_WriteString (char *a_, unsigned int _a_high)
     }
 }
 
-void _M2_StrIO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_StrIO_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
   /* IsATTY := isatty()  */
   IsATTY = FALSE;
 }
 
-void _M2_StrIO_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_StrIO_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GStrIO.h b/gcc/m2/mc-boot/GStrIO.h
index d3966f4f23f..6ec85184705 100644
--- a/gcc/m2/mc-boot/GStrIO.h
+++ b/gcc/m2/mc-boot/GStrIO.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_StrIO_H)
 #   define _StrIO_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
@@ -67,7 +67,7 @@ EXTERN void StrIO_ReadString (char *a, unsigned int _a_high);
    WriteString - writes a string to the default output.
 */
 
-EXTERN void StrIO_WriteString (char *a_, unsigned int _a_high);
+EXTERN void StrIO_WriteString (const char *a_, unsigned int _a_high);
 #   ifdef __cplusplus
 }
 #   endif
diff --git a/gcc/m2/mc-boot/GStrLib.c b/gcc/m2/mc-boot/GStrLib.c
index 302703992db..a956ff3826f 100644
--- a/gcc/m2/mc-boot/GStrLib.c
+++ b/gcc/m2/mc-boot/GStrLib.c
@@ -51,16 +51,16 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    StrConCat - combines a and b into c.
 */
 
-void StrLib_StrConCat (char *a_, unsigned int _a_high, char *b_, unsigned int _b_high, char *c, unsigned int _c_high);
+extern "C" void StrLib_StrConCat (const char *a_, unsigned int _a_high, const char *b_, unsigned int _b_high, char *c, unsigned int _c_high);
 
 /*
    StrLess - returns TRUE if string, a, alphabetically occurs before
              string, b.
 */
 
-unsigned int StrLib_StrLess (char *a_, unsigned int _a_high, char *b_, unsigned int _b_high);
-unsigned int StrLib_StrEqual (char *a_, unsigned int _a_high, char *b_, unsigned int _b_high);
-unsigned int StrLib_StrLen (char *a_, unsigned int _a_high);
+extern "C" unsigned int StrLib_StrLess (const char *a_, unsigned int _a_high, const char *b_, unsigned int _b_high);
+extern "C" unsigned int StrLib_StrEqual (const char *a_, unsigned int _a_high, const char *b_, unsigned int _b_high);
+extern "C" unsigned int StrLib_StrLen (const char *a_, unsigned int _a_high);
 
 /*
    StrCopy - copy string src into string dest providing dest is large enough.
@@ -68,20 +68,20 @@ unsigned int StrLib_StrLen (char *a_, unsigned int _a_high);
              dest is full.  Add a nul character if there is room in dest.
 */
 
-void StrLib_StrCopy (char *src_, unsigned int _src_high, char *dest, unsigned int _dest_high);
+extern "C" void StrLib_StrCopy (const char *src_, unsigned int _src_high, char *dest, unsigned int _dest_high);
 
 /*
    IsSubString - returns true if b is a subcomponent of a.
 */
 
-unsigned int StrLib_IsSubString (char *a_, unsigned int _a_high, char *b_, unsigned int _b_high);
+extern "C" unsigned int StrLib_IsSubString (const char *a_, unsigned int _a_high, const char *b_, unsigned int _b_high);
 
 /*
    StrRemoveWhitePrefix - copies string, into string, b, excluding any white
                           space infront of a.
 */
 
-void StrLib_StrRemoveWhitePrefix (char *a_, unsigned int _a_high, char *b, unsigned int _b_high);
+extern "C" void StrLib_StrRemoveWhitePrefix (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high);
 
 /*
    IsWhite - returns TRUE if, ch, is a space or a tab.
@@ -106,7 +106,7 @@ static unsigned int IsWhite (char ch)
    StrConCat - combines a and b into c.
 */
 
-void StrLib_StrConCat (char *a_, unsigned int _a_high, char *b_, unsigned int _b_high, char *c, unsigned int _c_high)
+extern "C" void StrLib_StrConCat (const char *a_, unsigned int _a_high, const char *b_, unsigned int _b_high, char *c, unsigned int _c_high)
 {
   unsigned int Highb;
   unsigned int Highc;
@@ -119,11 +119,11 @@ void StrLib_StrConCat (char *a_, unsigned int _a_high, char *b_, unsigned int _b
   memcpy (a, a_, _a_high+1);
   memcpy (b, b_, _b_high+1);
 
-  Highb = StrLib_StrLen ((char *) b, _b_high);
+  Highb = static_cast<unsigned int> (StrLib_StrLen ((const char *) b, _b_high));
   Highc = _c_high;
-  StrLib_StrCopy ((char *) a, _a_high, (char *) c, _c_high);
-  i = StrLib_StrLen ((char *) c, _c_high);
-  j = 0;
+  StrLib_StrCopy ((const char *) a, _a_high, (char *) c, _c_high);
+  i = static_cast<unsigned int> (StrLib_StrLen ((const char *) c, _c_high));
+  j = static_cast<unsigned int> (0);
   while ((j < Highb) && (i <= Highc))
     {
       c[i] = b[j];
@@ -132,7 +132,7 @@ void StrLib_StrConCat (char *a_, unsigned int _a_high, char *b_, unsigned int _b
     }
   if (i <= Highc)
     {
-      c[i] = ASCII_nul;
+      c[i] = static_cast<char> (ASCII_nul);
     }
 }
 
@@ -142,7 +142,7 @@ void StrLib_StrConCat (char *a_, unsigned int _a_high, char *b_, unsigned int _b
              string, b.
 */
 
-unsigned int StrLib_StrLess (char *a_, unsigned int _a_high, char *b_, unsigned int _b_high)
+extern "C" unsigned int StrLib_StrLess (const char *a_, unsigned int _a_high, const char *b_, unsigned int _b_high)
 {
   unsigned int Higha;
   unsigned int Highb;
@@ -154,9 +154,9 @@ unsigned int StrLib_StrLess (char *a_, unsigned int _a_high, char *b_, unsigned
   memcpy (a, a_, _a_high+1);
   memcpy (b, b_, _b_high+1);
 
-  Higha = StrLib_StrLen ((char *) a, _a_high);
-  Highb = StrLib_StrLen ((char *) b, _b_high);
-  i = 0;
+  Higha = static_cast<unsigned int> (StrLib_StrLen ((const char *) a, _a_high));
+  Highb = static_cast<unsigned int> (StrLib_StrLen ((const char *) b, _b_high));
+  i = static_cast<unsigned int> (0);
   while ((i < Higha) && (i < Highb))
     {
       if (a[i] < b[i])
@@ -176,7 +176,7 @@ unsigned int StrLib_StrLess (char *a_, unsigned int _a_high, char *b_, unsigned
   __builtin_unreachable ();
 }
 
-unsigned int StrLib_StrEqual (char *a_, unsigned int _a_high, char *b_, unsigned int _b_high)
+extern "C" unsigned int StrLib_StrEqual (const char *a_, unsigned int _a_high, const char *b_, unsigned int _b_high)
 {
   unsigned int i;
   unsigned int higha;
@@ -190,7 +190,7 @@ unsigned int StrLib_StrEqual (char *a_, unsigned int _a_high, char *b_, unsigned
 
   higha = _a_high;
   highb = _b_high;
-  i = 0;
+  i = static_cast<unsigned int> (0);
   while ((((i <= higha) && (i <= highb)) && (a[i] != ASCII_nul)) && (b[i] != ASCII_nul))
     {
       if (a[i] != b[i])
@@ -204,7 +204,7 @@ unsigned int StrLib_StrEqual (char *a_, unsigned int _a_high, char *b_, unsigned
   __builtin_unreachable ();
 }
 
-unsigned int StrLib_StrLen (char *a_, unsigned int _a_high)
+extern "C" unsigned int StrLib_StrLen (const char *a_, unsigned int _a_high)
 {
   unsigned int High;
   unsigned int Len;
@@ -213,7 +213,7 @@ unsigned int StrLib_StrLen (char *a_, unsigned int _a_high)
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  Len = 0;
+  Len = static_cast<unsigned int> (0);
   High = _a_high;
   while ((Len <= High) && (a[Len] != ASCII_nul))
     {
@@ -231,7 +231,7 @@ unsigned int StrLib_StrLen (char *a_, unsigned int _a_high)
              dest is full.  Add a nul character if there is room in dest.
 */
 
-void StrLib_StrCopy (char *src_, unsigned int _src_high, char *dest, unsigned int _dest_high)
+extern "C" void StrLib_StrCopy (const char *src_, unsigned int _src_high, char *dest, unsigned int _dest_high)
 {
   unsigned int HighSrc;
   unsigned int HighDest;
@@ -241,8 +241,8 @@ void StrLib_StrCopy (char *src_, unsigned int _src_high, char *dest, unsigned in
   /* make a local copy of each unbounded array.  */
   memcpy (src, src_, _src_high+1);
 
-  n = 0;
-  HighSrc = StrLib_StrLen ((char *) src, _src_high);
+  n = static_cast<unsigned int> (0);
+  HighSrc = static_cast<unsigned int> (StrLib_StrLen ((const char *) src, _src_high));
   HighDest = _dest_high;
   while ((n < HighSrc) && (n <= HighDest))
     {
@@ -260,7 +260,7 @@ void StrLib_StrCopy (char *src_, unsigned int _src_high, char *dest, unsigned in
    IsSubString - returns true if b is a subcomponent of a.
 */
 
-unsigned int StrLib_IsSubString (char *a_, unsigned int _a_high, char *b_, unsigned int _b_high)
+extern "C" unsigned int StrLib_IsSubString (const char *a_, unsigned int _a_high, const char *b_, unsigned int _b_high)
 {
   unsigned int i;
   unsigned int j;
@@ -273,14 +273,14 @@ unsigned int StrLib_IsSubString (char *a_, unsigned int _a_high, char *b_, unsig
   memcpy (a, a_, _a_high+1);
   memcpy (b, b_, _b_high+1);
 
-  LengthA = StrLib_StrLen ((char *) a, _a_high);
-  LengthB = StrLib_StrLen ((char *) b, _b_high);
-  i = 0;
+  LengthA = static_cast<unsigned int> (StrLib_StrLen ((const char *) a, _a_high));
+  LengthB = static_cast<unsigned int> (StrLib_StrLen ((const char *) b, _b_high));
+  i = static_cast<unsigned int> (0);
   if (LengthA > LengthB)
     {
       while (i <= (LengthA-LengthB))
         {
-          j = 0;
+          j = static_cast<unsigned int> (0);
           while ((j < LengthB) && (a[i+j] == b[j]))
             {
               j += 1;
@@ -306,7 +306,7 @@ unsigned int StrLib_IsSubString (char *a_, unsigned int _a_high, char *b_, unsig
                           space infront of a.
 */
 
-void StrLib_StrRemoveWhitePrefix (char *a_, unsigned int _a_high, char *b, unsigned int _b_high)
+extern "C" void StrLib_StrRemoveWhitePrefix (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high)
 {
   unsigned int i;
   unsigned int j;
@@ -317,9 +317,9 @@ void StrLib_StrRemoveWhitePrefix (char *a_, unsigned int _a_high, char *b, unsig
   /* make a local copy of each unbounded array.  */
   memcpy (a, a_, _a_high+1);
 
-  i = 0;
-  j = 0;
-  higha = StrLib_StrLen ((char *) a, _a_high);
+  i = static_cast<unsigned int> (0);
+  j = static_cast<unsigned int> (0);
+  higha = static_cast<unsigned int> (StrLib_StrLen ((const char *) a, _a_high));
   highb = _b_high;
   while ((i < higha) && (IsWhite (a[i])))
     {
@@ -337,10 +337,10 @@ void StrLib_StrRemoveWhitePrefix (char *a_, unsigned int _a_high, char *b, unsig
     }
 }
 
-void _M2_StrLib_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_StrLib_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
 
-void _M2_StrLib_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
+extern "C" void _M2_StrLib_finish (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[])
 {
 }
diff --git a/gcc/m2/mc-boot/GStrLib.h b/gcc/m2/mc-boot/GStrLib.h
index 626a9ba3840..fa916ecab5f 100644
--- a/gcc/m2/mc-boot/GStrLib.h
+++ b/gcc/m2/mc-boot/GStrLib.h
@@ -29,11 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #if !defined (_StrLib_H)
 #   define _StrLib_H
 
+#include "config.h"
+#include "system.h"
 #   ifdef __cplusplus
 extern "C" {
 #   endif
-#include "config.h"
-#include "system.h"
 #   if !defined (PROC_D)
 #      define PROC_D
        typedef void (*PROC_t) (void);
@@ -52,26 +52,26 @@ extern "C" {
    StrConCat - combines a and b into c.
 */
 
-EXTERN void StrLib_StrConCat (char *a_, unsigned int _a_high, char *b_, unsigned int _b_high, char *c, unsigned int _c_high);
+EXTERN void StrLib_StrConCat (const char *a_, unsigned int _a_high, const char *b_, unsigned int _b_high, char *c, unsigned int _c_high);
 
 /*
    StrLess - returns TRUE if string, a, alphabetically occurs before
              string, b.
 */
 
-EXTERN unsigned int StrLib_StrLess (char *a_, unsigned int _a_high, char *b_, unsigned int _b_high);
+EXTERN unsigned int StrLib_StrLess (const char *a_, unsigned int _a_high, const char *b_, unsigned int _b_high);
 
 /*
    StrEqual - performs a = b on two strings.
 */
 
-EXTERN unsigned int StrLib_StrEqual (char *a_, unsigned int _a_high, char *b_, unsigned int _b_high);
+EXTERN unsigned int StrLib_StrEqual (const char *a_, unsigned int _a_high, const char *b_, unsigned int _b_high);
 
 /*
    StrLen - returns the length of string, a.
 */
 
-EXTERN unsigned int StrLib_StrLen (char *a_, unsigned int _a_high);
+EXTERN unsigned int StrLib_StrLen (const char *a_, unsigned int _a_high);
 
 /*
    StrCopy - copy string src into string dest providing dest is large enough.
@@ -79,20 +79,20 @@ EXTERN unsigned int StrLib_StrLen (char *a_, unsigned int _a_high);
              dest is full.  Add a nul character if there is room in dest.
 */
 
-EXTERN void StrLib_StrCopy (char *src_, unsigned int _src_high, char *dest, unsigned int _dest_high);
+EXTERN void StrLib_StrCopy (const char *src_, unsigned int _src_high, char *dest, unsigned int _dest_high);
 
 /*
    IsSubString - returns true if b is a subcomponent of a.
 */
 
-EXTERN unsigned int StrLib_IsSubString (char *a_, unsigned int _a_high, char *b_, unsigned int _b_high);
+EXTERN unsigned int StrLib_IsSubString (const char *a_, unsigned int _a_high, const char *b_, unsigned int _b_high);
 
 /*
    StrRemoveWhitePrefix - copies string, into string, b, excluding any white
                           space infront of a.
 */
 
-EXTERN void StrLib_StrRemoveWhitePrefix (char *a_, unsigned int _a_high, char *b, unsigned int _b_high);
+EXTERN void StrLib_StrRemoveWhitePrefix (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high);
 #   ifdef __cplusplus
 }
 #   endif
diff --git a/gcc/m2/mc-boot/GStringConvert.c b/gcc/m2/mc-boot/GStringConvert.c
index 64489766456..3592eac188f 100644
--- a/gcc/m2/mc-boot/GStringConvert.c
+++ b/gcc/m2/mc-boot/GStringConvert.c
@@ -67,7 +67,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
                      are used.
 */
 
-DynamicStrings_String StringConvert_IntegerToString (int i, unsigned int width, char padding, unsigned int sign, unsigned int base, unsigned int lower);
+extern "C" DynamicStrings_String StringConvert_IntegerToString (int i, unsigned int width, char padding, unsigned int sign, unsigned int base, unsigned int lower);
 
 /*
    CardinalToString - converts CARDINAL, c, into a String. The field with can be specified
@@ -78,7 +78,7 @@ DynamicStrings_String StringConvert_IntegerToString (int i, unsigned int width,
                       are used.
 */
 
-DynamicStrings_String StringConvert_CardinalToString (unsigned int c, unsigned int width, char padding, unsigned int base, unsigned int lower);
+extern "C" DynamicStrings_String StringConvert_CardinalToString (unsigned int c, unsigned int width, char padding, unsigned int base, unsigned int lower);
 
 /*
    StringToInteger - converts a string, s, of, base, into an INTEGER.
@@ -88,7 +88,7 @@ DynamicStrings_String StringConvert_CardinalToString (unsigned int c, unsigned i
                      The parameter found is set TRUE if a number was found.
 */
 
-int StringConvert_StringToInteger (DynamicStrings_String s, unsigned int base, unsigned int *found);
+extern "C" int StringConvert_StringToInteger (DynamicStrings_String s, unsigned int base, unsigned int *found);
 
 /*
    StringToCardinal - converts a string, s, of, base, into a CARDINAL.
@@ -98,7 +98,7 @@ int StringConvert_StringToInteger (DynamicStrings_String s, unsigned int base, u
                       The parameter found is set TRUE if a number was found.
 */
 
-unsigned int StringConvert_StringToCardinal (DynamicStrings_String s, unsigned int base, unsigned int *found);
+extern "C" unsigned int StringConvert_StringToCardinal (DynamicStrings_String s, unsigned int base, unsigned int *found);
 
 /*
    LongIntegerToString - converts LONGINT, i, into a String. The field with
@@ -112,7 +112,7 @@ unsigned int StringConvert_StringToCardinal (DynamicStrings_String s, unsigned i
                          abcdef are used, and if FALSE then ABCDEF are used.
 */
 
-DynamicStrings_String StringConvert_LongIntegerToString (long int i, unsigned int width, char padding, unsigned int sign, unsigned int base, unsigned int lower);
+extern "C" DynamicStrings_String StringConvert_LongIntegerToString (long int i, unsigned int width, char padding, unsigned int sign, unsigned int base, unsigned int lower);
 
 /*
    StringToLongInteger - converts a string, s, of, base, into an LONGINT.
@@ -122,7 +122,7 @@ DynamicStrings_String StringConvert_LongIntegerToString (long int i, unsigned in
                          The parameter found is set TRUE if a number was found.
 */
 
-long int StringConvert_StringToLongInteger (DynamicStrings_String s, unsigned int base, unsigned int *found);
+extern "C" long int StringConvert_StringToLongInteger (DynamicStrings_String s, unsigned int base, unsigned int *found);
 
 /*
    LongCardinalToString - converts LONGCARD, c, into a String. The field
@@ -135,7 +135,7 @@ long int StringConvert_StringToLongInteger (DynamicStrings_String s, unsigned in
                           abcdef are used, and if FALSE then ABCDEF are used.
 */
 
-DynamicStrings_String StringConvert_LongCardinalToString (long unsigned int c, unsigned int width, char padding, unsigned int base, unsigned int lower);
+extern "C" DynamicStrings_String StringConvert_LongCardinalToString (long unsigned int c, unsigned int width, char padding, unsigned int base, unsigned int lower);
 
 /*
    StringToLongCardinal - converts a string, s, of, base, into a LONGCARD.
@@ -145,7 +145,7 @@ DynamicStrings_String StringConvert_LongCardinalToString (long unsigned int c, u
                           The parameter found is set TRUE if a number was found.
 */
 
-long unsigned int StringConvert_StringToLongCardinal (DynamicStrings_String s, unsigned int base, unsigned int *found);
+extern "C" long unsigned int StringConvert_StringToLongCardinal (DynamicStrings_String s, unsigned int base, unsigned int *found);
 
 /*
    ShortCardinalToString - converts SHORTCARD, c, into a String. The field
@@ -158,7 +158,7 @@ long unsigned int StringConvert_StringToLongCardinal (DynamicStrings_String s, u
                           abcdef are used, and if FALSE then ABCDEF are used.
 */
 
-DynamicStrings_String StringConvert_ShortCardinalToString (short unsigned int c, unsigned int width, char padding, unsigned int base, unsigned int lower);
+extern "C" DynamicStrings_String StringConvert_ShortCardinalToString (short unsigned int c, unsigned int width, char padding, unsigned int base, unsigned int lower);
 
 /*
    StringToShortCardinal - converts a string, s, of, base, into a SHORTCARD.
@@ -168,73 +168,73 @@ DynamicStrings_String StringConvert_ShortCardinalToString (short unsigned int c,
                            The parameter found is set TRUE if a number was found.
 */
 
-short unsigned int StringConvert_StringToShortCardinal (DynamicStrings_String s, unsigned int base, unsigned int *found);
+extern "C" short unsigned int StringConvert_StringToShortCardinal (DynamicStrings_String s, unsigned int base, unsigned int *found);
 
 /*
    stoi - decimal string to INTEGER
 */
 
-int StringConvert_stoi (DynamicStrings_String s);
+extern "C" int StringConvert_stoi (DynamicStrings_String s);
 
 /*
    itos - integer to decimal string.
 */
 
-DynamicStrings_String StringConvert_itos (int i, unsigned int width, char padding, unsigned int sign);
+extern "C" DynamicStrings_String StringConvert_itos (int i, unsigned int width, char padding, unsigned int sign);
 
 /*
    ctos - cardinal to decimal string.
 */
 
-DynamicStrings_String StringConvert_ctos (unsigned int c, unsigned int width, char padding);
+extern "C" DynamicStrings_String StringConvert_ctos (unsigned int c, unsigned int width, char padding);
 
 /*
    stoc - decimal string to CARDINAL
 */
 
-unsigned int StringConvert_stoc (DynamicStrings_String s);
+extern "C" unsigned int StringConvert_stoc (DynamicStrings_String s);
 
 /*
    hstoi - hexidecimal string to INTEGER
 */
 
-int StringConvert_hstoi (DynamicStrings_String s);
+extern "C" int StringConvert_hstoi (DynamicStrings_String s);
 
 /*
    ostoi - octal string to INTEGER
 */
 
-int StringConvert_ostoi (DynamicStrings_String s);
+extern "C" int StringConvert_ostoi (DynamicStrings_String s);
 
 /*
    bstoi - binary string to INTEGER
 */
 
-int StringConvert_bstoi (DynamicStrings_String s);
+extern "C" int StringConvert_bstoi (DynamicStrings_String s);
 
 /*
    hstoc - hexidecimal string to CARDINAL
 */
 
-unsigned int StringConvert_hstoc (DynamicStrings_String s);
+extern "C" unsigned int StringConvert_hstoc (DynamicStrings_String s);
 
 /*
    ostoc - octal string to CARDINAL
 */
 
-unsigned int StringConvert_ostoc (DynamicStrings_String s);
+extern "C" unsigned int StringConvert_ostoc (DynamicStrings_String s);
 
 /*
    bstoc - binary string to CARDINAL
 */
 
-unsigned int StringConvert_bstoc (DynamicStrings_String s);
+extern "C" unsigned int StringConvert_bstoc (DynamicStrings_String s);
 
 /*
    StringToLongreal - returns a LONGREAL and sets found to TRUE if a legal number is seen.
 */
 
-long double StringConvert_StringToLongreal (DynamicStrings_String s, unsigned int *found);
+extern "C" long double StringConvert_StringToLongreal (DynamicStrings_String s, unsigned int *found);
 
 /*
    LongrealToString - converts a LONGREAL number, Real, which has,
@@ -260,19 +260,19 @@ long double StringConvert_StringToLongreal (DynamicStrings_String s, unsigned in
                       fractional components.
 */
 
-DynamicStrings_String StringConvert_LongrealToString (long double x, unsigned int TotalWidth, unsigned int FractionWidth);
+extern "C" DynamicStrings_String StringConvert_LongrealToString (long double x, unsigned int TotalWidth, unsigned int FractionWidth);
 
 /*
    stor - returns a REAL given a string.
 */
 
-double StringConvert_stor (DynamicStrings_String s);
+extern "C" double StringConvert_stor (DynamicStrings_String s);
 
 /*
    stolr - returns a LONGREAL given a string.
 */
 
-long double StringConvert_stolr (DynamicStrings_String s);
+extern "C" long double StringConvert_stolr (DynamicStrings_String s);
 
 /*
    ToSigFig - returns a floating point or base 10 integer
@@ -292,7 +292,7 @@ long double StringConvert_stolr (DynamicStrings_String s);
               1      10
 */
 
-DynamicStrings_String StringConvert_ToSigFig (DynamicStrings_String s, unsigned int n);
+extern "C" DynamicStrings_String StringConvert_ToSigFig (DynamicStrings_String s, unsigned int n);
 
 /*
    ToDecimalPlaces - returns a floating point or base 10 integer
@@ -313,13 +313,13 @@ DynamicStrings_String StringConvert_ToSigFig (DynamicStrings_String s, unsigned
                      1      12.3
 */
 
-DynamicStrings_String StringConvert_ToDecimalPlaces (DynamicStrings_String s, unsigned int n);
+extern "C" DynamicStrings_String StringConvert_ToDecimalPlaces (DynamicStrings_String s, unsigned int n);
 
 /*
    Assert - implement a simple assert.
 */
 
-static void Assert (unsigned int b, char *file_, unsigned int _file_high, unsigned int line, char *func_, unsigned int _func_high);
+static void Assert (unsigned int b, const char *file_, unsigned int _file_high, unsigned int line, const char *func_, unsigned int _func_high);
 
 /*
    Max -
@@ -441,7 +441,7 @@ static DynamicStrings_String carryOne (DynamicStrings_String s, unsigned int i);
    Assert - implement a simple assert.
 */
 
-static void Assert (unsigned int b, char *file_, unsigned int _file_high, unsigned int line, char *func_, unsigned int _func_high)
+static void Assert (unsigned int b, const char *file_, unsigned int _file_high, unsigned int line, const char *func_, unsigned int _func_high)
 {
   char file[_file_high+1];
   char func[_func_high+1];
@@ -452,7 +452,7 @@ static void Assert (unsigned int b, char *file_, unsigned int _file_high, unsign
 
   if (! b)
     {
-      M2RTS_ErrorMessage ((char *) "assert failed", 13, (char *) file, _file_high, line, (char *) func, _func_high);
+      M2RTS_ErrorMessage ((const char *) "assert failed", 13, (const char *) file, _file_high, line, (const char *) func, _func_high);
     }
 }
 
@@ -535,7 +535,7 @@ static unsigned int IsDecimalDigitValid (char ch, unsigned int base, unsigned in
 {
   if ((IsDigit (ch)) && (( ((unsigned int) (ch))- ((unsigned int) ('0'))) < base))
     {
-      (*c) = ((*c)*base)+( ((unsigned int) (ch))- ((unsigned int) ('0')));
+      (*c) = static_cast<unsigned int> (((*c)*base)+( ((unsigned int) (ch))- ((unsigned int) ('0'))));
       return TRUE;
     }
   else
@@ -556,13 +556,13 @@ static unsigned int IsHexidecimalDigitValid (char ch, unsigned int base, unsigne
 {
   if (((ch >= 'a') && (ch <= 'f')) && ((( ((unsigned int) (ch))- ((unsigned int) ('a')))+10) < base))
     {
-      (*c) = ((*c)*base)+(( ((unsigned int) (ch))- ((unsigned int) ('a')))+10);
+      (*c) = static_cast<unsigned int> (((*c)*base)+(( ((unsigned int) (ch))- ((unsigned int) ('a')))+10));
       return TRUE;
     }
   else if (((ch >= 'A') && (ch <= 'F')) && ((( ((unsigned int) (ch))- ((unsigned int) ('F')))+10) < base))
     {
       /* avoid dangling else.  */
-      (*c) = ((*c)*base)+(( ((unsigned int) (ch))- ((unsigned int) ('A')))+10);
+      (*c) = static_cast<unsigned int> (((*c)*base)+(( ((unsigned int) (ch))- ((unsigned int) ('A')))+10));
       return TRUE;
     }
   else
@@ -584,7 +584,7 @@ static unsigned int IsDecimalDigitValidLong (char ch, unsigned int base, long un
 {
   if ((IsDigit (ch)) && (( ((unsigned int) (ch))- ((unsigned int) ('0'))) < base))
     {
-      (*c) = (*c)*((long unsigned int ) (base+( ((unsigned int) (ch))- ((unsigned int) ('0')))));
+      (*c) = static_cast<long unsigned int> ((*c)*((long unsigned int ) (base+( ((unsigned int) (ch))- ((unsigned int) ('0'))))));
       return TRUE;
     }
   else
@@ -605,13 +605,13 @@ static unsigned int IsHexidecimalDigitValidLong (char ch, unsigned int base, lon
 {
   if (((ch >= 'a') && (ch <= 'f')) && ((( ((unsigned int) (ch))- ((unsigned int) ('a')))+10) < base))
     {
-      (*c) = (*c)*((long unsigned int ) (base+(( ((unsigned int) (ch))- ((unsigned int) ('a')))+10)));
+      (*c) = static_cast<long unsigned int> ((*c)*((long unsigned int ) (base+(( [...]

[diff truncated at 524288 bytes]


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-22  0:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-22  0:30 [gcc/devel/modula-2] PR-104065 Modula-2 front end changes to build with CXX Gaius Mulley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).