www.riscos.com Technical Support:
Acorn C/C++



ToANSI is a desktop tool which provides an easy interface to the ToANSI program that Acorn C/C++ installs in your computer's library. The ToANSI tool constructs command lines and passes them to the ToANSI program. ToANSI helps convert program source written in the PCC style of C to program source in the ANSI style of C. PCC is the UNIX Portable C Compiler, and closely follows K&R C, as defined by B Kernighan and D Ritchie in their book The C Programming Language.

ToANSI enables you to write (with care) programs that can be automatically converted between the PCC and ANSI dialects of C, hence assisting you in constructing easily portable programs. The associated tool ToPCC makes approximately the reverse translations to ToANSI. For more details of portability issues, see the chapter entitled Portability. The changes that ToANSI makes to C source are listed in the ToANSI C translation below.

ToANSI is one of the non-interactive desktop tools, its desktop user interface being provided by the FrontEnd module. It shares many common features with the other non-interactive tools. These common features are described in the General features of the accompanying Desktop Tools guide.

ToANSI C translation

ToANSI makes the following transformations to C source code or header text:

  • Function declarations with embedded comments are rewritten without the comment tokens. This reverses the action of ToPCC with regard to function declarations, rewriting

    type foo(/* args */);


    type foo(args);

    This transformation is one which requires care in the use of ToANSI, as it can result in invalid C being uncommented.

  • Function definitions of the form

    type foo(a1, a2) 
    type a1;
    type a2; 

    are rewritten as

    type foo(type a1, type a2)

  • A va_alist in the function definition is translated to


  • type foo() is rewritten as type foo(void).
  • VoidStar (what ToPCC replaces void * with) is left untouched, as if it is correctly typedef'd to something suitable, thereafter its use is correct in both PCC and ANSI C.
  • ToPCC rewrites unsigned and unsigned long constants using the typecasts (unsigned) and (unsigned long). ToANSI does not reverse this change, as this is not required for correct ANSI C.

Note that ToANSI performs only simple textual translations and is not able to reliably diagnose C syntax errors, which may produce surprising results, so it is best to use ToANSI only on code you already know compiles.

A note about Make

Since porting programs is usually a one-off process involving some experimentation, only direct use of ToANSI makes sense. You cannot use ToANSI from Make.

Starting ToANSI

To start the ToANSI tool, first open the AcornC_C++.Tools directory display, then double click on !ToANSI. Its icon appears on the icon bar:


Clicking Select on this icon, or dragging a source file from a directory display to this icon, brings up the SetUp dialogue box, from which you control the running of ToANSI:


ToANSI has hardly any options for its use, so its interface is simpler than most of the other Acorn C/C++ tools.

The File writable icon is for the name of the description file to be processed. If you displayed the SetUp dialogue box by clicking on the ToANSI icon bar icon, you will want to fill this in by dragging a source file from a directory display to this icon before running ToANSI.

Clicking Menu on the SetUp dialogue box brings up the ToANSI SetUp menu, which owing to the simplicity of ToANSI only has a single Command line item:


The icon bar menu

Clicking Menu on the ToANSI application icon on the icon bar gives access to the following options:


For a description of each option in the application menu see the chapter entitled General features of the accompanying Desktop Tools guide.

Example output

Running ToANSI displays any error messages in the standard text output window for non-interactive tools. If all goes well this window is empty:


As an example of using the tool ToANSI, open an empty SrcEdit text window and type the following example C source lines in it:

int foo(a, b)
float a;
double b;

Check that your Wimp$Scrap environment variable is set to a sensible file name, then save your new text file straight onto the ToANSI icon bar icon. Run ToANSI, then save the output text file straight onto the SrcEdit icon bar icon. The translated file looks like:

int foo(float a, double b)

Command line interface

For normal use you do not need to understand the syntax of the underlying ToANSI program's command line, as it is generated automatically for you from the SetUp dialogue box and menu settings.

The syntax of the ToANSI command line is:

toansi «options» «infile «outfile»»

options Options: the -d option describes ToANSI, and the -help option gives the command line syntax and options.
infile Filename of the input C source or header text file, which defaults to stdin.
outfile Filename of the output C source or header text file, which defaults to stdout.

© 3QD Developments Ltd 2013