2C(10.1)                                                 2C(10.1)

     NAME
          0c, 1c, 2c, 5c, 8c, kc, qc, vc - C compilers

     SYNOPSIS
          0c [ option ... ] [ file ... ]
          1c [ option ... ] [ file ... ]
          2c [ option ... ] [ file ... ]
          5c [ option ... ] [ file ... ]
          8c [ option ... ] [ file ... ]
          kc [ option ... ] [ file ... ]
          qc [ option ... ] [ file ... ]
          vc [ option ... ] [ file ... ]

     DESCRIPTION
          0c, 1c, 2c, 5c, 8c, kc, qc, and vc compile the named C files
          into MIPS-LE, MC68000, MC68020, ARM, i386, SPARC, PowerPC,
          and MIPS object files.  The compilers handle most prepro-
          cessing directives themselves; a complete preprocessor is
          available in cpp(10.1), which must be run separately.

          Let the first letter of the compiler name be O= 0, 1, 2, 5,
          8, k, q, or v.  The output object files end in .O.  The let-
          ter is also the prefix of related programs: Oa is the assem-
          bler, Ol is the loader.  Associated with each compiler is a
          string objtype= spim, 68000, 68020, arm, 386, sparc, power,
          or mips.

          Plan 9 conventionally sets the $objtype environment variable
          to the objtype string appropriate to the current machine's
          type.  Plan 9 also conventionally has /objtype directories,
          which contain among other things: include, for machine-
          dependent include files; lib, for public object code
          libraries; bin, for public programs; and mkfile, for precon-
          ditioning mk(10.1).

          For Inferno cross-compilation on all platforms, not just
          Plan 9, both $objtype and $OBJTYPE are set by every native
          kernel mkfile to correspond to the target processor type.
          The Inferno mkfiles also set the -I option appropriately to
          search the Inferno include directories, since the Plan 9
          defaults are inappropriate.

          The compiler options are:

          -o obj    Place output in file obj (allowed only if there is
                    just one input file).  Default is to take the last
                    element of the input file name, strip any trailing
                    .c, and append .O.

          -w        Print warning messages about unused variables,

     Page 1                       Plan 9             (printed 3/29/24)

     2C(10.1)                                                 2C(10.1)

                    etc.

          -B        Accept functions without a new-style ANSI C func-
                    tion prototype.  By default, the compilers reject
                    functions used without a defined prototype,
                    although ANSI C permits them.

          -Dname=def
          -Dname    Define the name to the preprocessor, as if by
                    `#define'.  If no definition is given, the name is
                    defined as `1'.

          -F        Warn when the elements of a format (eg, those used
                    by print) disagree with in type or size with the
                    corresponding parameter, or there is a mismatch in
                    number.

          -Idir     An `#include' file whose name does not begin with
                    slash or is enclosed in double quotes is always
                    sought first in the directory of the file argu-
                    ment.  If this fails, or the name is enclosed in
                    <>, it is then sought in directories named in -I
                    options, then in /sys/include, and finally in
                    /$objtype/include.

          -N        Suppress automatic registerization and optimiza-
                    tion.

          -S        Print an assembly language version of the object
                    code on standard output as well as generating the
                    .O file.

          -a        Instead of compiling, print on standard output
                    acid functions (see acid(10.1)) for examining
                    structures declared in the source files.

          -aa       Like -a except suppress information about struc-
                    tures declared in included header files.

          The compilers support several extensions to ANSI C:

          -    A structure or union may contain unnamed substructures
               and subunions.  The fields of the substructures or sub-
               unions can then be used as if they were members of the
               parent structure or union (the resolution of a name
               conflict is unspecified).  When a pointer to the outer
               structure or union is used in a context that is only
               legal for the unnamed substructure, the compiler pro-
               motes the type and adjusts the pointer value to point
               at the substructure.  If the unnamed structure or union
               is of a type with a tag name specified by a typedef
               statement, the unnamed structure or union can be

     Page 2                       Plan 9             (printed 3/29/24)

     2C(10.1)                                                 2C(10.1)

               explicitly referenced by <struct variable>.<tagname>.

          -    A structure value can be formed with an expression such
               as
                   (struct S){v1, v2, v3}
               where the list elements are values for the fields of
               struct S.

          -    Array initializers can specify the indices of the array
               in square brackets, as
                   int a[] = { [3] 1, [10] 5 };
               which initializes the third and tenth elements of the
               eleven-element array a.

          -    Structure initializers can specify the structure ele-
               ment by using the name following a period, as
                   int struct { int x; int y; } s = { .y 1, .x 5 };
               which initializes elements y and then x of the struc-
               ture s.

          -    A global variable can be dedicated to a register by
               declaring it extern register in all modules and
               libraries.

          -    A #pragma of the form
                   #pragma lib "libbio.a"
               records that the program needs to be loaded with file
               /$objtype/lib/libbio.a; such lines, typically placed in
               library header files, obviate the -l option of the
               loaders.  To help identify files in non-standard direc-
               tories, within the file names in the #pragmas the
               string $M represents the name of the architecture
               (e.g., mips) and $O represents its identifying charac-
               ter (e.g., v).

          -    Two #pragma requests to define rules for checking
               print-like formats (see the -F option above).  One
               #pragma tells for a given routine which argument is the
               format.  For example:
                   #pragma varargck argpos print 1
                   #pragma varargck argpos sprint 2
               say that print has a format as its first argument, and
               sprint has one as its second.  Another #pragma associ-
               ates format character sequences and types:
                  #pragma varargck type "lld" vlong
                  #pragma varargck type "lx" void*
                  #pragma varargck type "S" Rune*
               where the format characters are those following the %
               in the format (ignoring any preceding formatting
               flags).  Note the assumption that all formats arguments
               are compatible.  The system include files have appro-
               priate #pragma lines for the standard format elements

     Page 3                       Plan 9             (printed 3/29/24)

     2C(10.1)                                                 2C(10.1)

               and formatting functions.

          -    The C++ comment (// to end of line) is accepted as well
               as the normal convention of /* */.

          -    The compilers accept long long variables as a 64-bit
               type.  The standard header typedefs this to vlong.  The
               vlong runtime is slow.

     EXAMPLE
          For the 68020, produce a program prog from C files main.c
          and sub.c:

               2c -w main.c sub.c
               2l -o prog main.2 sub.2

     FILES
          /sys/include       host system area for machine-independent
                             #include directives.
          /$objtype/include  host system area for machine-dependent
                             #include directives.

     SOURCE
          /utils/cc        machine-independent part
          /utils/2c, etc.  machine-dependent part

     SEE ALSO
          2a(10.1), 2l(10.1), mk(10.1), nm(10.1), acid(10.1),

          Rob Pike, ``How to Use the Plan 9 C Compiler''

     BUGS
          The preprocessor only handles `#define', `#include',
          `#undef', `#ifdef', `#line', and `#ifndef'.  For a full ANSI
          preprocessor, use cpp(10.1) on the files first.

     Page 4                       Plan 9             (printed 3/29/24)