home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / SIMTEL / HITECH-C / Z80DOC.EXE / lha / z80doc.txt
Text File  |  1993-06-08  |  292KB  |  11,353 lines

  1.  
  2.        HI-TECH C USER'S MANUAL                                    i
  3.  
  4.        CONTENTS
  5.  
  6.  
  7.  
  8.        1. Introduction                                            1
  9.          1.1. Features                                            1
  10.          1.2. System Requirements                                 2
  11.          1.3. Using this Manual                                   2
  12.  
  13.        2. Getting Started                                         3
  14.  
  15.        3. Compiler Structure                                      5
  16.  
  17.        4. Operating Details                                       7
  18.  
  19.        5. Specific Features                                      13
  20.          5.1. ANSI C Standard Compatibility                      13
  21.          5.2. Type Checking                                      13
  22.          5.3. Member Names                                       13
  23.          5.4. Unsigned Types                                     14
  24.          5.5. Arithmetic Operations                              14
  25.          5.6. Structure Operations                               15
  26.          5.7. Enumerated Types                                   16
  27.          5.8. Initialization Syntax                              16
  28.          5.9. Function Prototypes                                17
  29.          5.10. Void and Pointer to Void                          18
  30.          5.11. Type qualifiers                                   19
  31.          5.12.                                                   20
  32.          5.13. Pragma Directives                                 20
  33.  
  34.        6. Machine Dependencies                                   21
  35.          6.1. Predefined Macros                                  21
  36.  
  37.        7. Error Checking and Reporting                           23
  38.  
  39.        8. Standard Libraries                                     25
  40.          8.1. Standard I/O                                       25
  41.          8.2. Compatibility                                      25
  42.          8.3. Libraries for Embedded Systems                     25
  43.          8.4. Binary I/O                                         26
  44.          8.5. Floating Point Library                             27
  45.  
  46.        9. Stylistic Considerations                               29
  47.          9.1. Member Names                                       29
  48.          9.2. Use of Int                                         30
  49.          9.3. Extern Declarations                                30
  50.  
  51.        10. Memory Models                                         31
  52.  
  53.        11. What Went Wrong                                       33
  54.  
  55.        12. Z80 Assembler Reference Manual                        35
  56.          12.1. Introduction                                      35
  57.          12.2. Usage                                             35
  58.          12.3. The Assembly Language                             36
  59.            12.3.1. Symbols                                       36
  60.              12.3.1.1. Temporary Labels                          37
  61.            12.3.2. Constants                                     37
  62.              12.3.2.1. Character Constants                       38
  63.  
  64.  
  65.  
  66.  
  67.  
  68.    ii                                    HI-TECH C USER'S MANUAL
  69.  
  70.          12.3.2.2. Floating Constants                        38
  71.          12.3.2.3. Opcode Constants                          38
  72.        12.3.3. Expressions                                   38
  73.          12.3.3.1. Operators                                 38
  74.          12.3.3.2. Relocatability                            39
  75.        12.3.4. Pseudo-ops                                    40
  76.          12.3.4.1. DEFB, DB                                  40
  77.          12.3.4.2. DEFF                                      41
  78.          12.3.4.3. DEFW                                      41
  79.          12.3.4.4. DEFS                                      41
  80.          12.3.4.5. EQU                                       41
  81.          12.3.4.6. DEFL                                      41
  82.          12.3.4.7. DEFM                                      42
  83.          12.3.4.8. END                                       42
  84.          12.3.4.9. COND, IF, ELSE, ENDC                      42
  85.          12.3.4.10. ELSE                                     42
  86.          12.3.4.11. ENDC                                     42
  87.          12.3.4.12. ENDM                                     43
  88.          12.3.4.13. PSECT                                    43
  89.          12.3.4.14. GLOBAL                                   43
  90.          12.3.4.15. ORG                                      44
  91.          12.3.4.16. MACRO                                    44
  92.          12.3.4.17. LOCAL                                    45
  93.          12.3.4.18. REPT                                     46
  94.        12.3.5. IRP and IRPC                                  47
  95.        12.3.6. Extended Condition Codes                      48
  96.      12.4. Assembler Directives                              48
  97.      12.5. Diagnostics                                       49
  98.      12.6. Z80/Z180/64180 Instruction Set                    50
  99.  
  100.    13. Linker Reference Manual                               69
  101.      13.1. Relocation and Psects                             69
  102.        13.1.1. Program Sections                              69
  103.        13.1.2. Local Psects and the Large Model              70
  104.      13.2. Global Symbols                                    70
  105.      13.3. Operation                                         71
  106.      13.4. Examples                                          74
  107.      13.5. Invoking the Linker                               74
  108.  
  109.    14. Librarian                                             75
  110.      14.1. The Library Format                                75
  111.      14.2. Using                                             75
  112.      14.3. Examples                                          76
  113.      14.4. Supplying Arguments                               77
  114.      14.5. Listing Format                                    77
  115.      14.6. Ordering of Libraries                             77
  116.      14.7. Error Messages                                    78
  117.  
  118.    15. Objtohex                                              79
  119.  
  120.    16. Cref                                                  83
  121.    APPENDIX 1 Error Messages                                 85
  122.  
  123.    APPENDIX 2 Standard Library Functions                     99
  124.  
  125.  
  126.    INDEX                                                    165
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.                             HI-TECH C COMPILER
  137.  
  138.                               User's Manual
  139.  
  140.                                 March 1989
  141.  
  142.  
  143.  
  144.  
  145.        1. Introduction
  146.  
  147.  
  148.             The HI-TECH C Compiler  is  a  set  of  software  which
  149.        translates  programs written in the C language to executable
  150.        machine code programs. Versions are available which  compile
  151.        programs  for  operation under the host operating system, or
  152.        which produce programs for  execution  in  embedded  systems
  153.        without an operating system.
  154.  
  155.        1.1. Features
  156.  
  157.             Some of HI-TECH C's features are:
  158.  
  159.             A single command will compile, assemble and link entire
  160.             programs.
  161.  
  162.             The compiler performs strong type checking  and  issues
  163.             warnings  about  various constructs which may represent
  164.             programming errors.
  165.  
  166.             The generated code is extremely small and fast in  exe-
  167.             cution.
  168.  
  169.             A full run-time library is  provided  implementing  all
  170.             standard C input/output and other functions.
  171.  
  172.             The source code for all run-time routines is provided.
  173.  
  174.             A powerful general purpose macro assembler is included.
  175.  
  176.             Programs may be generated to  execute  under  the  host
  177.             operating  system,  or  customized  for installation in
  178.             ROM.
  179.  
  180.                  PC-DOS/MS-DOS
  181.                  CP/M-86
  182.                  Concurrent DOS
  183.                  Atari ST
  184.                  Xenix
  185.                  Unix
  186.                  CP/M-80
  187.  
  188.  
  189.                          Table 1. Supported Hosts
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.    Page 2                               HI-TECH C USER'S MANUAL
  201.  
  202.    1.2. System Requirements
  203.  
  204.         The HI-TECH C Compilers  operate  under  the  operating
  205.    sytems  listed  in  table  1. Ensure that the version of the
  206.    compiler you have matches the system you have.  Note that in
  207.    general  you  must  have  a hard disk or two floppy disks on
  208.    your system (it is possible to use one floppy disk  of  800K
  209.    or  more).   A  hard disk is strongly recommended. Note that
  210.    the CP/M-80 native compiler does not have all  the  features
  211.    described  in  this manual, as it has not been upgraded past
  212.    V3.09 due to memory limitations.   The  Z80  cross  compiler
  213.    does  support  all of the features described here and can be
  214.    used to generate programs to execute under CP/M-80.
  215.  
  216.    1.3. Using this Manual
  217.  
  218.         The documentation supplied with the HI-TECH C  compiler
  219.    comprises  two  separate  manuals within the one binder. The
  220.    manual you are reading now covers all versions of  the  com-
  221.    piler  (reflecting  the  portable nature of the compiler). A
  222.    separate manual covers machine  dependent  aspects  of  your
  223.    compiler, e.g. installation.
  224.  
  225.         This  manual  assumes  you  are  familiar  with  the  C
  226.    language  already.  If you are not, you should have at least
  227.    one reference book covering C, of which a large  number  are
  228.    available  from most computer bookstores, e.g. "A Book on C"
  229.    by Kelley and Pohl. Other suitable texts are "Programming in
  230.    ANSI  C"  by  S. Kochan and "The C Programming Language", by
  231.    Kernighan and Ritchie. You should read the "Getting Started"
  232.    chapter  in  this  manual, and the "Installation" chapter in
  233.    the machine-specific manual.  This  will  provide  you  with
  234.    sufficient  information  to  work  through  the introductory
  235.    examples in the C reference you are using.
  236.  
  237.         Once you have a basic grasp  of  the  C  language,  the
  238.    remainder  of  this manual will provide you with information
  239.    to enable you to explore the more advanced aspects of C.
  240.  
  241.         Most of the manual covers all  implementations  of  the
  242.    HI-TECH  C  compiler.  A separate manual is provided for the
  243.    macro assembler  for  your  particular  machine,  and  other
  244.    machine-dependent information.
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.        HI-TECH C USER'S MANUAL                               Page 3
  267.  
  268.  
  269.        2. Getting Started
  270.  
  271.  
  272.             If using the compiler on a hard disk  system  you  will
  273.        need  to  install  the  compiler  before  using  it. See the
  274.        "Installation" chapter for more details.  If using a  floppy
  275.        disk  based system, in general you should have a copy of the
  276.        distribution disk #1 in drive A: and maintain your files  on
  277.        a disk in the B: drive. Again see the "Installation" chapter
  278.        for more information.
  279.  
  280.             main()
  281.             {
  282.                     printf("Hello, world\n");
  283.             }
  284.  
  285.  
  286.                          Fig. 1. Sample C Program
  287.  
  288.  
  289.             Before compiling your program it must be contained in a
  290.        file  with an extension (or file type, i.e. that part of the
  291.        name after the '.') of .C.  For example  you  may  type  the
  292.        program shown in fig. 1 into a file called HELLO.C. You will
  293.        need a text editor to do this.  Generally  any  text  editor
  294.        that can create a straight ASCII file (i.e. not a "word pro-
  295.        cessor" type file) will be suitable. If using  editors  such
  296.        as  Wordstar,  you should use the "non-document mode".  Once
  297.        you have the program in such a file all that is required  to
  298.        compile  it  is  to  issue  the  C  command, e.g. to compile
  299.        HELLO.C simply type the command
  300.  
  301.             C -V HELLO.C
  302.  
  303.        Cross compilers (i.e. compilers that operate on  one  system
  304.        but  produce  code for a separate target system) will have a
  305.        compiler driver named slightly differently, e.g. the  68HC11
  306.        cross compiler driver is called C68.
  307.  
  308.             If you are using a floppy disk based system (or a  CP/M
  309.        system)  it  may be necessary to specify where to find the C
  310.        command, e.g. if the C command is on a disk in drive A:  and
  311.        you are working on B:, type the command
  312.  
  313.             A:C -V HELLO.C
  314.  
  315.  
  316.             The compiler will issue a sign on message, then proceed
  317.        to execute the various passes of the compiler in sequence to
  318.        compile the program. If you are using a  floppy  disk  based
  319.        system  where the compiler will not fit on a single disk you
  320.        will be prompted to change disks whenever the compiler  can-
  321.        not  find  a  pass. In this case you should insert a copy of
  322.        the next distribution disk in drive A: and press RETURN.
  323.  
  324.             As each pass of the compiler is about to be executed, a
  325.        command  line  to that pass will be displayed on the screen.
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.    Page 4                               HI-TECH C USER'S MANUAL
  333.  
  334.    This is because the -V option has been used. This stands for
  335.    Verbose,  and  had  it  not been given the compilation would
  336.    have been silent except for the sign on message.  Error mes-
  337.    sages can be redirected to a file by using the standard out-
  338.    put redirection notation, e.g. > _s_o_m_e_f_i_l_e.
  339.  
  340.         After completion of compilation, the compiler will exit
  341.    to  command  level.   You will notice that several temporary
  342.    files created during compilation will have been deleted, and
  343.    all  that  will be left on the disk (apart from the original
  344.    source file HELLO.C) will be an executable file. The name of
  345.    this executable file will be HELLO.EXE for MS-DOS, HELLO.PRG
  346.    for the Atari ST, HELLO.COM for CP/M-80  and  HELLO.CMD  for
  347.    CP/M-86.  For cross compilers it will be called HELLO.HEX or
  348.    HELLO.BIN depending on the default  output  format  for  the
  349.    particular compiler.  To execute this program, simply type
  350.  
  351.         HELLO
  352.  
  353.    and you should be rewarded with the message "Hello,  world!"
  354.    on  your screen.  If you are using a cross compiler you will
  355.    need to put the program into EPROM or download to the target
  356.    system  to  execute  it. Cross compilers do not produce pro-
  357.    grams executable on the host system.
  358.  
  359.         There are other options that may be  used  with  the  C
  360.    command,  but  you will not need to use them unless you wish
  361.    to do so. If you are new to the C language it will be advis-
  362.    able  to enter and compile a few simple programs (e.g. drawn
  363.    from one of the C reference texts  mentioned  above)  before
  364.    exploring other capabilities of the HI-TECH C compiler.
  365.  
  366.         There is one exception to the above; if you  compile  a
  367.    program  which  uses  floating  point  arithmetic (i.e. real
  368.    numbers) you MUST specify to the compiler that the  floating
  369.    point  library  should  be searched. This is done with a -LF
  370.    option at the END of the command line, e.g.
  371.  
  372.         C -V FLOAT.C -LF
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.        HI-TECH C USER'S MANUAL                               Page 5
  399.  
  400.  
  401.        3. Compiler Structure
  402.  
  403.  
  404.             The compiler is made up of several passes; each pass is
  405.        implemented  as  a  separate  program.  Note  that it is not
  406.        necessary for the user to invoke each pass individually,  as
  407.        the  C  command runs each pass automatically.  Note that the
  408.        machine dependent passes are named differently for each pro-
  409.        cessor,  for example those with 86 in their name are for the
  410.        8086 and those with 68K in their name are for the 68000.
  411.  
  412.             The passes are:
  413.  
  414.        CPP  The pre-processor - handles macros and conditional com-
  415.             pilation
  416.  
  417.        P1   The syntax and  semantic  analysis  pass.  This  writes
  418.             intermediate code for the code generator to read.
  419.  
  420.        CGEN, CG86 etc.
  421.             The code generator - produces assembler code.
  422.  
  423.        OPTIM, OPT86 etc.
  424.             The code improver - may optionally be omitted, reducing
  425.             compilation  time at a cost of larger, slower code pro-
  426.             duced.
  427.  
  428.        ZAS, AS86 etc.
  429.             The assembler - in fact a general purpose macro  assem-
  430.             bler.
  431.  
  432.        LINK
  433.             The link editor - links object files with libraries.
  434.  
  435.        OBJTOHEX
  436.             This utility converts  the  output  of  LINK  into  the
  437.             appropriate  executable  file format (e.g. .EXE or .PRG
  438.             or .HEX).
  439.  
  440.             The passes are invoked in the order  given.  Each  pass
  441.        reads  a  file  and writes a file for its successor to read.
  442.        Each intermediate file has a particular format; CPP produces
  443.        C code without the macro definitions and with uses of macros
  444.        expanded; P1 writes a file containing a program in an inter-
  445.        mediate code; CGEN translates this to assembly code; AS pro-
  446.        duces object code, a binary  format  containing  code  bytes
  447.        along  with relocation and symbol information.  LINK accepts
  448.        object files  and  libraries  of  object  files  and  writes
  449.        another  object file; this may be in absolute form or it may
  450.        preserve relocation information and be input to another LINK
  451.        command.
  452.  
  453.             There are also other utility programs:
  454.  
  455.        LIBR
  456.             Creates and maintains libraries of object modules
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.    Page 6                               HI-TECH C USER'S MANUAL
  465.  
  466.    CREF
  467.         Produces cross-reference listings  of  C  or  assembler
  468.         programs.
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.        HI-TECH C USER'S MANUAL                               Page 7
  531.  
  532.  
  533.        4. Operating Details
  534.  
  535.  
  536.             HI-TECH C was designed for ease of use; a  single  com-
  537.        mand will compile, assemble and link a C program. The syntax
  538.        of the C command is as follows:
  539.  
  540.             C [ options ] files [ libraries ]
  541.  
  542.             The options are zero or more options,  each  consisting
  543.        of  a dash ('-'), a single key letter, and possibly an argu-
  544.        ment following the key letter with no intervening space. The
  545.        files  are  one  or  more  C  source files, assembler source
  546.        files, or object  files.  Libraries  may  be  zero  or  more
  547.        library  names, or the abbreviated form -lname which will be
  548.        expanded to the library name libname.lib.
  549.  
  550.             The C command will,  as  determined  by  the  specified
  551.        options,  compile  any  C  source files given, assemble them
  552.        into object code unless requested  otherwise,  assemble  any
  553.        assembler  source  files specified, then link the results of
  554.        the assemblies with any object or library files specified.
  555.  
  556.             If the C command is invoked without arguments, then  it
  557.        will  prompt  for a command line to be entered. This command
  558.        line may be extended by typing a backslash ('\') on the  end
  559.        of  the  line.  Another  line will then be requested. If the
  560.        standard input of the command is from a file (e.g. by typing
  561.        C  <  afile)  then  the command lines will be read from that
  562.        file. Within the file more than one line  may  be  given  if
  563.        each line but the last ends with a backslash. Note that this
  564.        mechanism does not work in MS-DOS batch file, i.e. the  com-
  565.        mand  file for the C command must be a separate file. MS-DOS
  566.        has no mechanism for providing long command lines  or  stan-
  567.        dard input from inside a batch file.
  568.  
  569.             The options recognized by the C command are as follows:
  570.  
  571.        -S   Leave the results of compilation  of  any  C  files  as
  572.             assembler output. C source code will be interspersed as
  573.             comments in the assembler code.
  574.  
  575.        -C   Leave the results of all  compiles  and  assemblies  as
  576.             object files; do not invoke the linker. This allows the
  577.             linker to be invoked separately, or via the  C  command
  578.             at a later stage.
  579.  
  580.        -CR  Produce a cross reference listing. -CR on its own  will
  581.             leave  the  raw  cross-reference  information in a tem-
  582.             porary file, allowing the user to run CREF  explicitly,
  583.             while  supplying  a  file  name,  e.g. -CR_F_R_E_D._C_R_F will
  584.             cause CREF to be invoked to process the raw information
  585.             into the specified file, in this case _F_R_E_D._C_R_F.
  586.  
  587.        -CPM
  588.             For the Z80 cross compiler only,  produce  CP/M-80  COM
  589.             files.   Unless the -CPM option is given, the Z80 cross
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.    Page 8                               HI-TECH C USER'S MANUAL
  597.  
  598.         compiler uses the ROM runtime startoff module and  pro-
  599.         duces  hex  or  binary  images.   If the -CPM option is
  600.         given, CP/M-80 runtime startoff code is linked used and
  601.         a CP/M-80 COM file is produced.
  602.  
  603.    -O   Invoke  the  optimizer  on  all  compiled  code;   also
  604.         requests the assembler to perform jump optimization.
  605.  
  606.    -O_O_U_T_F_I_L_E
  607.         Specify a name for the executable file to  be  created.
  608.         By  default the name for the executable file is derived
  609.         from the name of the first source or object file speci-
  610.         fied to the compiler. This option allows the default to
  611.         be overridden. If no dot ('.')  appears  in  the  given
  612.         file  name, an extension appropriate for the particular
  613.         operating system will be added, e.g. -O_F_R_E_D  will  gen-
  614.         erate a file _F_R_E_D._E_X_E on MS-DOS or _F_R_E_D._C_M_D on CP/M-86.
  615.         For cross compilers this  also  provides  a  means  for
  616.         specifying the output format, e.g. specifying an output
  617.         file _P_R_O_G._B_I_N will make the compiler generate a  binary
  618.         file, while specifying _P_R_O_G._H_E_X will make it generate a
  619.         hexadecimal file.
  620.  
  621.    -V   Verbose: each step of the compilation will be echoed as
  622.         it is executed.
  623.  
  624.    -I   Specify an additional filename prefix to use in search-
  625.         ing  for #include files. For CP/M the default prefix is
  626.         0:A: (user number 0, disk  drive  A).  For  MS-DOS  the
  627.         default  prefix is A:\HITECH\. Under Unix and Xenix the
  628.         default prefix is /usr/hitech/include/.  Note  that  on
  629.         MS-DOS  a  trailing  backslash  must be appended to any
  630.         directory  name  given  as  an  argument  to  -I;  e.g.
  631.         -I\FRED\  not  -I\FRED.  Under  Unix  a  trailing slash
  632.         should be added.
  633.  
  634.    -D   Define a symbol to the preprocessor:  e.g.  -DCPM  will
  635.         define the symbol CPM as though via #define CPM 1.
  636.  
  637.    -U   Undefine a pre-defined symbol. The complement of -D.
  638.  
  639.    -F   Request the linker to produce a symbol  file,  for  use
  640.         with the debugger.
  641.  
  642.    -R   For the Z80 CP/M compiler only this option will link in
  643.         code  to  perform command line I/O redirection and wild
  644.         card expansion in file names.  See the  description  of
  645.         _getargs()  in  appendix 5 for details of the syntax of
  646.         the redirections.
  647.  
  648.    -X   Strip local symbols from any files compiled,  assembled
  649.         or linked. Only global symbols will remain.
  650.  
  651.    -M   Request the linker to produce a link map.
  652.  
  653.    -A   This option, for the Z80 only, will cause the  compiler
  654.         to  produce  an executable program that will, on execu-
  655.         tion, self-relocate  itself  to  the  top  of  the  TPA
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.        HI-TECH C USER'S MANUAL                               Page 9
  663.  
  664.             (Transient  Program  Area).  This allows the writing of
  665.             programs which may execute other programs  under  them-
  666.             selves.   Note that a program compiled in such a manner
  667.             will not automatically reset the bdos address at  loca-
  668.             tion 6 in order to protect itself. This must be done by
  669.             the program itself.
  670.  
  671.             For cross compilers this provides a way  of  specifying
  672.             to  the  linker the addresses that the compiled program
  673.             is to be  linked  at.  The  format  of  the  option  is
  674.             -A_R_O_M_A_D_R,_R_A_M_A_D_R,_R_A_M_S_I_Z_E.  _R_O_M_A_D_R  is the address of the
  675.             ROM in the system, and is where the executable code and
  676.             initialized  data  will  be placed. _R_A_M_A_D_R is the start
  677.             address of RAM, and is where  the  bss  psect  will  be
  678.             placed,  i.e.  uninitialized data.  _R_A_M_S_I_Z_E is the size
  679.             of RAM available to the program, and is used to set the
  680.             top of the stack.
  681.  
  682.             For the 6801/6301/68HC11 compiler, the -A option  takes
  683.             a  fourth  value  which  is  the address of a four byte
  684.             direct page area called ctemp which the  compiled  code
  685.             uses as a scratch pad.  If the ctemp address is omitted
  686.             from the -A option, it defaults to address 0.  Normally
  687.             this  will  be  acceptable,  however some 6801 variants
  688.             (like the 6303) have memory mapped I/O ports at address
  689.             0 and start their direct page RAM at address $80.
  690.  
  691.             For the large memory model of the 8051 compiler, the -A
  692.             option  takes  the form -A_R_O_M_A_D_R,_I_N_T_R_A_M,_E_X_T_R_A_M,_E_X_T_S_I_Z_E.
  693.             _R_O_M_A_D_R is the address of ROM in the system.  _I_N_T_R_A_M  is
  694.             the  start  address  of  internal RAM, and is where the
  695.             rbss psect will be placed.   The  8051  internal  stack
  696.             will  start after the end of the rbss psect.  _E_X_T_R_A_M is
  697.             the start address of external RAM, and is where the bss
  698.             psect  will be placed.  _E_X_T_S_I_Z_E is the size of external
  699.             RAM available to the program, and is used  to  set  the
  700.             top of the external stack.
  701.  
  702.        -B   For compilers  which  support  more  than  one  "memory
  703.             model",  this  option  is  used  to select which memory
  704.             model code is to be generated for.  The format of  this
  705.             option is -Bx where x is one or more letters specifying
  706.             which memory model to use.  For the 8086,  this  option
  707.             is  used  to  select  which  one  of five memory models
  708.             (Tiny, Small, Medium, Compact or Large) is to be used.
  709.  
  710.             For the 8051 compiler  this  this  option  is  used  to
  711.             select  which  one  of  the three memory models (Small,
  712.             Medium or Large) is to be used.  For the 8051  compiler
  713.             only,  this  option  can  also be used to select static
  714.             allocation of _a_u_t_o variables by appending an A  to  the
  715.             end  of  the -B option.  For example, -Bsa would select
  716.             small model with static allocation  of  all  variables,
  717.             while -Bm would select medium model with _a_u_t_o variables
  718.             dynamically allocated on the stack.
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.    Page 10                              HI-TECH C USER'S MANUAL
  729.  
  730.    -E   By default the 8086 compiler will initialize  the  exe-
  731.         cutable  file  header  to request a 64K data segment at
  732.         run time. This may be overridden by the -E  option.  It
  733.         takes  an  argument (usually in hexadecimal representa-
  734.         tion) which is the number of BYTES (not paragraphs)  to
  735.         be  allocated  to  the program at run time. For example
  736.         -E0ffff0h will request a megabyte. Since this much will
  737.         not be available, the operating system will allocate as
  738.         much as it can.
  739.  
  740.    -W   This options sets the warning level, i.e. it determines
  741.         how  picky the compiler is about legal but dubious type
  742.         conversions etc. -W0 will allow  all  warning  messages
  743.         (default),   -W1  will  suppress  the  message  "Func()
  744.         declared implicit int". -W3 is recommended for  compil-
  745.         ing  code  originally  written with other, less strict,
  746.         compilers. -W9 will suppress all warning messages.
  747.  
  748.    -H   This option  generates  a  symbol  file  for  use  with
  749.         debuggers.  The  format of the symbol file is described
  750.         elsewhere. The default  name  of  the  symbol  file  is
  751.         _l._s_y_m.  An  alternate  name  may  be  specfied with the
  752.         option, e.g. -H_s_y_m_f_i_l_e._a_b_c.
  753.  
  754.    -G   Like -H, -G also generates a symbol file, but one  that
  755.         contains  line and file number information for a source
  756.         level debugger. Like -H a file name may  be  specified.
  757.         When  used in conjunction with -O, only partial optimi-
  758.         zation  will  be  performed  to  avoid  confusing   the
  759.         debugger.
  760.  
  761.    -P   Execution profiling is available  on  native  compilers
  762.         running  under  DOS,  CP/M-86 and on the Atari ST. This
  763.         option generates code to turn  on  execution  profiling
  764.         when  the  program  is  run. A -H option should also be
  765.         specified to provide a symbol table  for  the  profiler
  766.         EPROF.
  767.  
  768.    -Z   For version 5.xx compilers only, the -Z option is  used
  769.         to  select  global  optimization of the code generated.
  770.         For the 8086 and 6801/6301/68HC11  compilers  the  only
  771.         valid  -Z  option  is  -Zg.  For the 8051 compiler, the
  772.         valid -Z options are -Zg which invokes global optimiza-
  773.         tion,  -Zs  which  optimizes  for  space, and -Zf which
  774.         optimizes for speed.  The s and f options may  be  used
  775.         with  the  g option, thus the options -Zgf and -Zgs are
  776.         valid.   Speed  and  space  optimization  are  mutually
  777.         exclusive,  i.e.  the  s  and  f options cannot be used
  778.         together.
  779.  
  780.    -1   For the 8086 compiler only, request the  generation  of
  781.         code which takes advantage of the extra instructions of
  782.         the 80186 processor. A program compiled  with  -1  will
  783.         not execute on an 8086 or 8088 processor. For the 68000
  784.         compiler, generate instructions for the  68010  proces-
  785.         sor.
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.        HI-TECH C USER'S MANUAL                              Page 11
  795.  
  796.        -2   Like -1 but for the 80286 and 68020.
  797.  
  798.        -11  For the 6801/HC11 compiler, this  option  will  request
  799.             generation  of instructions specific to the 68HC11 pro-
  800.             cessor.
  801.  
  802.        -6301
  803.             For the 6801/HC11 compiler, this  option  will  request
  804.             generation  of  instructions  specific to the 6301/6303
  805.             processors.
  806.  
  807.             Some examples of the use of the C command are:
  808.  
  809.        c prog.c
  810.  
  811.        c -mlink.map prog.c x.obj -lx
  812.  
  813.        c -S prog.c
  814.  
  815.        c -O -C -CRprog.crf prog.c prog2.c
  816.  
  817.        c -v -Oxfile.exe afile.obj anfile.c -lf
  818.  
  819.  
  820.             Upper and lower case has been used in the  above  exam-
  821.        ples for emphasis: the compiler does not distinguish between
  822.        cases, although arguments specifying  names,  e.g.  -D,  are
  823.        inherently case sensitive.
  824.  
  825.             Taking the above examples in order; the first  compiles
  826.        and  links  the  C  source  file  prog.c with the standard C
  827.        library. The second example will compile the file prog.c and
  828.        link it with the object file x.obj and the library libx.lib;
  829.        a link map will be written to the file link.map.
  830.  
  831.             The third example compiles the file prog.c, leaving the
  832.        assembler  output  in  a  file prog.as. It does not assemble
  833.        this file or invoke the linker.  The next  example  compiles
  834.        both  prog.c  and  prog2.c,  invoking  the optimizer on both
  835.        files, but does not perform any linking. A  cross  reference
  836.        listing will be left in the file _p_r_o_g._c_r_f.
  837.  
  838.             The last example pertains to the 8086  version  of  the
  839.        compiler,  It runs the compiler with the verbose option, and
  840.        will cause anfile.c to be compiled without  optimization  to
  841.        object   code,   yielding  anfile.obj,  then  afile.obj  and
  842.        anfile.obj will be linked together with the  floating  point
  843.        library  (from  the  -LF option) and the standard library to
  844.        yield the executable program  xfile.exe  (assuming  this  is
  845.        performed  on an MS-DOS system).  One would expect this pro-
  846.        gram to use floating point, if  it  did  not  then  the  -LF
  847.        option would have been required.
  848.  
  849.             If more than one C or assembler source file is given to
  850.        the  C command, the name of each file will be printed on the
  851.        console as it is processed.  If any fatal errors occur  dur-
  852.        ing  the  compilation  or  assembly of source files, further
  853.        source files will be processed, but the linker will  not  be
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.    Page 12                              HI-TECH C USER'S MANUAL
  861.  
  862.    invoked.
  863.  
  864.  
  865.         Other commands which may be issued by the user,  rather
  866.    than automatically by the C command, are:
  867.  
  868.    ZAS  The Z80 assembler.
  869.  
  870.    AS86
  871.         The 8086 assembler.
  872.  
  873.    LINK
  874.         The linker
  875.  
  876.    LIBR
  877.         The library maintainer
  878.  
  879.    OBJTOHEX
  880.         Object to hex converter
  881.  
  882.    CREF
  883.         Cross reference generator.
  884.  
  885.         In general, these commands accept the same type of com-
  886.    mand line as the C command, i.e. zero or more options (indi-
  887.    cated by a leading '-') followed by one or more  file  argu-
  888.    ments.  If  the  linker  or the librarian is invoked with no
  889.    arguments, it wll prompt for a  command  line.  This  allows
  890.    command  lines  of more than 128 bytes to be entered.  Input
  891.    may also be taken from a file by using the redirection capa-
  892.    blities  (see  _getargs()  in the library function listing).
  893.    See the discussion above of the C command.   These  commands
  894.    are described in further detail in their respective manuals.
  895.  
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.        HI-TECH C USER'S MANUAL                              Page 13
  927.  
  928.  
  929.        5. Specific Features
  930.  
  931.  
  932.             The HI-TECH C compiler has a number of features,  which
  933.        while  largely compatible with other C compilers, contribute
  934.        to more reliable programming methods.
  935.  
  936.        5.1. ANSI C Standard Compatibility
  937.  
  938.             At the time of writing the Draft ANSI Standard for  the
  939.        C Language was at an advanced stage, though not yet an offi-
  940.        cial standard. Accordingly it is not possible to claim  com-
  941.        pliance  with  that standard, however HI-TECH C includes the
  942.        majority of the new and altered features in the  draft  ANSI
  943.        standard.  Thus  it  is in the sense that most people under-
  944.        stand it "ANSI compatible".
  945.  
  946.        5.2. Type Checking
  947.  
  948.             Previous C compilers have adopted  a  lax  approach  to
  949.        type  checking.  This  is  typified  by the Unix C compiler,
  950.        which allows almost arbritary mixing  of  types  in  expres-
  951.        sions. The HI-TECH C compiler performs much more strict type
  952.        checking, although in most cases only warning  messages  are
  953.        issued,  allowing  compilation  to proceed if the user knows
  954.        that the errors are harmless. This would occur, for example,
  955.        when  an  integer  value was assigned to a pointer variable.
  956.        The generated code would almost certainly be what  the  user
  957.        intended,  however if in fact it represented an error in the
  958.        source code, the user is prompted to check  and  correct  it
  959.        where necessary.
  960.  
  961.        5.3. Member Names
  962.  
  963.             In early C compilers member names in  different  struc-
  964.        tures were required to be distinct except under certain cir-
  965.        cumstances. HI-TECH C, like most recent  implementations  of
  966.        C, allows member names in different structures and unions to
  967.        overlap.  A member name is recognized only in the context of
  968.        an  expression  whose type is that of the structure in which
  969.        the member is defined.  In practice this means that a member
  970.        name  will  be recognized only to the right of a '.' or '->'
  971.        operator, where the expression to the left of  the  operator
  972.        is  of  type  structure  or pointer to structure the same as
  973.        that in which the member name was declared.  This  not  only
  974.        allows  structure  names  to  be re-used without conflict in
  975.        more than one structure, it permits strict checking  of  the
  976.        usage  of  members; a common error with other C compilers is
  977.        the use of a member name with a  structure  pointer  of  the
  978.        wrong type, or worse with a variable which is a pointer to a
  979.        simple type.
  980.  
  981.             There is however an escape from this,  where  the  user
  982.        desires to use as a structure pointer something which is not
  983.        declared as such. This is via the use  of  a  typecast.  For
  984.        example, suppose it is desired to access a memory-mapped i/o
  985.        device, consisting of several  registers.  The  declarations
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.    Page 14                              HI-TECH C USER'S MANUAL
  993.  
  994.    and use may look something like the code fragment in fig. 2.
  995.  
  996.    struct io_dev
  997.    {
  998.            short   io_status;    /* status */
  999.            char    io_rxdata;    /* rx data */
  1000.            char    io_txdata;    /* tx data */
  1001.    };
  1002.  
  1003.    #define RXRDY   01           /* rx ready */
  1004.    #define TXRDY   02           /* tx ready */
  1005.  
  1006.    /* define the (absolute) device address */
  1007.  
  1008.    #define DEVICE  ((struct io_dev *)0xFF00)
  1009.  
  1010.    send_byte(c)
  1011.    char c;
  1012.    {
  1013.            /* wait till transmitter ready */
  1014.            while(!(DEVICE->io_status & TXRDY))
  1015.                    continue;
  1016.            /* send the data byte */
  1017.            DEVICE->io_txdata = c;
  1018.    }
  1019.  
  1020.           Fig. 2. Use of Typecast on an Absolute Address
  1021.  
  1022.  
  1023.         In this example, the device in question has  a  16  bit
  1024.    status  port,  and  two 8 bit data ports. The address of the
  1025.    device (i.e. the address of its status  port)  is  given  as
  1026.    (hex)0FF00.  This address is typecast to the required struc-
  1027.    ture pointer type to enable  use  of  the  structure  member
  1028.    names.  The  code generated by this will use absolute memory
  1029.    references to access the device, as required.
  1030.  
  1031.         Some examples of right and wrong usage of member  names
  1032.    are shown in fig. 3.
  1033.  
  1034.    5.4. Unsigned Types
  1035.  
  1036.         HI-TECH C implements unsigned versions of all  integral
  1037.    types;  i.e.   unsigned  char,  short,  int and long.  If an
  1038.    unsigned quantity is shifted right, the shift will  be  per-
  1039.    formed  as  a  logical  shift,  i.e. bringing zeros into the
  1040.    rightmost bits. Similarly right shifts of a signed  quantity
  1041.    will sign extend the rightmost bits.
  1042.  
  1043.    5.5. Arithmetic Operations
  1044.  
  1045.         On machines where arithmetic  operations  may  be  per-
  1046.    formed   more  efficiently  in  lengths  shorter  than  int,
  1047.    operands shorter than int will not be extended to int length
  1048.    unless necessary.
  1049.  
  1050.         For example, if two characters are added and the result
  1051.    stored  into  another  character,  it  is  only necessary to
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.        HI-TECH C USER'S MANUAL                              Page 15
  1059.  
  1060.  
  1061.        struct fred
  1062.        {
  1063.              char      a;
  1064.              int       b;
  1065.        }     s1, * s2;
  1066.  
  1067.        struct bill
  1068.        {
  1069.                float   c;
  1070.                long    b;
  1071.        }       x1, * x2;
  1072.  
  1073.        main()
  1074.        {
  1075.                /* wrong - c is not a member of fred */
  1076.                s1.c = 2;
  1077.  
  1078.                /* correct */
  1079.                s1.a = 2;
  1080.  
  1081.                /* wrong - s2 is a pointer */
  1082.                s2.a = 2;
  1083.  
  1084.                /* correct */
  1085.                x2->b = 24L;
  1086.  
  1087.                /* right, but note type conversion
  1088.                        from long to int */
  1089.                s2->b = x2->b;
  1090.        }
  1091.  
  1092.                      Fig. 3. Examples of Member Usage
  1093.  
  1094.        perform arithmetic in 8 bits, since any  overflow  into  the
  1095.        top  8 bits will be lost. However, if the sum of two charac-
  1096.        ters is stored into an int, the addition should be  done  in
  1097.        16 bits to ensure the correct result.
  1098.  
  1099.             In accordance with the draft ANSI standard,  operations
  1100.        on  float rather than double quantities will be performed in
  1101.        the shorter precision rather than being converted to  double
  1102.        precision then back again.
  1103.  
  1104.        5.6. Structure Operations
  1105.  
  1106.             HI-TECH C implements structure  assignments,  structure
  1107.        arguments  and structure-valued functions in their full gen-
  1108.        erality. The example in fig. 4 is  a  function  returning  a
  1109.        structure. Some legal (and illegal) uses of the function are
  1110.        also shown.
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.    Page 16                              HI-TECH C USER'S MANUAL
  1125.  
  1126.  
  1127.    struct bill
  1128.    {
  1129.            char    a;
  1130.            int     b;
  1131.    }
  1132.    afunc()
  1133.    {
  1134.            struct bill     x;
  1135.  
  1136.            return x;
  1137.    }
  1138.  
  1139.    main()
  1140.    {
  1141.            struct bill     a;
  1142.  
  1143.            a = afunc();            /* ok */
  1144.            pf("%d", afunc().a);    /* ok */
  1145.  
  1146.            /* illegal, afunc() cannot be assigned
  1147.                    to, therefore neither can
  1148.                    afunc().a */
  1149.            afunc().a = 1;
  1150.  
  1151.            /* illegal, same reason */
  1152.            afunc().a++;
  1153.    }
  1154.  
  1155.        Fig. 4. Example of a Function Returning a Structure
  1156.  
  1157.    5.7. Enumerated Types
  1158.  
  1159.         HI-TECH C supports enumerated types;  these  provide  a
  1160.    structured way of defining named constants.
  1161.  
  1162.         The uses of enumerated types are more  restricted  than
  1163.    that  allowed by the Unix C compiler, yet more flexible than
  1164.    permitted  by  LINT.  In  particular,   an   expression   of
  1165.    enumerated type may be used to dimension arrays, as an array
  1166.    index or as the operand of a switch  statement.   Arithmetic
  1167.    may  be  performed  on enumerated types, and enumerated type
  1168.    expressions may be compared, both for equality and with  the
  1169.    relation  operators.  An example of the use of an enumerated
  1170.    type is given in fig. 5.
  1171.  
  1172.    5.8. Initialization Syntax
  1173.  
  1174.         Kernighan and Ritchie in "The C  Programming  Language"
  1175.    state  that  pairs of braces may be omitted from an initial-
  1176.    izer in certain contexts; the draft ANSI  standard  provides
  1177.    that  a  conforming C program must either include all braces
  1178.    in an initializer, or leave them all out. HI-TECH  C  allows
  1179.    any  pairs  of braces to be omitted providing that the front
  1180.    end of the compiler can determine the  size  of  any  arrays
  1181.    being  initialized, and providing that there is no ambiguity
  1182.    as to which braces have been omitted. To avoid ambiguity  if
  1183.    any  pairs of braces are present then any braces which would
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.        HI-TECH C USER'S MANUAL                              Page 17
  1191.  
  1192.  
  1193.        /* a represents 0, b -> 1 */
  1194.        enum fred { a, b, c = 4 };
  1195.  
  1196.        main()
  1197.        {
  1198.                enum fred       x, y, z;
  1199.  
  1200.                x = z;
  1201.                if(x < z)
  1202.                        func();
  1203.                x = (enum fred)3;
  1204.                switch(z) {
  1205.                case a:
  1206.                case b:
  1207.                default:
  1208.                }
  1209.        }
  1210.  
  1211.                     Fig. 5. Use of an Enumerated Type
  1212.  
  1213.        enclose those braces must also be present. The compiler will
  1214.        complain  ("initialization  syntax")  if  any  ambiguity  is
  1215.        present.
  1216.  
  1217.        5.9. Function Prototypes
  1218.  
  1219.             A new feature of C included in the proposed ANSI for C,
  1220.        known  as "function prototypes", provides C with an argument
  1221.        checking facility, i.e. it allows the compiler to  check  at
  1222.        compile  time  that  actual arguments supplied to a function
  1223.        invocation  are  consistent  with  the   formal   parameters
  1224.        expected  by the function. The feature allows the programmer
  1225.        to include in a function  declaration  (either  an  external
  1226.        declaration or an actual definition) the types of the param-
  1227.        eters to that function.   For  example,  the  code  fragment
  1228.        shown in fig. 6 shows two function prototypes.
  1229.  
  1230.             void fred(int, long, char *);
  1231.  
  1232.             char *
  1233.             bill(int a, short b, ...)
  1234.             {
  1235.                     return a;
  1236.             }
  1237.  
  1238.                        Fig. 6. Function Prototypes
  1239.  
  1240.  
  1241.             The first prototype is an external declaration  of  the
  1242.        function  _f_r_e_d(),  which  accepts  one integer argument, one
  1243.        long argument, and one argument which is a pointer to  char.
  1244.        Any  usage  of  _f_r_e_d() while the prototype declaration is in
  1245.        scope will cause the actual parameters  to  be  checked  for
  1246.        number  and  type  against  the  prototype, e.g. if only two
  1247.        arguments were supplied or an integral  value  was  supplied
  1248.        for the third argument the compiler would report an error.
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.    Page 18                              HI-TECH C USER'S MANUAL
  1257.  
  1258.         In the second example, the function _b_i_l_l() expects  two
  1259.    or more arguments. The first and second will be converted to
  1260.    int and short respectively, while the remainder (if present)
  1261.    may  be  of any type. The ellipsis symbol (...) indicates to
  1262.    the compiler that zero or more arguments  of  any  type  may
  1263.    follow the other arguments. The ellipsis symbol must be last
  1264.    in the argument list, and may not appear as the  only  argu-
  1265.    ment in a prototype.
  1266.  
  1267.         All prototypes for a function must agree exactly,  how-
  1268.    ever  it  is legal for a definition of a function in the old
  1269.    style,  i.e.  with  just  the  parameter  names  inside  the
  1270.    parentheses,  to follow a prototype declaration provided the
  1271.    number and type of the arguments agree. In this case  it  is
  1272.    essential  that  the  function definition is in scope of the
  1273.    prototype declaration.
  1274.  
  1275.         Access to unspecified arguments  (i.e.  arguments  sup-
  1276.    plied where an ellipsis appeared in a prototype) must be via
  1277.    the macros defined  in  the  header  file  <stdarg.h>.  This
  1278.    defines the macros _v_a__s_t_a_r_t, _v_a__a_r_g and _v_a__e_n_d. See _v_a__s_t_a_r_t
  1279.    in the library function listing for more information.
  1280.  
  1281.         NOTE that is is a grave error to use a  function  which
  1282.    has  an  associated  prototype  unless  that prototype is in
  1283.    scope, i.e. the prototype MUST be declared  (possibly  in  a
  1284.    header  file)  before  the  function is invoked.  Failure to
  1285.    comply with this rule may result in strange behaviour of the
  1286.    program.  HI-TECH  C  will  issue a warning message ("func()
  1287.    declared  implicit  int")  whenever  a  function  is  called
  1288.    without  an  explicit  declaration.   It is good practice to
  1289.    declare all functions and global variables in  one  or  more
  1290.    header  files  which are included wherever the functions are
  1291.    defined or referenced.
  1292.  
  1293.    5.10. Void and Pointer to Void
  1294.  
  1295.         The _v_o_i_d type may be used to indicate to  the  compiler
  1296.    that  a  function  does not return a value. Any usage of the
  1297.    return value from a void function  will  be  flagged  as  an
  1298.    error.
  1299.  
  1300.         The type _v_o_i_d *, i.e. pointer to void, may be used as a
  1301.    "universal"  pointer type. This is intended to assist in the
  1302.    writing of general purpose storage allocators and the  like,
  1303.    where a pointer is returned which may be assigned to another
  1304.    variable of some other pointer type.  The  compiler  permits
  1305.    without  typecasting  and  without  reporting  an  error the
  1306.    conversion of _v_o_i_d * to any  other  pointer  type  and  vice
  1307.    versa.  The programmer is advised to use this facility care-
  1308.    fully and ensure that any  _v_o_i_d  *  value  is  usable  as  a
  1309.    pointer  to  any  other type, e.g. the alignment of any such
  1310.    pointer should be suitable for storage of any object.
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.        HI-TECH C USER'S MANUAL                              Page 19
  1323.  
  1324.        5.11. Type qualifiers
  1325.  
  1326.             The ANSI C standard  introduced  the  concept  of  _t_y_p_e
  1327.        _q_u_a_l_i_f_i_e_r_s to C; these are keywords that qualify the type to
  1328.        which they are applied.  The type qualifiers defined by ANSI
  1329.        C are const and volatile.  HI-TECH C also implements several
  1330.        other type qualifiers.  The extra qualifiers include:
  1331.  
  1332.             far
  1333.             near
  1334.             interrupt
  1335.             fast interrupt
  1336.             port
  1337.  
  1338.        Not all versions of the compilers implement all of the extra
  1339.        qualifiers.  See  the  machine dependent section for further
  1340.        information.
  1341.  
  1342.             When constructing declarations using  type  qualifiers,
  1343.        it  is very easy to be confused as to the exact semantics of
  1344.        the declaration. A couple of rules-of-thumb will  make  this
  1345.        easier.  Firstly, where a type qualifier appears at the left
  1346.        of a declaration  it  may  appear  with  any  storage  class
  1347.        specifier and the basic type in any order, e.g.
  1348.  
  1349.             static void interrupt   func();
  1350.  
  1351.        is semantically the same as
  1352.  
  1353.             interrupt static void   func();
  1354.  
  1355.  
  1356.             Where a qualifier appears in this context,  it  applies
  1357.        to  the  basic  type  of  the declaration. Where a qualifier
  1358.        appears to the right of  one  or  more  '*'  (_s_t_a_r)  pointer
  1359.        modifiers,  then  you should read the declaration from right
  1360.        to left, e.g.
  1361.  
  1362.             char * far fred;
  1363.  
  1364.        should be read as "fred is a  far  pointer  to  char".  This
  1365.        means  that  fred is qualified by _f_a_r, not the char to which
  1366.        it points. On the other hand,
  1367.  
  1368.             char far * bill;
  1369.  
  1370.        should be read as "bill is a pointer to a  far  char",  i.e.
  1371.        the  char to which bill points is located in the far address
  1372.        space. In the context of the 8086 compiler  this  will  mean
  1373.        that  bill  is  a  32  bit  pointer  while  fred is a 16 bit
  1374.        pointer. You will hear bill referred to as a "far  pointer",
  1375.        however the terminology "pointer to far" is preferred.
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.    Page 20                              HI-TECH C USER'S MANUAL
  1389.  
  1390.    5.12.
  1391.  
  1392.         There are two methods provided  for  in-line  assembler
  1393.    code  in  C  programs.   The  first  allows several lines of
  1394.    assembler anywhere in a program. This is via  the  #asm  and
  1395.    #endasm  preprocessor  directives.   Any lines between these
  1396.    two directives will be copied straight through to the assem-
  1397.    bler  file  produced  by the compiler. Alternatively you can
  1398.    use the asm("_s_t_r_i_n_g"); construct anywhere a C  statement  is
  1399.    expected. The _s_t_r_i_n_g will be copied through to the assembler
  1400.    file. Care should be  taken  with  using  in-line  assembler
  1401.    since it may interact with compiler generated code.
  1402.  
  1403.    5.13. Pragma Directives
  1404.  
  1405.         The draft  ANSI  C  standard  provides  for  a  #pragma
  1406.    preprocessor  directive that allows compiler implementations
  1407.    to control  various  aspects  of  the  compilation  process.
  1408.    Currently  HI-TECH  C  only  supports  one  pragma, the _p_a_c_k
  1409.    directive. This allows control  over  the  manner  in  which
  1410.    members  are  allocated inside a structure. By default, some
  1411.    of the compilers (especially the 8086 and  68000  compilers)
  1412.    will  align structure members onto even boundaries to optim-
  1413.    ize machine accesses. It is sometimes  desired  to  override
  1414.    this  to achieve a particular layout inside a structure. The
  1415.    _p_a_c_k pragma allows specification of a maximum  packing  fac-
  1416.    tor.  For  example,  #pragma pack1(1) will instruct the com-
  1417.    piler that no additional padding be inserted between  struc-
  1418.    ture  members,  i.e.  that  all members should be aligned on
  1419.    boundaries divisible by 1. Similarly  #pragma  pack(2)  will
  1420.    allow  alignment  on  boundaries  divisible by 2. In no case
  1421.    will use of the _p_a_c_k pragma force a greater  alignment  than
  1422.    would have been used for that data type anyway.
  1423.  
  1424.         More that one _p_a_c_k pragma may be used in a program. Any
  1425.    use  will  remain  in force until changed by another _p_a_c_k or
  1426.    until the end of the file. Do not use a _p_a_c_k  pragma  before
  1427.    include files such as <_s_t_d_i_o._h> as this will cause incorrect
  1428.    declarations of run-time library data structures.
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.        HI-TECH C USER'S MANUAL                              Page 21
  1455.  
  1456.  
  1457.        6. Machine Dependencies
  1458.  
  1459.  
  1460.             HI-TECH C eliminates  many  of  the  machine  dependent
  1461.        aspects of C, since it uniformly implements such features as
  1462.        unsigned char. There are however certain areas where machine
  1463.        dependencies  are  inherent  in  the C language; programmers
  1464.        should be aware of these and take  them  into  account  when
  1465.        writing portable code.
  1466.  
  1467.             The most obvious of these machine dependencies  is  the
  1468.        varying  size of C types; on some machines an int will be 16
  1469.        bits, on others it may be 32 bits. HI-TECH C conforms to the
  1470.        following  rules,  which represent common practice in most C
  1471.        compilers.
  1472.  
  1473.             char    is at least 8 bits
  1474.             short   is at least 16 bits
  1475.             long    is at least 32 bits
  1476.             int     is the same as either short or long
  1477.             float   is at least 32 bits
  1478.             double  is at least as wide as float
  1479.  
  1480.  
  1481.             Because of the variable width of an int, it  is  recom-
  1482.        mended  that  short  or  long  be  used wherever possible in
  1483.        preference to int. The exception to this is where a quantity
  1484.        is  required  to  correspond to the natural word size of the
  1485.        machine.
  1486.  
  1487.             Another area of machine differences  is  that  of  byte
  1488.        ordering;  the ordering of bytes in a short or long can vary
  1489.        significantly between machines. There is no easy approach to
  1490.        this  problem  other  than  to avoid code which depends on a
  1491.        particular ordering. In particular you should avoid  writing
  1492.        out  whole  structures  to  a file (via _f_w_r_i_t_e()) unless the
  1493.        file is only to be read by the same  program  then  deleted.
  1494.        Different compilers use different amounts of padding between
  1495.        structure members, though  this  can  be  modified  via  the
  1496.        #pragma pack(n) construct.
  1497.  
  1498.        6.1. Predefined Macros
  1499.  
  1500.             One technique through which machine unavoidable machine
  1501.        dependencies  may  be  managed is the predefined macros pro-
  1502.        vided by each compiler to identify the target processor  and
  1503.        operating system (if any). These are defined by the compiler
  1504.        driver  and  may  be  tested  with  conditional  compilation
  1505.        preprocessor directives.
  1506.  
  1507.             The macros defined by various compilers are  listed  in
  1508.        table 2. These can be used as shown in the example in fig .
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.    Page 22                              HI-TECH C USER'S MANUAL
  1521.  
  1522.  
  1523.            ___________________________________________
  1524.           |_M_a_c_r_o_______________D_e_f_i_n_e_d__f_o_r_____________|
  1525.           | i8051    8051 processor family           |
  1526.           | i8086    8086 processor family           |
  1527.           | i8096    8096 processor family           |
  1528.           | z80      Z80 processor and derivatives   |
  1529.           | m68000   68000 processor family          |
  1530.           | m6800    6801, 68HC11 and 6301 processors|
  1531.           | m6809    6809 processor                  |
  1532.           | DOS      MS-DOS and PC-DOS               |
  1533.           | CPM      CP/M-80 and CP/M-86             |
  1534.           | TOS      Atari ST                        |
  1535.           |___________________________________________|
  1536.  
  1537.  
  1538.                     Table 2. Predefined Macros
  1539.  
  1540.  
  1541.         #if     DOS
  1542.         char *  filename = "c:file";
  1543.         #endif  /* DOS */
  1544.         #if     CPM
  1545.         char *  filename = "0:B:afile";
  1546.         #endif  /* CPM */
  1547.  
  1548.  
  1549.  
  1550.  
  1551.                      Use this page for notes
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.        HI-TECH C USER'S MANUAL                              Page 23
  1587.  
  1588.  
  1589.        7. Error Checking and Reporting
  1590.  
  1591.  
  1592.             Errors may be reported by any  pass  of  the  compiler,
  1593.        however  in  practice  the  assembler and optimizer will not
  1594.        encounter any errors in the generated  code.  The  types  of
  1595.        errors  produced by each pass are summarized below.  In gen-
  1596.        eral any error will be indentified by the name of the source
  1597.        file  in  which  it  was encountered, and the line number at
  1598.        which it was detected.  P1 will also nominate  the  name  of
  1599.        the function inside which the error was detected.
  1600.  
  1601.             Errors may be redirected to a file with the usual  syn-
  1602.        tax, i.e. a 'greater than' symbol ('>') followed by the name
  1603.        of a file into which the errors should be written. The  file
  1604.        name  may of course be a device name, e.g.  LST: for CP/M or
  1605.        PRN for MS-DOS.
  1606.  
  1607.             CPP will report errors relating  to  macro  definitions
  1608.        and expansions, as well as conditional compilation.
  1609.  
  1610.             P1 is the pass which reports most errors;  it  performs
  1611.        syntax  and  semantic checking of the input, and will report
  1612.        both fatal  and  warning  errors  when  encountered.  Syntax
  1613.        errors  will  normally  be expressed as "symbol expected" or
  1614.        "symbol unexpected". Semantic errors  may  relate  to  unde-
  1615.        clared,  redeclared  or misdeclared variables.  P1 will also
  1616.        report variable definitons which are unused or unreferenced.
  1617.        These errors are warnings, as are most type checking errors.
  1618.  
  1619.             When P1 encounters errors it will list the source  line
  1620.        containing  the  error on the screen, and underneath display
  1621.        the error message and an up arrow pointing to the  point  at
  1622.        which  the  compiler  detected  the error. In some cases the
  1623.        actual cause of the error may be earlier in the line or even
  1624.        on previous line.
  1625.  
  1626.             CGEN may occasionally report errors, usually  warnings,
  1627.        and  mostly  related  to  unusual combinations of types with
  1628.        constants, for example testing if an  unsigned  quantity  is
  1629.        less  than  zero. One fatal error produced by CGEN is "can't
  1630.        generate code  for  this  expression"  and  means  that  the
  1631.        expression  currently being compiled is in some way too com-
  1632.        plicated to produce code for. This can usually  be  overcome
  1633.        by  rewriting the source code. Such errors are rare and will
  1634.        occur only for unusual constructs.
  1635.  
  1636.             The linker will report undefined  or  multiply  defined
  1637.        symbols.  Note  that  variable  declarations inside a header
  1638.        file which is included in more than one source file must  be
  1639.        declared as extern, to avoid multiply defined symbol errors.
  1640.        These symbols must then be  defined  in  one  and  one  only
  1641.        source file.
  1642.  
  1643.             A comprehensive list of error messages is  included  in
  1644.        an appendix.
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.    Page 24                              HI-TECH C USER'S MANUAL
  1653.  
  1654.  
  1655.  
  1656.  
  1657.                      Use this page for notes
  1658.  
  1659.  
  1660.  
  1661.  
  1662.  
  1663.  
  1664.  
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678.  
  1679.  
  1680.  
  1681.  
  1682.  
  1683.  
  1684.  
  1685.  
  1686.  
  1687.  
  1688.  
  1689.  
  1690.  
  1691.  
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.        HI-TECH C USER'S MANUAL                              Page 25
  1719.  
  1720.  
  1721.        8. Standard Libraries
  1722.  
  1723.  
  1724.        8.1. Standard I/O
  1725.  
  1726.             C is a language which does not specify the  I/O  facil-
  1727.        ites in the language itself; rather all I/O is performed via
  1728.        library routines. In practice this results in  I/O  handling
  1729.        which  is  no  less convenient than any other language, with
  1730.        the added possibility of customising the I/O for a  specific
  1731.        application. For example it is possible to provide a routine
  1732.        to replace the standard getchar() (which gets one  character
  1733.        from  the  standard input) with a special getchar(). This is
  1734.        particulary useful when writing code which is to  run  on  a
  1735.        special  hardware  configuration,  while  maintaining a high
  1736.        level of compatibility with "standard" C I/O.
  1737.  
  1738.             There is in fact a Standard I/O library  (STDIO)  which
  1739.        defines  a  portable set of I/O routines. These are the rou-
  1740.        tines which are normally used by any C application  program.
  1741.        These  routines,  along with other non-I/O library routines,
  1742.        are listed in detail in a subsequent section of the manual.
  1743.  
  1744.        8.2. Compatibility
  1745.  
  1746.             The libraries supplied with HI-TECH C are highly compa-
  1747.        tible  with  the  ANSI  libraries,  as  well  as the V7 UNIX
  1748.        libraries, both at the Standard I/O level and the UNIX  sys-
  1749.        tem  call  level.  The Standard I/O library is complete, and
  1750.        conforms in all respects with the UNIX Standard I/O library.
  1751.        The  library  routines  implementing  UNIX  system call like
  1752.        functions are as close as possible to  those  system  calls,
  1753.        however  there  are  some  UNIX  system calls that cannot be
  1754.        simulated on other systems, e.g.  the link() operation. How-
  1755.        ever  the  basic  low  level I/O routines, i.e. open, close,
  1756.        read, write and lseek are identical to the UNIX equivalents.
  1757.        This  means  that many programs written to run on UNIX, even
  1758.        if they do not use Standard I/O, will run with little modif-
  1759.        ication when compiled with HI-TECH C.
  1760.  
  1761.        8.3. Libraries for Embedded Systems
  1762.  
  1763.             The cross compilers, designed to produce code for  tar-
  1764.        get  systems  without  operating  systems, are supplied with
  1765.        libraries implementing a subset of the STDIO functions.  Not
  1766.        provided  are  those  functions dealing with files. Included
  1767.        are _p_r_i_n_t_f(), _s_c_a_n_f() etc. These operate by calling two  low
  1768.        level  functions  _p_u_t_c_h and _g_e_t_c_h() which typically send and
  1769.        receive characters via a serial port. Where the compiler  is
  1770.        aimed  at  a  single-chip  micro  with on-board UART this is
  1771.        used.  The source code for all these functions  is  supplied
  1772.        enabling the user to modify it to address a different serial
  1773.        port.
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.    Page 26                              HI-TECH C USER'S MANUAL
  1785.  
  1786.    8.4. Binary I/O
  1787.  
  1788.         On some operating  systems,  notably  CP/M,  files  are
  1789.    treated  differently according to whether they contain ASCII
  1790.    (i.e. printable) or binary data.  MD-DOS also  suffers  from
  1791.    this  problem,  not  due to any lack in the operating system
  1792.    itself, but rather because of the hangover from  CP/M  which
  1793.    results  in  many programs putting a redundant ctrl-Z at the
  1794.    end of files.  Unfortunately there is no  way  to  determine
  1795.    which  type  of  data a file contains (except perhaps by the
  1796.    name or type of the file, and  this  is  not  reliable).  To
  1797.    overcome  this difficulty, there is an extra character which
  1798.    may be included in the MODE string to  a  fopen()  call.  To
  1799.    open a file for ASCII I/O, the form of the fopen() call is:
  1800.  
  1801.    fopen("filename.ext", "r")      /* for reading */
  1802.    fopen("filename.ext", "w")      /* for writing */
  1803.  
  1804.    To open a file for binary I/O,  the  character  'b'  may  be
  1805.    appended to the
  1806.  
  1807.    fopen("filename.ext", "rb")
  1808.    fopen("filename.ext", "wb")
  1809.  
  1810.  
  1811.         The additional character instructs  the  STDIO  library
  1812.    that  this file is to be handled in a strict binary fashion.
  1813.    On CP/M or MS-DOS, a file opened in ASCII mode will have the
  1814.    following  special character handling performed by the STDIO
  1815.    routines:
  1816.  
  1817.    newline
  1818.         ('\n') converted to carriage return/newline on output.
  1819.  
  1820.    return
  1821.         ('\r') ignored on input
  1822.  
  1823.    Ctrl-Z
  1824.         interpreted as End-Of-File on input and, for CP/M only,
  1825.         appended when closing the file.
  1826.  
  1827.         The special actions performed  on  ASCII  files  ensure
  1828.    that  the  file is written in a format compatible with other
  1829.    programs handling text files, while eliminating the require-
  1830.    ment for any special handling by the user program - the file
  1831.    appears to the user program as though it  were  a  UNIX-like
  1832.    text file.
  1833.  
  1834.         None of these special actions are performed on  a  file
  1835.    opened  in  binary mode.  This is required when handling any
  1836.    kind of binary data, to ensure that spurious bytes  are  not
  1837.    inserted, and premature EOF's are not seen.
  1838.  
  1839.         Since the binary mode character is  additional  to  the
  1840.    normal  mode  character, this usage is quite compatible with
  1841.    UNIX C. When compiled on UNIX, the additional character will
  1842.    be ignored.
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.        HI-TECH C USER'S MANUAL                              Page 27
  1851.  
  1852.             A mention here of the  term  `stream'  is  appropriate;
  1853.        stream  is used in relation to the STDIO library routines to
  1854.        mean the source or sink of bytes (characters) manipulated by
  1855.        those  routines.  Thus the FILE pointer supplied as an argu-
  1856.        ment to the STDIO routines may be regarded as  a  handle  on
  1857.        the  corresponding  stream.   A  stream  may  be viewed as a
  1858.        featureless sequence of bytes,  originating  from  or  being
  1859.        sent  to  a  device or file or even some other indeterminate
  1860.        source. A FILE pointer should not be confused with the 'file
  1861.        descriptors'  used  with the low-level I/O functions _o_p_e_n(),
  1862.        _c_l_o_s_e(), _r_e_a_d() and _w_r_i_t_e(). These form an independent group
  1863.        of  I/O  functions which perform unbuffered reads and writes
  1864.        to files.
  1865.  
  1866.        8.5. Floating Point Library
  1867.  
  1868.             HI-TECH C  supports  floating  point  as  part  of  the
  1869.        language,  however  the  Z80  implementation provides single
  1870.        precision only; double floats are permitted but are no  dif-
  1871.        ferent   to  floats.  In  addition,  the  standard  library,
  1872.        LIBC.LIB, does not  contain  any  floating  point  routines.
  1873.        These   have   been  separated  out  into  another  library,
  1874.        LIBF.LIB. This means that if this library is not searched no
  1875.        floating  point  support  routines  will  be linked in, thus
  1876.        avoiding any size penalty for the floating point support  if
  1877.        it is not used. This is particulary important for printf and
  1878.        scanf, and thus LIBF.LIB contains  versions  of  printf  and
  1879.        scanf that do support floating point formats.
  1880.  
  1881.             Thus, if floating point is used, a -LF option should be
  1882.        used  AFTER the source and/or object files to the C command.
  1883.        E.g.:
  1884.  
  1885.             C -V -O x.c y.c z.obj -LF
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.    Page 28                              HI-TECH C USER'S MANUAL
  1917.  
  1918.  
  1919.  
  1920.  
  1921.                      Use this page for notes
  1922.  
  1923.  
  1924.  
  1925.  
  1926.  
  1927.  
  1928.  
  1929.  
  1930.  
  1931.  
  1932.  
  1933.  
  1934.  
  1935.  
  1936.  
  1937.  
  1938.  
  1939.  
  1940.  
  1941.  
  1942.  
  1943.  
  1944.  
  1945.  
  1946.  
  1947.  
  1948.  
  1949.  
  1950.  
  1951.  
  1952.  
  1953.  
  1954.  
  1955.  
  1956.  
  1957.  
  1958.  
  1959.  
  1960.  
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.        HI-TECH C USER'S MANUAL                              Page 29
  1983.  
  1984.  
  1985.        9. Stylistic Considerations
  1986.  
  1987.  
  1988.             Although it is not the purpose of this  manual  to  set
  1989.        out  a coding standard for C, some comments regarding use of
  1990.        some of the features of HI-TECH C may be useful.
  1991.  
  1992.        9.1. Member Names
  1993.  
  1994.             Although HI-TECH C allows the same structure  or  union
  1995.        member  name to be used in more than one structure or union,
  1996.        this may not be allowed  by  another  C  compiler.  To  help
  1997.        ensure  portability  of  the  code,  it  is recommended that
  1998.        member names all be distinct, and a useful way  of  ensuring
  1999.        this  is  to prefix each member name with one or two letters
  2000.        derived from the name of the structure itself. An example is
  2001.        given in fig. 7.
  2002.  
  2003.        struct tree_node
  2004.        {
  2005.                struct tree_node *      t_left;
  2006.                struct tree_node *      t_right;
  2007.                short                   t_operator;
  2008.        };
  2009.  
  2010.  
  2011.                           Fig. 7. Member Naming
  2012.  
  2013.  
  2014.             Because HI-TECH C insists on use  of  all  intermediate
  2015.        names when referencing a member nested inside several struc-
  2016.        tures, some simple macro definitions can serve as  a  short-
  2017.        hand. An example is given in fig. 8.
  2018.  
  2019.        struct tree_node
  2020.        {
  2021.            short       t_operator;
  2022.            union
  2023.            {
  2024.                struct tree_node *  t_un_sub[2];
  2025.                char *              t_un_name;
  2026.                long                t_un_val;
  2027.            }   t_un;
  2028.        };
  2029.  
  2030.        #define t_left  t_un.t_un_sub[0]
  2031.        #define t_right t_un.t_un_sub[1]
  2032.        #define t_name  t_un.t_un_name
  2033.        #define t_val   t_un.t_un_val
  2034.  
  2035.  
  2036.                       Fig. 8. Member Name Shorthand
  2037.  
  2038.  
  2039.             This enables the variant components of the structure to
  2040.        be  referred to by short names, while guaranteeing portabil-
  2041.        ity and presenting a clean definition of the structure.
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.    Page 30                              HI-TECH C USER'S MANUAL
  2049.  
  2050.    9.2. Use of Int
  2051.  
  2052.         It is recommended that the type int be avoided wherever
  2053.    possible,  in preference to the types short or long. This is
  2054.    because of the variable size of int, whereas short  is  com-
  2055.    monly 16 bits and long 32 bits in most C implementations.
  2056.  
  2057.    9.3. Extern Declarations
  2058.  
  2059.         Some compilers permit a non-initialized global variable
  2060.    to  be  declared  in  more than one place, with the multiple
  2061.    definitions being resolved by the linker as all defining the
  2062.    same  thing. HI-TECH C specifically disallows this, since it
  2063.    may lead to subtle bugs. Instead, global  variables  may  be
  2064.    declared  extern  in as many places as you wish, and must be
  2065.    defined in one and one only place. Typically this will  mean
  2066.    declaring  global  variables in a header file as extern, and
  2067.    defining each variable in the file most  closely  associated
  2068.    with that variable.
  2069.  
  2070.         This usage will be portable to  virually  all  other  C
  2071.    implementations.
  2072.  
  2073.  
  2074.  
  2075.  
  2076.  
  2077.  
  2078.  
  2079.  
  2080.  
  2081.  
  2082.  
  2083.  
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.  
  2094.  
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.        HI-TECH C USER'S MANUAL                              Page 31
  2115.  
  2116.  
  2117.        10. Memory Models
  2118.  
  2119.  
  2120.             With many of the processors supported by the HI-TECH  C
  2121.        compilers  there  are more than one address space accessible
  2122.        to a program. Typically one address space is more economical
  2123.        to  access  than  another,  larger address space. Thus it is
  2124.        desirable to be able to tailor a prorgram's use of memory to
  2125.        achieve  the greatest economy in addressing (thus minimizing
  2126.        program size and maximizing speed) while allowing access  to
  2127.        as much memory as the program requires.
  2128.  
  2129.             This concept of different address spaces is not catered
  2130.        for  by either K&R or ANSI C (except to recognize the possi-
  2131.        bility of  separate  address  spaces  for  code  and  data).
  2132.        Without any extensions to the language itself it is possible
  2133.        to devise more than one memory model for a given  processor,
  2134.        selected  at  compile time. This has the effect of selecting
  2135.        one addressing method for all data and/or code. This permits
  2136.        the model for a particular program to be chosen depending on
  2137.        that program's memory requirements.
  2138.  
  2139.             In many programs, however, only one or two data  struc-
  2140.        tures  are  large  enough to need to be placed in the larger
  2141.        address space. Selection of a "large" memory model  for  the
  2142.        whole  of  the  program  makes  the whole program larger and
  2143.        slower just to allow a few large data structures.  This  can
  2144.        be  overcome by allowing individual selection of the address
  2145.        space for each data structure.  Unfortunately  this  entails
  2146.        extensions  to  the language, never a desirable approach. To
  2147.        minimize the effect of such extensions they  should  satisfy
  2148.        the following criteria:
  2149.  
  2150.        1.   As far as possible the extensions should be  consistent
  2151.             with common practice.
  2152.  
  2153.        2.   The extensions should fit a  machine-independent  model
  2154.             to maximize portability across processors and operating
  2155.             systems.
  2156.  
  2157.             These goals have been  achieved  within  HI-TECH  C  by
  2158.        means of the following model:
  2159.  
  2160.             Each memory model  defines  three  address  spaces
  2161.             each  for code and data.  These address spaces are
  2162.             known as the _n_e_a_r, _f_a_r  and  _d_e_f_a_u_l_t  spaces.  Any
  2163.             object  qualified  by  the  near  keyword  will be
  2164.             placed in the _n_e_a_r address space, any object qual-
  2165.             ified  by  the  far keyword shall be placed in the
  2166.             _f_a_r address space, and all other objects shall  be
  2167.             placed  in  the  _d_e_f_a_u_l_t  address  space. The _n_e_a_r
  2168.             address space shall be a (possibly improper)  sub-
  2169.             space  of  the  _d_e_f_a_u_l_t  address  space, while the
  2170.             _d_e_f_a_u_l_t  address  space  shall  be   a   (possibly
  2171.             improper) subspace of the _f_a_r address space. There
  2172.             shall be up to three kinds of pointers correspond-
  2173.             ing  to  the three address spaces, each capable of
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.    Page 32                              HI-TECH C USER'S MANUAL
  2181.  
  2182.         addressing an object in its own address space or a
  2183.         subspace of that address space.
  2184.  
  2185.         This implies that the address of an object may be  con-
  2186.    verted to a pointer into a larger address space, e.g. a _n_e_a_r
  2187.    object may have its address converted to a pointer  to  _f_a_r,
  2188.    but  a  _f_a_r  object  may  not  be  able to be addressed by a
  2189.    pointer to _n_e_a_r.
  2190.  
  2191.         In practice the  _d_e_f_a_u_l_t  address  space  will  usually
  2192.    correspond exactly to either the _n_e_a_r or _f_a_r address spaces.
  2193.    If all three address spaces correspond to  the  same  memory
  2194.    then  there  is  only one memory model possible. This occurs
  2195.    with the 68000 processor. Where the _d_e_f_a_u_l_t  code  and  data
  2196.    spaces may each correspond to either the _n_e_a_r or _f_a_r address
  2197.    spaces then there will be a total  of  four  memory  models.
  2198.    This is the case with the 8086 processor.
  2199.  
  2200.         The keywords far and near are supported by all the  HI-
  2201.    TECH  C  compilers,  but the exact correspondence of address
  2202.    spaces is determined by the  individual  characteristics  of
  2203.    each processor and the choice of memory model (if there is a
  2204.    choice). However code written using these keywords  will  be
  2205.    portable  providing  it  obeys  the constraints of the model
  2206.    described above.
  2207.  
  2208.         This model also corresponds well with other implementa-
  2209.    tions  using the near and far keywords, although such imple-
  2210.    mentations do not appear to have been designed around a for-
  2211.    mal, portable model.
  2212.  
  2213.  
  2214.  
  2215.  
  2216.  
  2217.  
  2218.  
  2219.  
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.        HI-TECH C USER'S MANUAL                              Page 33
  2247.  
  2248.  
  2249.        11. What Went Wrong
  2250.  
  2251.  
  2252.             There are numerous error messages that the compiler may
  2253.        produce.  Most  of these relate to errors in the source code
  2254.        (syntax errors of various  kinds  and  so  forth)  but  some
  2255.        represent  limitations,  particularly  of  memory.  The  two
  2256.        passes most likely to be affected by memory limitations  are
  2257.        the  code  generator  and  the optimizer. The code generator
  2258.        will issue the message "No room" if it runs out  of  dynamic
  2259.        memory.  This  can  usually be eliminated by simplifying the
  2260.        expression at the line nominated in the error  message.  The
  2261.        more  complex the expression, the more memory is required to
  2262.        store the tree representing it. Reducing the number of  sym-
  2263.        bols used in the program will also help.
  2264.  
  2265.             Note that this error  is  different  from  the  message
  2266.        "Can't  generate  code  for this expression" which indicates
  2267.        that the expression is in some way  too  difficult  for  the
  2268.        code  generator  to handle. This message will be encountered
  2269.        very infrequently, and can be  eliminated  by  changing  the
  2270.        expression in some way, e.g. computing an intermediate value
  2271.        into a temporary variable.
  2272.  
  2273.             The optimizer reads the  assembler  code  for  a  whole
  2274.        function  into memory at one time. Very large functions will
  2275.        not fit, giving the error message "Optim: out of  memory  in
  2276.        _func"  where  func is the name of the function responsible.
  2277.        In this case the function should be broken up  into  smaller
  2278.        functions.  This will only occur with functions with several
  2279.        hundred lines of C source code. Good  coding  practice  will
  2280.        normally limit functions to less than 50 lines each.
  2281.  
  2282.             If a pass exits with the message "Error closing  file",
  2283.        or  "Write error on file", this usually indicates that there
  2284.        is insufficient room on the current disk.
  2285.  
  2286.             If you use a wordprocessing editor  such  as  Wordstar,
  2287.        ensure  that you use the "non-document" mode or whatever the
  2288.        corresponding mode is. The edited file  should  not  contain
  2289.        any  characters  with the high bit set, and the line feed at
  2290.        the end of the line must be present.  Lines  should  be  not
  2291.        more than 255 characters long.
  2292.  
  2293.             When using floating point, ensure that you  use  a  -LF
  2294.        flag  at  the END of the command line, to cause the floating
  2295.        point library to be searched. This will cause floating  ver-
  2296.        sions  of  printf  and  scanf  to  be  linked in, as well as
  2297.        specific floating point routines.
  2298.  
  2299.             If the non-floating version of printf is  used  with  a
  2300.        floating  format  such  as  %f then it will simply print the
  2301.        letter f.
  2302.  
  2303.             If the linker gives an "Undefined symbol"  message  for
  2304.        some  symbol  which  you  know nothing about, it is possible
  2305.        that it is a library routine which was not found during  the
  2306.  
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312.    Page 34                              HI-TECH C USER'S MANUAL
  2313.  
  2314.    library  search  due  to incorrect library ordering. In this
  2315.    case you can search the library twice, e.g.  for  the  stan-
  2316.    dard  library add a -LC to the end of the C command line, or
  2317.    -LF for the floating library.  If  you  have  specified  the
  2318.    library by name simply repeat its name.
  2319.  
  2320.  
  2321.  
  2322.  
  2323.  
  2324.  
  2325.  
  2326.  
  2327.  
  2328.  
  2329.  
  2330.  
  2331.  
  2332.  
  2333.  
  2334.  
  2335.  
  2336.  
  2337.  
  2338.  
  2339.  
  2340.  
  2341.  
  2342.  
  2343.  
  2344.  
  2345.  
  2346.  
  2347.  
  2348.  
  2349.  
  2350.  
  2351.  
  2352.  
  2353.  
  2354.  
  2355.  
  2356.  
  2357.  
  2358.  
  2359.  
  2360.  
  2361.  
  2362.  
  2363.  
  2364.  
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.        HI-TECH C USER'S MANUAL                              Page 35
  2379.  
  2380.  
  2381.        12. Z80 Assembler Reference Manual
  2382.  
  2383.  
  2384.        12.1. Introduction
  2385.  
  2386.             The assembler incorporated in the  HI-TECH  C  compiler
  2387.        system is a full-featured relocating macro assembler accept-
  2388.        ing Zilog mnemonics. These mnemonics and the syntax  of  the
  2389.        Z80  assembly  language  are  described in the "Z80 Assembly
  2390.        Language Handbook" published by Zilog and  are  included  at
  2391.        the  end of this manual as a reference. The assembler imple-
  2392.        ments certain extensions to the operands allowed,  and  cer-
  2393.        tain  additional  pseudo-ops, which are described here.  The
  2394.        assembler also accepts the additional opcodes for the  Hita-
  2395.        chi 64180 and Z180 processors.
  2396.  
  2397.        12.2. Usage
  2398.  
  2399.             The assembler is named zas, and is invoked as follows:
  2400.  
  2401.             ZAS options files ...
  2402.  
  2403.  
  2404.             The files are one or more assembler source files  which
  2405.        will be assembled, but note that all the files are assembled
  2406.        as one, not as separate files.  To assemble separate  files,
  2407.        the  assembler  must be invoked on each file separately. The
  2408.        options are zero or more options from the following list:
  2409.  
  2410.        -N   Ignore arithmetic  overflow  in  expressions.   The  -N
  2411.             option suppresses the normal check for arithmetic over-
  2412.             flow. The assembler follows the "Z80 Assembly  Language
  2413.             Handbook"  in its treatment of overflow, and in certain
  2414.             instances this can lead to an error where in  fact  the
  2415.             expression  does  evaluate  to  what the user intended.
  2416.             This option may be used to override the overflow check-
  2417.             ing.
  2418.  
  2419.        -J   Attempt to optimize jumps to branches.  The  -J  option
  2420.             will request the assembler to attempt to assemble jumps
  2421.             and conditional jumps as relative branches where possi-
  2422.             ble.   Only   those   conditional   jumps  with  branch
  2423.             equivalents will be optimized, and jumps will  only  be
  2424.             optimized  to  branches  where  the target is in branch
  2425.             range. Note that the  use  of  this  option  slows  the
  2426.             assembly  down,  due to the necessity for the assembler
  2427.             to make an additional pass over the input code.
  2428.  
  2429.        -U   Treat undefined symbols as  external.   The  -U  option
  2430.             will suppress error messages relating to undefined sym-
  2431.             bols. Such symbols are  treated  as  externals  in  any
  2432.             case.  The use of this option will not alter the object
  2433.             code generated, but merely serves to suppress the error
  2434.             messages.
  2435.  
  2436.  
  2437.  
  2438.  
  2439.  
  2440.  
  2441.  
  2442.  
  2443.  
  2444.    Page 36                              HI-TECH C USER'S MANUAL
  2445.  
  2446.    -O_f_i_l_e
  2447.         Place the object code in _f_i_l_e.  The default object file
  2448.         name  is  constructed from the name of the first source
  2449.         file. Any suffix or file type (i.e. anything  following
  2450.         the  rightmost  dot  ('.') in the name is stripped, and
  2451.         the suffix .obj appended. Thus the command
  2452.  
  2453.              ZAS file1.as file2.z80
  2454.  
  2455.         will produce an object file called file1.obj.  The  use
  2456.         of the -O option will override this default convention,
  2457.         allowing the object file to be arbitrarily  named.  For
  2458.         example:
  2459.  
  2460.              ZAS -ox.obj file1.obj
  2461.  
  2462.         will place the object code in x.obj.
  2463.  
  2464.    -L_l_i_s_t
  2465.         Place an assembly listing in the file _l_i_s_t, or on stan-
  2466.         dard  output if _l_i_s_t is null A listfile may be produced
  2467.         with the -L option. If a file name is supplied  to  the
  2468.         option,  the  list file will be created with that name,
  2469.         otherwise the listing will be written to standard  out-
  2470.         put  (i.e.  the  console). List file names such as CON:
  2471.         and LST: are acceptable.
  2472.  
  2473.    -W_w_i_d_t_h
  2474.         The listing is to be formatted for a printer  of  given
  2475.         _w_i_d_t_h  The  -W  option specifies the width to which the
  2476.         listing is to be formatted. E.g.
  2477.  
  2478.              ZAS -Llst: -W80 x.as
  2479.  
  2480.         will output  a  listing  formatted  for  an  80  column
  2481.         printer to the list device.
  2482.  
  2483.    -C   This options requests ZAS to  produce  cross  reference
  2484.         information  in a file. The file will be called _x_x_x.crf
  2485.         where _x_x_x is the base part of  the  first  source  file
  2486.         name. It will then be necessary to run the CREF utility
  2487.         to turn this information into a formatted listing.
  2488.  
  2489.    12.3. The Assembly Language
  2490.  
  2491.         As mentioned above, the assembly language  accepted  by
  2492.    zas  is  based  on the Zilog mnemonics. You should have some
  2493.    reference book such as the "Z80 Assembly Language Handbook".
  2494.    Described below are those areas in which zas differs, or has
  2495.    extensions,  compared  to  the   standard   Zilog   assembly
  2496.    language.
  2497.  
  2498.    12.3.1. Symbols
  2499.  
  2500.         The symbols (labels) accepted by the assembler  may  be
  2501.    of any length, and all characters are significant. The char-
  2502.    acters used to form a symbol may be chosen  from  the  upper
  2503.    and  lower case alphabetics, the digits 0-9, and the special
  2504.  
  2505.  
  2506.  
  2507.  
  2508.  
  2509.  
  2510.        HI-TECH C USER'S MANUAL                              Page 37
  2511.  
  2512.        symbols underscore ('_'), dollar  ('$')  and  question  mark
  2513.        ('?').  The  first  character  may not be numeric. Upper and
  2514.        lower case are distinct. The following  are  all  legal  and
  2515.        distinct symbols.
  2516.  
  2517.             An_identifier
  2518.             an_identifier
  2519.             an_identifier1
  2520.             $$$
  2521.             ?$_123455
  2522.  
  2523.  
  2524.             Note that the symbol $  is  special  (representing  the
  2525.        current  location)  and  may not be used as a label. Nor may
  2526.        any opcode or pseudo-op mnemonic, register name or condition
  2527.        code  name.   You  should note the additional condition code
  2528.        names described later.
  2529.  
  2530.        12.3.1.1. Temporary Labels
  2531.  
  2532.             The assembler implements a system of temporary  labels,
  2533.        useful  for  use  within  a localized section of code. These
  2534.        help eliminate the need to generate names for  labels  which
  2535.        are  referenced  only  in  the  immediate  vicinity of their
  2536.        definition, for example where a loop is implemented.
  2537.  
  2538.             A temporary label takes the form of a digit  string.  A
  2539.        reference  to  such  a label requires the same digit string,
  2540.        plus an appended b or f to signify  a  backward  or  forward
  2541.        reference  respectively.  Here  is  an example of the use of
  2542.        such labels.
  2543.  
  2544.        entry_point:   ;This is referenced from far away
  2545.            ld   b,10
  2546.        1:  dec  c
  2547.            jr   nz,2f ;if zero, branch forward to 2:
  2548.            ld   c,8
  2549.            djnz 1b    ;decrement and branch back to 1:
  2550.            jr   1f    ;this does not branch to the
  2551.                       ;same label as the djnz
  2552.        2:  call fred  ;get here from the jr nz,2f
  2553.        1:  ret        ;get here from the jr 1f
  2554.  
  2555.  
  2556.             The digit string may be any positive decimal  number  0
  2557.        to  65535. A temporary label value may be re-used any number
  2558.        of times. Where a reference to e.g.  1b is made,  this  will
  2559.        reference  the  closest  label 1: found by looking backwards
  2560.        from the current point  in  the  file.  Similarly  23f  will
  2561.        reference the first label 23: found by looking forwards from
  2562.        the current point in the file.
  2563.  
  2564.        12.3.2. Constants
  2565.  
  2566.             Constants may be entered in one of the radices 2, 8, 10
  2567.        or 16. The default is 10. Constants in the other radices may
  2568.        be denoted by a trailing character drawn from the  following
  2569.        set:
  2570.  
  2571.  
  2572.  
  2573.  
  2574.  
  2575.  
  2576.    Page 38                              HI-TECH C USER'S MANUAL
  2577.  
  2578.                  Character   Radix   Name
  2579.  
  2580.                  B           2       binary
  2581.                  O           8       octal
  2582.                  Q           8       octal
  2583.                  o           8       octal
  2584.                  q           8       octal
  2585.                  H           16      hexadecimal
  2586.                  h           16      hexadecimal
  2587.  
  2588.  
  2589.         Hexadecimal constants may also be specified in C style,
  2590.    for  example LD A,0x21.  Note that a lower case b may not be
  2591.    used to indicate a binary number, since  1b  is  a  backward
  2592.    reference to a temporary label 1:.
  2593.  
  2594.    12.3.2.1. Character Constants
  2595.  
  2596.         A character constant is a single character enclosed  in
  2597.    single  quotes  (').  Multi  character constants may be used
  2598.    only as an operand to a DEFM pseudo-op.
  2599.  
  2600.    12.3.2.2. Floating Constants
  2601.  
  2602.         A floating constant in the usual notation  (e.g.  1.234
  2603.    or 1234e-3) may be used as the operand to a DEFF pseudo-op.
  2604.  
  2605.    12.3.2.3. Opcode Constants
  2606.  
  2607.         Any z80 opcode may be used as a constant in an  expres-
  2608.    sion.  The  value  of the opcode in this context will be the
  2609.    byte that the opcode would have assembled to if used in  the
  2610.    normal  way. If the opcode is a 2-byte opcode (CB or ED pre-
  2611.    fix byte) only the second byte of the opcode will  be  used.
  2612.    This  is  particularly  useful when setting up jump vectors.
  2613.    For example:
  2614.  
  2615.    ld   a,jp         ;a jump instruction
  2616.    ld   (0),a        ;0 is jump to warm boot
  2617.    ld   hl,boot      ;done here
  2618.    ld   (1),hl
  2619.  
  2620.  
  2621.    12.3.3. Expressions
  2622.  
  2623.         Expressions are constructed largely as described in the
  2624.    "Z80 Assembly Language Handbook".
  2625.  
  2626.    12.3.3.1. Operators
  2627.  
  2628.         The following operators may be used in expressions:
  2629.  
  2630.                  Operator   Meaning
  2631.  
  2632.                  &          Bitwise AND
  2633.                  *          Multiplication
  2634.                  +          Addition
  2635.                  -          Subtraction
  2636.  
  2637.  
  2638.  
  2639.  
  2640.  
  2641.  
  2642.        HI-TECH C USER'S MANUAL                              Page 39
  2643.  
  2644.                      .and.      Bitwise AND
  2645.                      .eq.       Equality test
  2646.                      .gt.       Signed greater than
  2647.                      .high.     Hi byte of operand
  2648.                      .low.      Low byte of operand
  2649.                      .lt.       Signed less than
  2650.                      .mod.      Modulus
  2651.                      .not.      Bitwise complement
  2652.                      .or.       Bitwise or
  2653.                      .shl.      Shift left
  2654.                      .shr.      Shift right
  2655.                      .ult.      Unsigned less than
  2656.                      .ugt.      Unsigned greater than
  2657.                      .xor.      Exclusive or
  2658.                      /          Divison
  2659.                      <          Signed less than
  2660.                      =          Equality
  2661.                      >          Signed greater than
  2662.                      ^          Bitwise or
  2663.  
  2664.  
  2665.             Operators starting with a dot "." should  be  delimited
  2666.        by  spaces,  thus  label .and. 1 is valid but label.and.1 is
  2667.        not.
  2668.  
  2669.        12.3.3.2. Relocatability
  2670.  
  2671.             Zas produces object code  which  is  relocatable;  this
  2672.        means  that  it  is  not  necessary to specify assembly time
  2673.        where the code is to be located in memory. It is possible to
  2674.        do  so,  by  use of the ORG pseudo-op, however the preferred
  2675.        approach is to use program sections or psects. A psect is  a
  2676.        named  section  of the program, in which code or data may be
  2677.        defined at assembly time. All  parts  of  a  psect  will  be
  2678.        loaded  contiguously  into memory, even if they were defined
  2679.        in separate files, or in the same file but separated by code
  2680.        for another psect. For example, the following code will load
  2681.        some executable instructions into the psect named text,  and
  2682.        some data bytes into the data psect.
  2683.  
  2684.  
  2685.  
  2686.  
  2687.  
  2688.  
  2689.  
  2690.  
  2691.  
  2692.  
  2693.  
  2694.  
  2695.  
  2696.  
  2697.  
  2698.  
  2699.  
  2700.  
  2701.  
  2702.  
  2703.  
  2704.  
  2705.  
  2706.  
  2707.  
  2708.    Page 40                              HI-TECH C USER'S MANUAL
  2709.  
  2710.  
  2711.             psect text, global
  2712.  
  2713.         alabel:
  2714.             ld    hl,astring
  2715.             call  putit
  2716.             ld    hl,anotherstring
  2717.  
  2718.             psect data, global
  2719.         astring:
  2720.             defm  'A string of chars'
  2721.             defb  0
  2722.         anotherstring:
  2723.             defm  'Another string'
  2724.             defb  0
  2725.  
  2726.             psect text
  2727.  
  2728.         putit:
  2729.             ld    a,(hl)
  2730.             or    a
  2731.             ret   z
  2732.             call  outchar
  2733.             inc   hl
  2734.             jr    putit
  2735.  
  2736.  
  2737.         Note that even though the two blocks  of  code  in  the
  2738.    text  psect  are separated by a block in the data psect, the
  2739.    two text psect blocks will be contiguous when loaded by  the
  2740.    linker.  The  instruction  "ld  hl,anotherstring"  will fall
  2741.    through to the label "putit:" during execution.  The  actual
  2742.    location  in  memory of the two psects will be determined by
  2743.    the linker. See the linker manual  for  information  on  how
  2744.    psect addresses are determined.
  2745.  
  2746.         A label defined in a psect is said to  be  relocatable,
  2747.    that  is,  its  actual  memory  address is not determined at
  2748.    assembly time. Note that this does not apply if the label is
  2749.    in the default (unnamed) psect, or in a psect declared abso-
  2750.    lute (see  the  PSECT  pseudo-op  description  below).   Any
  2751.    labels  declared in an absolute psect will be absolute, that
  2752.    is their address will be determined by the assembler.
  2753.  
  2754.         With the version of ZAS  supplied  with  version  7  or
  2755.    later  of HI-TECH C, relocatable expressions may be combined
  2756.    freely in expressions.  Older versions of ZAS  allowed  only
  2757.    limited arithmetic on relocatable expressions.
  2758.  
  2759.    12.3.4. Pseudo-ops
  2760.  
  2761.         The pseudo-ops are based on those described in the "Z80
  2762.    Assembly Language Handbook", with some additions.
  2763.  
  2764.    12.3.4.1. DEFB, DB
  2765.  
  2766.         This pseudo-op should be followed by a  comma-separated
  2767.    list of expressions, which will be assembled into sequential
  2768.  
  2769.  
  2770.  
  2771.  
  2772.  
  2773.  
  2774.        HI-TECH C USER'S MANUAL                              Page 41
  2775.  
  2776.        byte locations. Each expression must have  a  value  between
  2777.        -128  and  255  inclusive.   DB can be used as a synonym for
  2778.        DEFB.  Example:
  2779.  
  2780.            DEFB  10, 20, 'a', 0FFH
  2781.            DB    'hello world',13,10,0
  2782.  
  2783.  
  2784.  
  2785.        12.3.4.2. DEFF
  2786.  
  2787.             This pseudo-op assembles floating point constants  into
  2788.        32 bit HI-TECH C format floating point constants.  For exam-
  2789.        ple:
  2790.  
  2791.        pi: DEFF  3.14159
  2792.  
  2793.  
  2794.  
  2795.        12.3.4.3. DEFW
  2796.  
  2797.             This operates in a similar fashion to DEFB, except that
  2798.        it  assembles expressions into words, without the value res-
  2799.        triction.  Example:
  2800.  
  2801.            DEFW  -1, 3664H, 'A', 3777Q
  2802.  
  2803.  
  2804.  
  2805.        12.3.4.4. DEFS
  2806.  
  2807.             Defs reserves  memory  locations  without  initializing
  2808.        them.  Its  operand  is an absolute expression, representing
  2809.        the number of bytes to  be  reserved.   This  expression  is
  2810.        added  to  the  current  location counter. Note however that
  2811.        locations reserved by DEFS may be initialized to zero by the
  2812.        linker  if  the  reserved locations are in the middle of the
  2813.        program.  Example:
  2814.  
  2815.            DEFS  20h   ;reserve 32 bytes of memory
  2816.  
  2817.  
  2818.  
  2819.        12.3.4.5. EQU
  2820.  
  2821.             Equ sets the value of a symbol on the left  of  EQU  to
  2822.        the  expression on the right. It is illegal to set the value
  2823.        of a symbol which is already defined.  Example:
  2824.  
  2825.        SIZE      equ   46
  2826.  
  2827.  
  2828.  
  2829.        12.3.4.6. DEFL
  2830.  
  2831.             This is identical to EQU except that  it  may  redefine
  2832.        existing symbols.  Example:
  2833.  
  2834.  
  2835.  
  2836.  
  2837.  
  2838.  
  2839.  
  2840.    Page 42                              HI-TECH C USER'S MANUAL
  2841.  
  2842.  
  2843.    SIZE      defl  48
  2844.  
  2845.  
  2846.  
  2847.    12.3.4.7. DEFM
  2848.  
  2849.         Defm should be followed  by  a  string  of  characters,
  2850.    enclosed  in single quotes.  The ASCII values of these char-
  2851.    acters  are  assembled  into  successive  memory  locations.
  2852.    Example:
  2853.  
  2854.        DEFM  'A string of funny *@$ characters'
  2855.  
  2856.  
  2857.  
  2858.    12.3.4.8. END
  2859.  
  2860.         The end of an assembly is signified by the end  of  the
  2861.    source  file,  or  the  END pseudo-op. The END pseudo-op may
  2862.    optionally be followed by an expression  which  will  define
  2863.    the  start address of the program. This is not actually use-
  2864.    ful for CP/M. Only one start address may be defined per pro-
  2865.    gram, and the linker will complain if there are more.  Exam-
  2866.    ple:
  2867.  
  2868.        END   somelabel
  2869.  
  2870.  
  2871.  
  2872.    12.3.4.9. COND, IF, ELSE, ENDC
  2873.  
  2874.         Conditional assembly is introduced by the COND  pseudo-
  2875.    op.  The  operand to COND must be an absolute expression. If
  2876.    its value is false (zero) the code following the COND up  to
  2877.    the  corresponding  ENDC  pseudo-op  will  not be assembled.
  2878.    COND/ENDC pairs may be nested.  IF may be used as a  synonym
  2879.    for  COND.  The ELSE pseudo operation may be included within
  2880.    a COND/ENDC block, for example:
  2881.  
  2882.        IF    CPM
  2883.        call  5
  2884.        ELSE
  2885.        call  os_func
  2886.        ENDC
  2887.  
  2888.  
  2889.  
  2890.    12.3.4.10. ELSE
  2891.  
  2892.         See COND.
  2893.  
  2894.    12.3.4.11. ENDC
  2895.  
  2896.         See COND.
  2897.  
  2898.  
  2899.  
  2900.  
  2901.  
  2902.  
  2903.  
  2904.  
  2905.  
  2906.        HI-TECH C USER'S MANUAL                              Page 43
  2907.  
  2908.        12.3.4.12. ENDM
  2909.  
  2910.             See MACRO.
  2911.  
  2912.        12.3.4.13. PSECT
  2913.  
  2914.             This pseudo-op allows specification of relocatable pro-
  2915.        gram  sections.  Its  arguments are a psect name, optionally
  2916.        followed by a list of psect flags.  The psect name is a sym-
  2917.        bol  constructed  according to the same rules as for labels,
  2918.        however a psect may have the same name as  a  label  without
  2919.        conflict.  Psect  names  are  recognized  only after a PSECT
  2920.        pseudo-op.  The psect flags are as follows:
  2921.  
  2922.             ABS       Psect is absolute
  2923.  
  2924.             GLOBAL    Psect is global
  2925.  
  2926.             LOCAL           Psect is not global
  2927.  
  2928.             OVRLD     Psect is to be overlapped by linker
  2929.  
  2930.             PURE            Psect is to be read-only
  2931.  
  2932.  
  2933.             If a psect is global, the linker will merge it with any
  2934.        other  global  psects  of  the same name from other modules.
  2935.        Local psects will be treated  as  distinct  from  any  other
  2936.        psect from another module. Psects are global by default.
  2937.  
  2938.             By default the linker concatenates code within a  psect
  2939.        from  various modules. If a psect is specified as OVRLD, the
  2940.        linker will  overlap  each  module's  contribution  to  that
  2941.        psect.  This  is  particularly  useful  when linking modules
  2942.        which initialize e.g. interrupt vectors.
  2943.  
  2944.             The PURE flag instructs the linker that the psect is to
  2945.        be  made  read-only at run time. The usefulness of this flag
  2946.        depends on the ability of the linker to enforce the require-
  2947.        ment. CP/M fails miserably in this regard.
  2948.  
  2949.             The ABS flag makes a psect absolute. The psect will  be
  2950.        loaded  at zero.  This is useful for statically initializing
  2951.        interrupt vectors and jump tables.  Examples:
  2952.  
  2953.  
  2954.             PSECT     text, global, pure
  2955.             PSECT     data, global
  2956.             PSECT     vectors, ovrld
  2957.  
  2958.  
  2959.  
  2960.        12.3.4.14. GLOBAL
  2961.  
  2962.             Global should be followed by one  more  symbols  (comma
  2963.        separated)  which will be treated by the assembler as global
  2964.        symbols, either internal or external  depending  on  whether
  2965.        they are defined within the current module or not.  Example:
  2966.  
  2967.  
  2968.  
  2969.  
  2970.  
  2971.  
  2972.    Page 44                              HI-TECH C USER'S MANUAL
  2973.  
  2974.  
  2975.        GLOBAL      label1, putchar, _printf
  2976.  
  2977.  
  2978.  
  2979.    12.3.4.15. ORG
  2980.  
  2981.         An ORG pseudo-op sets the current psect to the  default
  2982.    (absolute)  psect,  and the location counter to its operand,
  2983.    which must be an absolute expression.  Example:
  2984.  
  2985.        ORG   100H
  2986.  
  2987.  
  2988.  
  2989.    12.3.4.16. MACRO
  2990.  
  2991.         This pseudo-op defines a macro.  It  should  be  either
  2992.    preceded or followed by the macro name, then optionally fol-
  2993.    lowed by a comma-separated list of formal  parameters.   The
  2994.    lines  of  code following the MACRO pseudo-op up to the next
  2995.    ENDM pseudo-op will be stored as the body of the macro.  The
  2996.    macro name may subsequently be used in the opcode part of an
  2997.    assembler statement, followed by actual parameters. The text
  2998.    of  the body of the macro will be substituted at that point,
  2999.    with any use of the formal parameters substituted  with  the
  3000.    corresponding actual parameter. For example:
  3001.  
  3002.    print     MACRO string
  3003.        psect data
  3004.    999:      db    string,'$'
  3005.        psect text
  3006.        ld    de,999b
  3007.        ld    c,9
  3008.        call  5
  3009.        ENDM
  3010.  
  3011.  
  3012.  
  3013.         When used, this macro will expand to the 3 instructions
  3014.    in the body of the macro, with the actual parameters substi-
  3015.    tuted for func and arg. Thus
  3016.  
  3017.        print 'hello world'
  3018.  
  3019.  
  3020.    expands to
  3021.  
  3022.        psect data
  3023.    999:      db    'hello world','$'
  3024.        psect text
  3025.        ld    de,999b
  3026.        ld    c,9
  3027.        call  5
  3028.  
  3029.  
  3030.  
  3031.         Macro arguments can be enclosed in angle brackets  ('<'
  3032.  
  3033.  
  3034.  
  3035.  
  3036.  
  3037.  
  3038.        HI-TECH C USER'S MANUAL                              Page 45
  3039.  
  3040.        and  '>') to pass arbitrary text including delimiter charac-
  3041.        ters like commas as a single argument.  For example, suppose
  3042.        you  wanted  to use the print macro defined above to print a
  3043.        string which includes the carriage return and linefeed char-
  3044.        acters.  The macro invocation:
  3045.  
  3046.            print 'hello world',13,10
  3047.  
  3048.  
  3049.        would fail because 13 and 10 are treated as extra  arguments
  3050.        and ignored. In order to pass a string which includes commas
  3051.        as a single argument, you could write:
  3052.  
  3053.            print <'hello world',13,10>
  3054.  
  3055.  
  3056.        which would cause the text 'hello world',13,10 to be  passed
  3057.        through as a single argument.  This would expand to the fol-
  3058.        lowing code:
  3059.  
  3060.            psect data
  3061.        999:      db    'hello world',13,10,'$'
  3062.            psect text
  3063.            ld    de,999b
  3064.            ld    c,9
  3065.            call  5
  3066.  
  3067.  
  3068.  
  3069.             ZAS supports two forms of macro declaration for  compa-
  3070.        tibility  with  older  versions  of ZAS and other Z80 assem-
  3071.        blers.  The macro name may be declared either in  the  label
  3072.        field  before  the  MACRO pseudo-op, or in the operand field
  3073.        after the MACRO pseudo-op.  Thus these  two  MACRO  declara-
  3074.        tions are equivalent:
  3075.  
  3076.        bdos      MACRO func,arg
  3077.            ld    de,arg
  3078.            ld    c,func
  3079.            call  5
  3080.            ENDM
  3081.  
  3082.        and
  3083.  
  3084.            MACRO bdos,func,arg
  3085.            ld    de,arg
  3086.            ld    c,func
  3087.            call  5
  3088.            ENDM
  3089.  
  3090.  
  3091.  
  3092.        12.3.4.17. LOCAL
  3093.  
  3094.             The LOCAL pseudo-op allows unique labels to be  defined
  3095.        for each expansion of a macro.  Any symbols listed after the
  3096.        LOCAL directive will have a unique assembler-generated  sym-
  3097.        bol  substituted  for  them when the macro is expanded.  For
  3098.  
  3099.  
  3100.  
  3101.  
  3102.  
  3103.  
  3104.    Page 46                              HI-TECH C USER'S MANUAL
  3105.  
  3106.    example:
  3107.  
  3108.    copy      MACRO source,dest,count
  3109.        LOCAL nocopy
  3110.        push  af
  3111.        push  bc
  3112.        ld    bc,source
  3113.        ld    a,b
  3114.        or    c
  3115.        jr    z,nocopy
  3116.        push  de
  3117.        push  hl
  3118.        ld    de,dest
  3119.        ld    hl,source
  3120.        ldir
  3121.        pop   hl
  3122.        pop   de
  3123.    nocopy:   pop   bc
  3124.        pop   af
  3125.        ENDM
  3126.  
  3127.  
  3128.    when expanded will  include  a  unique  assembler  generated
  3129.    label    in    place   of   nocopy.    For   example,   copy
  3130.    (recptr),buf,(recsize) will expand to:
  3131.  
  3132.        push  af
  3133.        push  bc
  3134.        ld    bc,(recsize)
  3135.        ld    a,b
  3136.        or    c
  3137.        jr    z,??0001
  3138.        push  de
  3139.        push  hl
  3140.        ld    de,buf
  3141.        ld    hl,(recptr)
  3142.        ldir
  3143.        pop   hl
  3144.        pop   de
  3145.    ??0001:   pop   bc
  3146.        pop   af
  3147.  
  3148.    if invoked a second time, the label nocopy would  expand  to
  3149.    ??0002.
  3150.  
  3151.    12.3.4.18. REPT
  3152.  
  3153.         The REPT pseudo-op defines a temporary macro  which  is
  3154.    then  expanded a number of times, as determined by its argu-
  3155.    ment.  For example:
  3156.  
  3157.        REPT  3
  3158.        ld    (hl),0
  3159.        inc   hl
  3160.        ENDM
  3161.  
  3162.  
  3163.    will expand to
  3164.  
  3165.  
  3166.  
  3167.  
  3168.  
  3169.  
  3170.        HI-TECH C USER'S MANUAL                              Page 47
  3171.  
  3172.  
  3173.            ld    (hl),0
  3174.            inc   hl
  3175.            ld    (hl),0
  3176.            inc   hl
  3177.            ld    (hl),0
  3178.            inc   hl
  3179.  
  3180.  
  3181.  
  3182.        12.3.5. IRP and IRPC
  3183.  
  3184.             The IRP and IRPC directives are similar to  REPT,  how-
  3185.        ever  instead of repeating the block a fixed number of times
  3186.        it is repeated once for each member of an argument list.  In
  3187.        the  case  of  IRP the list is a conventional macro argument
  3188.        list, in the case of IRPC it is successive characters from a
  3189.        string.  For example:
  3190.  
  3191.            IRP   string,<'hello world',13,10>,'arg2'
  3192.            LOCAL str
  3193.            psect data
  3194.        str:      db    string,'$'
  3195.            psect text
  3196.            ld    c,9
  3197.            ld    de,str
  3198.            call  5
  3199.            ENDM
  3200.  
  3201.  
  3202.        would expand to
  3203.  
  3204.            psect data
  3205.        ??0001:   db    'hello world',13,10,'$'
  3206.            psect text
  3207.            ld    c,9
  3208.            ld    de,??0001
  3209.            call  5
  3210.            psect data
  3211.        ??0002:   db    'arg2','$'
  3212.            psect text
  3213.            ld    c,9
  3214.            ld    de,??0002
  3215.            call  5
  3216.  
  3217.  
  3218.        Note the use of LOCAL labels and angle brackets in the  same
  3219.        manner as with conventional macros.
  3220.  
  3221.             IRPC is best demonstrated using the following example:
  3222.  
  3223.            IRPC  char,ABC
  3224.            ld    c,2
  3225.            ld    e,'char'
  3226.            call  5
  3227.            ENDM
  3228.  
  3229.  
  3230.  
  3231.  
  3232.  
  3233.  
  3234.  
  3235.  
  3236.    Page 48                              HI-TECH C USER'S MANUAL
  3237.  
  3238.    will expand to:
  3239.  
  3240.        ld    c,2
  3241.        ld    e,'A'
  3242.        call  5
  3243.        ld    c,2
  3244.        ld    e,'B'
  3245.        call  5
  3246.        ld    c,2
  3247.        ld    e,'C'
  3248.        call  5
  3249.  
  3250.  
  3251.  
  3252.    12.3.6. Extended Condition Codes
  3253.  
  3254.         The assembler recognizes several  additional  condition
  3255.    codes. These are:
  3256.  
  3257.         _________________________________________________
  3258.        | Code|  Equivalent|  Meaning                    |
  3259.        | alt |  m         |  Arithmetic less than       |
  3260.        | llt |  c         |  Logical less than          |
  3261.        | age |  p         |  Arithmetic greater or equal|
  3262.        | lge |  nc        |  Logical greater or equal   |
  3263.        | di  |            |  Use after ld a,i for  test-|
  3264.        | ei  |            |  ing   state   of  interrupt|
  3265.        |     |            |  enable flag  -  enabled  or|
  3266.        ||______||_____________||__d_i_s_a_b_l_e_d__r_e_s_p_e_c_t_i_v_e_l_y_._______||
  3267.  
  3268.  
  3269.    12.4. Assembler Directives
  3270.  
  3271.         An assembler directive is a line  in  the  source  file
  3272.    which  produces  no  code,  but  rather  which  modifies the
  3273.    behaviour of the assembler. Each directive is recognized  by
  3274.    the presence of an asterisk in the first column of the line,
  3275.    followed immediately by a word, only the first character  of
  3276.    which is looked at. the line containing the directive itself
  3277.    is never listed.  The directives are:
  3278.  
  3279.    *Title
  3280.         Use the text following the directive as a title for the
  3281.         listing.
  3282.  
  3283.    *Heading
  3284.         Use the text following the directive as a subtitle  for
  3285.         the listing; also causes an *Eject.
  3286.  
  3287.    *List
  3288.         May be followed by ON or OFF to turn listing on or  off
  3289.         respectively.  Note  that  this  directive  may be used
  3290.         inside a macro or include file to  control  listing  of
  3291.         that macro or include file.  The previous listing state
  3292.         will be restored on exit  from  the  macro  or  include
  3293.         file.
  3294.  
  3295.  
  3296.  
  3297.  
  3298.  
  3299.  
  3300.  
  3301.  
  3302.        HI-TECH C USER'S MANUAL                              Page 49
  3303.  
  3304.        *Include
  3305.             The file named following the directive will be included
  3306.             in the assembly at that point.
  3307.  
  3308.        *Eject
  3309.             A new page will be  started  in  the  listing  at  that
  3310.             point.  A  form  feed character in the source will have
  3311.             the same effect.
  3312.  
  3313.             Some examples of the use of these directives:
  3314.  
  3315.  
  3316.             *Title Widget Control Program
  3317.             *Heading Initialization Phase
  3318.  
  3319.             *Include widget.i
  3320.  
  3321.  
  3322.  
  3323.        12.5. Diagnostics
  3324.  
  3325.             An error message will be written on the standard  error
  3326.        stream for each error encountered in the assembly. This mes-
  3327.        sage identifies the file name and line number and  describes
  3328.        the  error.  In  addition  the line in the listing where the
  3329.        error occurred will be flagged with a  single  character  to
  3330.        indicate  the  error.  The  characters and the corresponding
  3331.        messages are:
  3332.  
  3333.  
  3334.  
  3335.  
  3336.  
  3337.  
  3338.  
  3339.  
  3340.  
  3341.  
  3342.  
  3343.  
  3344.  
  3345.  
  3346.  
  3347.  
  3348.  
  3349.  
  3350.  
  3351.  
  3352.  
  3353.  
  3354.  
  3355.  
  3356.  
  3357.  
  3358.  
  3359.  
  3360.  
  3361.  
  3362.  
  3363.  
  3364.  
  3365.  
  3366.  
  3367.  
  3368.    Page 50                              HI-TECH C USER'S MANUAL
  3369.  
  3370.  
  3371.  
  3372.         A:   Absolute expression required
  3373.  
  3374.         B:   Bad arg to *L
  3375.              Bad arg to IM
  3376.              Bad bit number
  3377.              Bad character constant
  3378.              Bad jump condition
  3379.  
  3380.         D:   Directive not recognized
  3381.              Digit out of range
  3382.  
  3383.         E:   EOF inside conditional
  3384.              Expression error
  3385.  
  3386.         G:   Garbage after operands
  3387.              Garbage on end of line
  3388.  
  3389.         I:   Index offset too large
  3390.  
  3391.         J:   Jump target out of range
  3392.  
  3393.         L:   Lexical error
  3394.  
  3395.         M:   Multiply defined symbol
  3396.  
  3397.         O:   Operand error
  3398.  
  3399.         P:   Phase error
  3400.              Psect may not be local and global
  3401.  
  3402.         R:   Relocation error
  3403.  
  3404.         S:   Size error
  3405.              Syntax error
  3406.  
  3407.         U:   Undefined symbol
  3408.              Undefined temporary label
  3409.              Unterminated string
  3410.  
  3411.  
  3412.    12.6. Z80/Z180/64180 Instruction Set
  3413.  
  3414.         The remainder of this chapter is devoted to a  complete
  3415.    instruction  set listing for the Z80, Z180, 64180 and NSC800
  3416.    processors.   The  Z180  and  64180  will  execute  all  Z80
  3417.    instructions, although the timing is different.
  3418.  
  3419.  
  3420.  
  3421.  
  3422.  
  3423.  
  3424.  
  3425.  
  3426.  
  3427.  
  3428.  
  3429.  
  3430.  
  3431.  
  3432.  
  3433.  
  3434.        HI-TECH C USER'S MANUAL                              Page 51
  3435.  
  3436.  
  3437.  
  3438.  
  3439.  
  3440.  
  3441.  
  3442.  
  3443.  
  3444.  
  3445.  
  3446.  
  3447.  
  3448.  
  3449.  
  3450.  
  3451.  
  3452.  
  3453.  
  3454.  
  3455.  
  3456.  
  3457.  
  3458.  
  3459.  
  3460.  
  3461.  
  3462.  
  3463.  
  3464.  
  3465.  
  3466.  
  3467.  
  3468.  
  3469.  
  3470.  
  3471.  
  3472.  
  3473.  
  3474.  
  3475.  
  3476.  
  3477.  
  3478.  
  3479.  
  3480.  
  3481.  
  3482.  
  3483.  
  3484.  
  3485.  
  3486.  
  3487.  
  3488.  
  3489.  
  3490.  
  3491.  
  3492.  
  3493.  
  3494.  
  3495.  
  3496.  
  3497.  
  3498.  
  3499.  
  3500.    Page 52                              HI-TECH C USER'S MANUAL
  3501.  
  3502.  
  3503.  
  3504.  
  3505.  
  3506.  
  3507.  
  3508.  
  3509.  
  3510.  
  3511.  
  3512.  
  3513.  
  3514.  
  3515.  
  3516.  
  3517.  
  3518.  
  3519.  
  3520.  
  3521.  
  3522.  
  3523.  
  3524.  
  3525.  
  3526.  
  3527.  
  3528.  
  3529.  
  3530.  
  3531.  
  3532.  
  3533.  
  3534.  
  3535.  
  3536.  
  3537.  
  3538.  
  3539.  
  3540.  
  3541.  
  3542.  
  3543.  
  3544.  
  3545.  
  3546.  
  3547.  
  3548.  
  3549.  
  3550.  
  3551.  
  3552.  
  3553.  
  3554.  
  3555.  
  3556.  
  3557.  
  3558.  
  3559.  
  3560.  
  3561.  
  3562.  
  3563.  
  3564.  
  3565.  
  3566.        HI-TECH C USER'S MANUAL                              Page 53
  3567.  
  3568.  
  3569.  
  3570.  
  3571.  
  3572.  
  3573.  
  3574.  
  3575.  
  3576.  
  3577.  
  3578.  
  3579.  
  3580.  
  3581.  
  3582.  
  3583.  
  3584.  
  3585.  
  3586.  
  3587.  
  3588.  
  3589.  
  3590.  
  3591.  
  3592.  
  3593.  
  3594.  
  3595.  
  3596.  
  3597.  
  3598.  
  3599.  
  3600.  
  3601.  
  3602.  
  3603.  
  3604.  
  3605.  
  3606.  
  3607.  
  3608.  
  3609.  
  3610.  
  3611.  
  3612.  
  3613.  
  3614.  
  3615.  
  3616.  
  3617.  
  3618.  
  3619.  
  3620.  
  3621.  
  3622.  
  3623.  
  3624.  
  3625.  
  3626.  
  3627.  
  3628.  
  3629.  
  3630.  
  3631.  
  3632.    Page 54                              HI-TECH C USER'S MANUAL
  3633.  
  3634.  
  3635.  
  3636.  
  3637.  
  3638.  
  3639.  
  3640.  
  3641.  
  3642.  
  3643.  
  3644.  
  3645.  
  3646.  
  3647.  
  3648.  
  3649.  
  3650.  
  3651.  
  3652.  
  3653.  
  3654.  
  3655.  
  3656.  
  3657.  
  3658.  
  3659.  
  3660.  
  3661.  
  3662.  
  3663.  
  3664.  
  3665.  
  3666.  
  3667.  
  3668.  
  3669.  
  3670.  
  3671.  
  3672.  
  3673.  
  3674.  
  3675.  
  3676.  
  3677.  
  3678.  
  3679.  
  3680.  
  3681.  
  3682.  
  3683.  
  3684.  
  3685.  
  3686.  
  3687.  
  3688.  
  3689.  
  3690.  
  3691.  
  3692.  
  3693.  
  3694.  
  3695.  
  3696.  
  3697.  
  3698.        HI-TECH C USER'S MANUAL                              Page 55
  3699.  
  3700.  
  3701.  
  3702.  
  3703.  
  3704.  
  3705.  
  3706.  
  3707.  
  3708.  
  3709.  
  3710.  
  3711.  
  3712.  
  3713.  
  3714.  
  3715.  
  3716.  
  3717.  
  3718.  
  3719.  
  3720.  
  3721.  
  3722.  
  3723.  
  3724.  
  3725.  
  3726.  
  3727.  
  3728.  
  3729.  
  3730.  
  3731.  
  3732.  
  3733.  
  3734.  
  3735.  
  3736.  
  3737.  
  3738.  
  3739.  
  3740.  
  3741.  
  3742.  
  3743.  
  3744.  
  3745.  
  3746.  
  3747.  
  3748.  
  3749.  
  3750.  
  3751.  
  3752.  
  3753.  
  3754.  
  3755.  
  3756.  
  3757.  
  3758.  
  3759.  
  3760.  
  3761.  
  3762.  
  3763.  
  3764.    Page 56                              HI-TECH C USER'S MANUAL
  3765.  
  3766.  
  3767.  
  3768.  
  3769.  
  3770.  
  3771.  
  3772.  
  3773.  
  3774.  
  3775.  
  3776.  
  3777.  
  3778.  
  3779.  
  3780.  
  3781.  
  3782.  
  3783.  
  3784.  
  3785.  
  3786.  
  3787.  
  3788.  
  3789.  
  3790.  
  3791.  
  3792.  
  3793.  
  3794.  
  3795.  
  3796.  
  3797.  
  3798.  
  3799.  
  3800.  
  3801.  
  3802.  
  3803.  
  3804.  
  3805.  
  3806.  
  3807.  
  3808.  
  3809.  
  3810.  
  3811.  
  3812.  
  3813.  
  3814.  
  3815.  
  3816.  
  3817.  
  3818.  
  3819.  
  3820.  
  3821.  
  3822.  
  3823.  
  3824.  
  3825.  
  3826.  
  3827.  
  3828.  
  3829.  
  3830.        HI-TECH C USER'S MANUAL                              Page 57
  3831.  
  3832.  
  3833.  
  3834.  
  3835.  
  3836.  
  3837.  
  3838.  
  3839.  
  3840.  
  3841.  
  3842.  
  3843.  
  3844.  
  3845.  
  3846.  
  3847.  
  3848.  
  3849.  
  3850.  
  3851.  
  3852.  
  3853.  
  3854.  
  3855.  
  3856.  
  3857.  
  3858.  
  3859.  
  3860.  
  3861.  
  3862.  
  3863.  
  3864.  
  3865.  
  3866.  
  3867.  
  3868.  
  3869.  
  3870.  
  3871.  
  3872.  
  3873.  
  3874.  
  3875.  
  3876.  
  3877.  
  3878.  
  3879.  
  3880.  
  3881.  
  3882.  
  3883.  
  3884.  
  3885.  
  3886.  
  3887.  
  3888.  
  3889.  
  3890.  
  3891.  
  3892.  
  3893.  
  3894.  
  3895.  
  3896.    Page 58                              HI-TECH C USER'S MANUAL
  3897.  
  3898.  
  3899.  
  3900.  
  3901.  
  3902.  
  3903.  
  3904.  
  3905.  
  3906.  
  3907.  
  3908.  
  3909.  
  3910.  
  3911.  
  3912.  
  3913.  
  3914.  
  3915.  
  3916.  
  3917.  
  3918.  
  3919.  
  3920.  
  3921.  
  3922.  
  3923.  
  3924.  
  3925.  
  3926.  
  3927.  
  3928.  
  3929.  
  3930.  
  3931.  
  3932.  
  3933.  
  3934.  
  3935.  
  3936.  
  3937.  
  3938.  
  3939.  
  3940.  
  3941.  
  3942.  
  3943.  
  3944.  
  3945.  
  3946.  
  3947.  
  3948.  
  3949.  
  3950.  
  3951.  
  3952.  
  3953.  
  3954.  
  3955.  
  3956.  
  3957.  
  3958.  
  3959.  
  3960.  
  3961.  
  3962.        HI-TECH C USER'S MANUAL                              Page 59
  3963.  
  3964.  
  3965.  
  3966.  
  3967.  
  3968.  
  3969.  
  3970.  
  3971.  
  3972.  
  3973.  
  3974.  
  3975.  
  3976.  
  3977.  
  3978.  
  3979.  
  3980.  
  3981.  
  3982.  
  3983.  
  3984.  
  3985.  
  3986.  
  3987.  
  3988.  
  3989.  
  3990.  
  3991.  
  3992.  
  3993.  
  3994.  
  3995.  
  3996.  
  3997.  
  3998.  
  3999.  
  4000.  
  4001.  
  4002.  
  4003.  
  4004.  
  4005.  
  4006.  
  4007.  
  4008.  
  4009.  
  4010.  
  4011.  
  4012.  
  4013.  
  4014.  
  4015.  
  4016.  
  4017.  
  4018.  
  4019.  
  4020.  
  4021.  
  4022.  
  4023.  
  4024.  
  4025.  
  4026.  
  4027.  
  4028.    Page 60                              HI-TECH C USER'S MANUAL
  4029.  
  4030.  
  4031.  
  4032.  
  4033.  
  4034.  
  4035.  
  4036.  
  4037.  
  4038.  
  4039.  
  4040.  
  4041.  
  4042.  
  4043.  
  4044.  
  4045.  
  4046.  
  4047.  
  4048.  
  4049.  
  4050.  
  4051.  
  4052.  
  4053.  
  4054.  
  4055.  
  4056.  
  4057.  
  4058.  
  4059.  
  4060.  
  4061.  
  4062.  
  4063.  
  4064.  
  4065.  
  4066.  
  4067.  
  4068.  
  4069.  
  4070.  
  4071.  
  4072.  
  4073.  
  4074.  
  4075.  
  4076.  
  4077.  
  4078.  
  4079.  
  4080.  
  4081.  
  4082.  
  4083.  
  4084.  
  4085.  
  4086.  
  4087.  
  4088.  
  4089.  
  4090.  
  4091.  
  4092.  
  4093.  
  4094.        HI-TECH C USER'S MANUAL                              Page 61
  4095.  
  4096.  
  4097.  
  4098.  
  4099.  
  4100.  
  4101.  
  4102.  
  4103.  
  4104.  
  4105.  
  4106.  
  4107.  
  4108.  
  4109.  
  4110.  
  4111.  
  4112.  
  4113.  
  4114.  
  4115.  
  4116.  
  4117.  
  4118.  
  4119.  
  4120.  
  4121.  
  4122.  
  4123.  
  4124.  
  4125.  
  4126.  
  4127.  
  4128.  
  4129.  
  4130.  
  4131.  
  4132.  
  4133.  
  4134.  
  4135.  
  4136.  
  4137.  
  4138.  
  4139.  
  4140.  
  4141.  
  4142.  
  4143.  
  4144.  
  4145.  
  4146.  
  4147.  
  4148.  
  4149.  
  4150.  
  4151.  
  4152.  
  4153.  
  4154.  
  4155.  
  4156.  
  4157.  
  4158.  
  4159.  
  4160.    Page 62                              HI-TECH C USER'S MANUAL
  4161.  
  4162.  
  4163.  
  4164.  
  4165.  
  4166.  
  4167.  
  4168.  
  4169.  
  4170.  
  4171.  
  4172.  
  4173.  
  4174.  
  4175.  
  4176.  
  4177.  
  4178.  
  4179.  
  4180.  
  4181.  
  4182.  
  4183.  
  4184.  
  4185.  
  4186.  
  4187.  
  4188.  
  4189.  
  4190.  
  4191.  
  4192.  
  4193.  
  4194.  
  4195.  
  4196.  
  4197.  
  4198.  
  4199.  
  4200.  
  4201.  
  4202.  
  4203.  
  4204.  
  4205.  
  4206.  
  4207.  
  4208.  
  4209.  
  4210.  
  4211.  
  4212.  
  4213.  
  4214.  
  4215.  
  4216.  
  4217.  
  4218.  
  4219.  
  4220.  
  4221.  
  4222.  
  4223.  
  4224.  
  4225.  
  4226.        HI-TECH C USER'S MANUAL                              Page 63
  4227.  
  4228.  
  4229.  
  4230.  
  4231.  
  4232.  
  4233.  
  4234.  
  4235.  
  4236.  
  4237.  
  4238.  
  4239.  
  4240.  
  4241.  
  4242.  
  4243.  
  4244.  
  4245.  
  4246.  
  4247.  
  4248.  
  4249.  
  4250.  
  4251.  
  4252.  
  4253.  
  4254.  
  4255.  
  4256.  
  4257.  
  4258.  
  4259.  
  4260.  
  4261.  
  4262.  
  4263.  
  4264.  
  4265.  
  4266.  
  4267.  
  4268.  
  4269.  
  4270.  
  4271.  
  4272.  
  4273.  
  4274.  
  4275.  
  4276.  
  4277.  
  4278.  
  4279.  
  4280.  
  4281.  
  4282.  
  4283.  
  4284.  
  4285.  
  4286.  
  4287.  
  4288.  
  4289.  
  4290.  
  4291.  
  4292.    Page 64                              HI-TECH C USER'S MANUAL
  4293.  
  4294.  
  4295.  
  4296.  
  4297.  
  4298.  
  4299.  
  4300.  
  4301.  
  4302.  
  4303.  
  4304.  
  4305.  
  4306.  
  4307.  
  4308.  
  4309.  
  4310.  
  4311.  
  4312.  
  4313.  
  4314.  
  4315.  
  4316.  
  4317.  
  4318.  
  4319.  
  4320.  
  4321.  
  4322.  
  4323.  
  4324.  
  4325.  
  4326.  
  4327.  
  4328.  
  4329.  
  4330.  
  4331.  
  4332.  
  4333.  
  4334.  
  4335.  
  4336.  
  4337.  
  4338.  
  4339.  
  4340.  
  4341.  
  4342.  
  4343.  
  4344.  
  4345.  
  4346.  
  4347.  
  4348.  
  4349.  
  4350.  
  4351.  
  4352.  
  4353.  
  4354.  
  4355.  
  4356.  
  4357.  
  4358.        HI-TECH C USER'S MANUAL                              Page 65
  4359.  
  4360.  
  4361.  
  4362.  
  4363.  
  4364.  
  4365.  
  4366.  
  4367.  
  4368.  
  4369.  
  4370.  
  4371.  
  4372.  
  4373.  
  4374.  
  4375.  
  4376.  
  4377.  
  4378.  
  4379.  
  4380.  
  4381.  
  4382.  
  4383.  
  4384.  
  4385.  
  4386.  
  4387.  
  4388.  
  4389.  
  4390.  
  4391.  
  4392.  
  4393.  
  4394.  
  4395.  
  4396.  
  4397.  
  4398.  
  4399.  
  4400.  
  4401.  
  4402.  
  4403.  
  4404.  
  4405.  
  4406.  
  4407.  
  4408.  
  4409.  
  4410.  
  4411.  
  4412.  
  4413.  
  4414.  
  4415.  
  4416.  
  4417.  
  4418.  
  4419.  
  4420.  
  4421.  
  4422.  
  4423.  
  4424.    Page 66                              HI-TECH C USER'S MANUAL
  4425.  
  4426.  
  4427.  
  4428.  
  4429.  
  4430.  
  4431.  
  4432.  
  4433.  
  4434.  
  4435.  
  4436.  
  4437.  
  4438.  
  4439.  
  4440.  
  4441.  
  4442.  
  4443.  
  4444.  
  4445.  
  4446.  
  4447.  
  4448.  
  4449.  
  4450.  
  4451.  
  4452.  
  4453.  
  4454.  
  4455.  
  4456.  
  4457.  
  4458.  
  4459.  
  4460.  
  4461.  
  4462.  
  4463.  
  4464.  
  4465.  
  4466.  
  4467.  
  4468.  
  4469.  
  4470.  
  4471.  
  4472.  
  4473.  
  4474.  
  4475.  
  4476.  
  4477.  
  4478.  
  4479.  
  4480.  
  4481.  
  4482.  
  4483.  
  4484.  
  4485.  
  4486.  
  4487.  
  4488.  
  4489.  
  4490.        HI-TECH C USER'S MANUAL                              Page 67
  4491.  
  4492.  
  4493.  
  4494.  
  4495.  
  4496.  
  4497.  
  4498.  
  4499.  
  4500.  
  4501.  
  4502.  
  4503.  
  4504.  
  4505.  
  4506.  
  4507.  
  4508.  
  4509.  
  4510.  
  4511.  
  4512.  
  4513.  
  4514.  
  4515.  
  4516.  
  4517.  
  4518.  
  4519.  
  4520.  
  4521.  
  4522.  
  4523.  
  4524.  
  4525.  
  4526.  
  4527.  
  4528.  
  4529.  
  4530.  
  4531.  
  4532.  
  4533.  
  4534.  
  4535.  
  4536.  
  4537.  
  4538.  
  4539.  
  4540.  
  4541.  
  4542.  
  4543.  
  4544.  
  4545.  
  4546.  
  4547.  
  4548.  
  4549.  
  4550.  
  4551.  
  4552.  
  4553.  
  4554.  
  4555.  
  4556.    Page 68                              HI-TECH C USER'S MANUAL
  4557.  
  4558.  
  4559.  
  4560.  
  4561.  
  4562.  
  4563.  
  4564.  
  4565.  
  4566.  
  4567.  
  4568.  
  4569.  
  4570.  
  4571.  
  4572.  
  4573.  
  4574.  
  4575.  
  4576.  
  4577.  
  4578.  
  4579.  
  4580.  
  4581.  
  4582.  
  4583.  
  4584.  
  4585.  
  4586.  
  4587.  
  4588.  
  4589.  
  4590.  
  4591.  
  4592.  
  4593.  
  4594.  
  4595.  
  4596.  
  4597.  
  4598.  
  4599.  
  4600.  
  4601.  
  4602.  
  4603.  
  4604.  
  4605.  
  4606.  
  4607.  
  4608.  
  4609.  
  4610.  
  4611.  
  4612.  
  4613.  
  4614.  
  4615.  
  4616.  
  4617.  
  4618.  
  4619.  
  4620.  
  4621.  
  4622.        HI-TECH C USER'S MANUAL                              Page 69
  4623.  
  4624.  
  4625.        13. Linker Reference Manual
  4626.  
  4627.  
  4628.             HI-TECH  C  incorporates  a  relocating  assembler  and
  4629.        linker  to  permit  separate  compilation of C source files.
  4630.        This means that a program may be divided into several source
  4631.        files,  each  of  which may be kept to a manageable size for
  4632.        ease of editing and compilation, then each object file  com-
  4633.        piled  separately  and  finally  all the object files linked
  4634.        together into a single executable program.
  4635.  
  4636.             The assembler  is  described  in  the  machine-specific
  4637.        manual.   This  appendix describes the theory behind and the
  4638.        usage of the linker.
  4639.  
  4640.        13.1. Relocation and Psects
  4641.  
  4642.             The fundamental  task  of  the  linker  is  to  combine
  4643.        several  relocatable object files into one. The object files
  4644.        are said to be relocatable since the files  have  sufficient
  4645.        information  in  them  so  that any references to program or
  4646.        data addresses (e.g. the address of a function)  within  the
  4647.        file  may  be  adjusted according to where the file is ulti-
  4648.        mately located in memory after the linkage process. Thus the
  4649.        file  is  said  to  be  relocatable. Relocation may take two
  4650.        basic forms; relocation by  name,  i.e.  relocation  by  the
  4651.        ultimate  value  of a global symbol, or relocation by psect,
  4652.        i.e. relocation by the base address of a particular  section
  4653.        of  code,  for  example  the  section of code containing the
  4654.        actual excutable instructions.
  4655.  
  4656.        13.1.1. Program Sections
  4657.  
  4658.             Any object file may  contain  bytes  to  be  stored  in
  4659.        memory  in  one  or  more  program  sections,  which will be
  4660.        referred to as psects. These psects represent logical group-
  4661.        ings  of  certain  types  of code bytes in the program.  The
  4662.        section of the program containing executable instructions is
  4663.        normally  referred  to as the text psect. Other sections are
  4664.        the initialized data psect, called simply  the  data  psect,
  4665.        and the uninitialized data psect, called the bss psect.
  4666.  
  4667.             In fact the linker will handle any  number  of  psects,
  4668.        and  in  fact more may be used in special applications. How-
  4669.        ever the C compiler uses only the three mentioned,  and  the
  4670.        names  text,  data and bss are simply chosen for identifica-
  4671.        tion; the linker assigns no special significance to the name
  4672.        of a psect.
  4673.  
  4674.             The difference between the data and bss psects  may  be
  4675.        exemplified  by  considering  two external variables; one is
  4676.        initialized to the value 1, and the other  is  not  initial-
  4677.        ized.  The first will be placed into the data psect, and the
  4678.        second in the bss psect. The bss psect is always cleared  to
  4679.        zeros  on  startup  of the program, thus the second variable
  4680.        will be initialized at run time to zero. The first will how-
  4681.        ever occupy space in the program file, and will maintain its
  4682.  
  4683.  
  4684.  
  4685.  
  4686.  
  4687.  
  4688.    Page 70                              HI-TECH C USER'S MANUAL
  4689.  
  4690.    initialized value of 1 at startup. It is quite  possible  to
  4691.    modify the value of a variable in the data psect during exe-
  4692.    cution, however it is better practice not to  do  so,  since
  4693.    this  leads  to more consistent use of variables, and allows
  4694.    for restartable and romable programs.
  4695.  
  4696.         The text psect is the section into which all executable
  4697.    instructions are placed. On CP/M-80 the text psect will nor-
  4698.    mally start at the base of the TPA, which is where execution
  4699.    commences.  The  data  psect  will  normally follow the text
  4700.    psect, and the bss will be last. The  bss  does  not  occupy
  4701.    space  in  the  program (.COM) file. This ordering of psects
  4702.    may be overridden by an option to the linker. This is  espe-
  4703.    cially useful when producing code for special hardware.
  4704.  
  4705.         For MS-DOS and CP/M-86 the psects are  ordered  in  the
  4706.    same way, but since the 8086 processor has segment registers
  4707.    providing relocation, both the text and data psects start at
  4708.    0,  even  though  they will be loaded one after the other in
  4709.    memory. This allows 64k code and 64k data and stack.  Suffi-
  4710.    cient  information is placed in the executable file (.EXE or
  4711.    .CMD) for the  operating  system  to  load  the  program  in
  4712.    memory.
  4713.  
  4714.    13.1.2. Local Psects and the Large Model
  4715.  
  4716.         Since for practical purposes the psects are limited  to
  4717.    64K  on  the  8086, to allow more than 64K code the compiler
  4718.    makes use of local psects. A psect is  considered  local  if
  4719.    the  .psect  directive has a LOCAL flag. Any number of local
  4720.    psects may be linked from different  modules  without  being
  4721.    combined  even if they have the same name. Note however that
  4722.    no local psect may have the same name as a global psect.
  4723.  
  4724.         All references to a local psect within the same  module
  4725.    (or  within  the same library) will be treated as references
  4726.    to the same psect. Between modules however two local  psects
  4727.    of the same name are treated as distinct.  In order to allow
  4728.    collective referencing of local psects  via  the  -P  option
  4729.    (described  later) a local psect may have a class name asso-
  4730.    ciated with it. This is achieved witht the _C_L_A_S_S flag on the
  4731.    .psect directive.
  4732.  
  4733.    13.2. Global Symbols
  4734.  
  4735.         The  linker  handles  only  symbols  which  have   been
  4736.    declared  as  global  to  the  assembler.  From the C source
  4737.    level, this means all names which have storage class  exter-
  4738.    nal  and which are not declared as static. These symbols may
  4739.    be referred to by modules other than the one in  which  they
  4740.    are  defined. It is the linker's job to match up the defini-
  4741.    tion of a global symbol with the references to it.
  4742.  
  4743.  
  4744.  
  4745.  
  4746.  
  4747.  
  4748.  
  4749.  
  4750.  
  4751.  
  4752.  
  4753.  
  4754.        HI-TECH C USER'S MANUAL                              Page 71
  4755.  
  4756.        13.3. Operation
  4757.  
  4758.             A command to the linker takes the following form:
  4759.  
  4760.             LINK options files ...
  4761.  
  4762.  
  4763.             Options is zero or more linker options, each  of  which
  4764.        modifies  the  behaviour of the linker in some way. Files is
  4765.        one or more object files, and zero or  more  library  names.
  4766.        The  options  recognized  by the linker are as follows: they
  4767.        will be recognized in upper or lower case.
  4768.  
  4769.        -R   Leave the output relocatable.
  4770.  
  4771.        -L   Retain absolute relocation info. -LM will  retain  only
  4772.             segement relocation information.
  4773.  
  4774.        -I   Ignore undefined symbols.
  4775.  
  4776.        -N   Sort symbols by address.
  4777.  
  4778.        -Caddr
  4779.             Produce a binary output file offset by addr.
  4780.  
  4781.        -S   Strip symbol information from the output file.
  4782.  
  4783.        -X   Suppress local symbols in the output file.
  4784.  
  4785.        -Z   Suppress trivial (compiler-generated)  symbols  in  the
  4786.             output file.
  4787.  
  4788.        -Oname
  4789.             Call the output file name.
  4790.  
  4791.        -Pspec
  4792.             Spec is a psect location specification.
  4793.  
  4794.        -Mname
  4795.             Write a link map to the file name.
  4796.  
  4797.        -Usymbol
  4798.             Make symbol initially undefined.
  4799.  
  4800.        -Dfile
  4801.             Write a symbol file.
  4802.  
  4803.        -Wwidth
  4804.             Specify map width.
  4805.  
  4806.             Taking each of these in turn:
  4807.  
  4808.             The -R option will instruct the  linker  to  leave  the
  4809.        output  file  (as named by a -O option, or l.obj by default)
  4810.        relocatable. This is  normally  because  there  are  further
  4811.        files  to  be linked in, and the output of this link will be
  4812.        used as input  to  the  linker  subsequently.  Without  this
  4813.        option,  the linker will make the output file absolute, that
  4814.  
  4815.  
  4816.  
  4817.  
  4818.  
  4819.  
  4820.    Page 72                              HI-TECH C USER'S MANUAL
  4821.  
  4822.    is with all relocatable addresses made into absolute  refer-
  4823.    ences.   This  option  may  not  be  used  with the -L or -C
  4824.    options.
  4825.  
  4826.         The -L option will cause  the  linker  to  output  null
  4827.    relocation  information  even  though the file will be abso-
  4828.    lute. This information allows  self-relocating  programs  to
  4829.    know  what  addresses  must  be  relocated at run time. This
  4830.    option is not usable with the -C option. In order to  create
  4831.    an  executable  file (i.e. a .COM file) the program objtohex
  4832.    must be used.  If a -LM option is used, only segment reloca-
  4833.    tion  information will be retained.  This is used in conjuc-
  4834.    tion with the large memory  model.  Objtohex  will  use  the
  4835.    relocation  information  (when  invoked  with  a -L flag) to
  4836.    insert segment  relocation  addresses  into  the  executable
  4837.    file.
  4838.  
  4839.         The -I option is used when it is desired to  link  code
  4840.    which  contains symbols which are not defined in any module.
  4841.    This is normally only used during top-down program  develop-
  4842.    ment,  when  routines  are referenced in code written before
  4843.    the routines themselves have been coded.
  4844.  
  4845.         When obtaining a link map via the -M option, the symbol
  4846.    table  is by default sorted in order of symbol name. To sort
  4847.    in order of address, the -N option may be used.
  4848.  
  4849.         The output of the linker is by default an object  file.
  4850.    To create an executable program, this must be converted into
  4851.    an executable image. For CP/M this is a .COM file, which  is
  4852.    simply  an  image  of  the  executable  program as it should
  4853.    appear in memory, starting at location 100H. The linker will
  4854.    produce such a file with the -C100H option. File formats for
  4855.    other applications requiring an image binary file  may  also
  4856.    be  produced  with the -C option.  The address following the
  4857.    -C may be given in decimal (default), octal (by using o or O
  4858.    suffix) or hexadecimal (by using an h or H suffix).
  4859.  
  4860.         Note that because of the complexity of  the  executable
  4861.    file  formats  for MS-DOS and CP/M-86, LINK will not produce
  4862.    these (.EXE and .CMD resp.) formats directly.  The  compiler
  4863.    automatically runs OBJTOHEX with appropriate options to gen-
  4864.    erate the correct file format.
  4865.  
  4866.         The -S, -X and -Z options, which are  meaningless  when
  4867.    the  -C option is used, will strip respectively all symbols,
  4868.    all local symbols or all trivial local symbols from the out-
  4869.    put  file.  Trivial symbols are symbols produced by the com-
  4870.    piler, and have the form of one of a set of alphabetic char-
  4871.    acters followed by a digit string.
  4872.  
  4873.         The default output file name is _l._o_b_j,  or  _l._b_i_n  when
  4874.    the -C option is used.  This may be overridden by the -O_n_a_m_e
  4875.    option.  The  output  file  will  be  called  _n_a_m_e  in  this
  4876.    instance.  Note  that no suffix is appended to the name; the
  4877.    file will be called exactly the argument to the option.
  4878.  
  4879.         For certain specialized  applications,  e.g.  producing
  4880.  
  4881.  
  4882.  
  4883.  
  4884.  
  4885.  
  4886.        HI-TECH C USER'S MANUAL                              Page 73
  4887.  
  4888.        code  for  an  embedded  microprocessor,  it is necessary to
  4889.        specify to the linker at what  address  the  various  psects
  4890.        should  be located. This is accomplished with the -P option.
  4891.        It is followed by a specification  consisting  of  a  comma-
  4892.        separated list of psect names, each with an optional address
  4893.        specification. In the absence of  an  address  specification
  4894.        for  a psect listed, it will be concatenated with the previ-
  4895.        ous psect. For example
  4896.  
  4897.             -Ptext=0c000h,data,bss=8000h
  4898.  
  4899.  
  4900.             This will cause the text psect to be located at 0C000H,
  4901.        the  data  psect  to start at the end of the text psect, and
  4902.        the bss psect to start at 8000H. This may be for a processor
  4903.        with ROM at 0C000H and RAM at 8000H.
  4904.  
  4905.             Where the link address, that is the  address  at  which
  4906.        the  code  will be addressed at execution time, and the load
  4907.        address, that is the address offset within the output  file,
  4908.        are  different  (e.g for the 8086) it is possible to specify
  4909.        the load address separately from the link address. For exam-
  4910.        ple:
  4911.  
  4912.             -Ptext=100h/0,data=0C000h/
  4913.  
  4914.  
  4915.             This specification will cause the text  segment  to  be
  4916.        linked  for execution at 100h, but loaded in the output file
  4917.        at 0, while the data segment will be linked for 0C000h,  but
  4918.        loaded  contiguously  with the text psect in the file.  Note
  4919.        that if the slash (`/') is omitted, the load address is  the
  4920.        same  as  the  link address, while if the slash is supplied,
  4921.        but not followed by an address, the  psect  will  be  loaded
  4922.        after the previous psect.
  4923.  
  4924.             In order to specify link and load addresses  for  local
  4925.        psects,  the  group  name  to which the psects belong may be
  4926.        used in place of a global psect name. The local psects  will
  4927.        then  have a link address as specified in the -P option, and
  4928.        load addresses incrementing upwards from the specified  load
  4929.        address.
  4930.  
  4931.             The -Mname option requests a link map, containing  sym-
  4932.        bol  table and module load address information to be written
  4933.        onto the file name. If name is  omitted,  the  map  will  be
  4934.        written  to  standard  output. -W may be used to specify the
  4935.        desired width of the map.
  4936.  
  4937.             The -U option allows the specification to the linker of
  4938.        a  symbol  which  is to be initially entered into the symbol
  4939.        table as undefined. This is  useful  when  loading  entirely
  4940.        from libraries. More than one -U flag may be used.
  4941.  
  4942.             If it is desired to use the  debugger  on  the  program
  4943.        being  linked,  it  is  useful to produce a symbol file. The
  4944.        -D_f_i_l_e option will write such a symbol file onto  the  named
  4945.        _f_i_l_e, or _l._s_y_m if no file is given. The symbol file consists
  4946.  
  4947.  
  4948.  
  4949.  
  4950.  
  4951.  
  4952.    Page 74                              HI-TECH C USER'S MANUAL
  4953.  
  4954.    of a list of addresses and symbols, one per line.
  4955.  
  4956.    13.4. Examples
  4957.  
  4958.         Here are some examples of using the linker.  Note  how-
  4959.    ever  that  in the normal case it is not necessary to invoke
  4960.    the linker explicitly, since it is invoked automatically  by
  4961.    the C command.
  4962.  
  4963.    LINK -MMAP -C100H START.OBJ MAIN.OBJ A:LIBC.LIB
  4964.  
  4965.  
  4966.         This command links the  files  start.obj  and  main.obj
  4967.    with  the  library  a:libc.lib.  Only those modules that are
  4968.    required from the library will be in  fact  linked  in.  The
  4969.    output  is  to be in .COM format, placed in the default file
  4970.    l.bin. A map is to be written to the file of the  name  map.
  4971.    Note  that  the  file start.obj should contain startup code,
  4972.    and in fact the lowest address code in  that  file  will  be
  4973.    executed when the program is run, since it will be at 100H.
  4974.  
  4975.         LINK -X -R -OX.OBJ FILE1.OBJ FILE2.OBJ A:LIBC.LIB
  4976.  
  4977.  
  4978.         The files file1.obj and file2.obj will be  linked  with
  4979.    any  necessary routines from a:libc.lib and left in the file
  4980.    x.obj.  This file will remain relocatable. Undefined symbols
  4981.    will not cause an error.  The file x.obj will probably later
  4982.    be the object of another link invocation.  All local symbols
  4983.    will be stripped from the output file, thus saving space.
  4984.  
  4985.    13.5. Invoking the Linker
  4986.  
  4987.         The linker is called LINK, and normally resides on  the
  4988.    A:  drive,  under CP/M, or in the directory A:\HITECH\ under
  4989.    MS-DOS. It may be invoked with no arguments, in  which  case
  4990.    it  will  prompt for input from standard input. If the stan-
  4991.    dard input is a file, no prompts will be printed.  The input
  4992.    supplied in this manner may contain lower case, whereas CP/M
  4993.    converts the entire command line to upper case  by  default.
  4994.    This  is useful with the -U  and -P options.  This manner of
  4995.    invocation is generally useful if the number of arguments to
  4996.    LINK  is large. Even if the list of files is too long to fit
  4997.    on one line, continuation lines may be included by leaving a
  4998.    backslash  ('\')  at  the end of the preceding line. In this
  4999.    fashion, LINK commands of almost  unlimited  length  may  be
  5000.    issued.
  5001.  
  5002.  
  5003.  
  5004.  
  5005.  
  5006.  
  5007.  
  5008.  
  5009.  
  5010.  
  5011.  
  5012.  
  5013.  
  5014.  
  5015.  
  5016.  
  5017.  
  5018.        HI-TECH C USER'S MANUAL                              Page 75
  5019.  
  5020.  
  5021.        14. Librarian
  5022.  
  5023.  
  5024.             The librarian program, LIBR, has the function  of  com-
  5025.        bining  several  object  files into a single file known as a
  5026.        library. The  purposes  of  combining  several  such  object
  5027.        modules are several.
  5028.  
  5029.             a.   fewer files to link
  5030.             b.   faster access
  5031.             c.   uses less disk space
  5032.  
  5033.  
  5034.             In order to make the  library  concept  useful,  it  is
  5035.        necessary  for the linker to treat modules in a library dif-
  5036.        ferently from object files. If an object file  is  specified
  5037.        to  the  linker,  it  will  be  linked into the final linked
  5038.        module. A module in a library, however, will only be  linked
  5039.        in  if  it defines one or more symbols previously known, but
  5040.        not defined, to the linker. Thus modules in a  library  will
  5041.        be  linked  only if required. Since the choice of modules to
  5042.        link is made on the  first  pass  of  the  linker,  and  the
  5043.        library  is  searched in a linear fashion, it is possible to
  5044.        order the modules in a library to  produce  special  effects
  5045.        when linking.  More will be said about this later.
  5046.  
  5047.        14.1. The Library Format
  5048.  
  5049.             The modules  in  a  library  are  basically  just  con-
  5050.        catenated, but at the beginning of a library is maintained a
  5051.        directory of the modules and symbols in the  library.  Since
  5052.        this  directory  is smaller than the sum of the modules, the
  5053.        linker is speeded up when searching a library since it  need
  5054.        read only the directory and not all the modules on the first
  5055.        pass. On the second pass it need  read  only  those  modules
  5056.        which are required, seeking over the others. This all minim-
  5057.        izes disk i/o when linking.
  5058.  
  5059.             It should be noted that the library  format  is  geared
  5060.        exclusively toward object modules, and is not a general pur-
  5061.        pose archiving mechanism as is used by some  other  compiler
  5062.        systems.  This  has  the  advantage  that  the format may be
  5063.        optimized toward speeding up the linkage process.
  5064.  
  5065.        14.2. Using
  5066.  
  5067.             The librarian program is called LIBR, and the format of
  5068.        commands to it is as follows:
  5069.  
  5070.             LIBR k file.lib file.obj ...
  5071.  
  5072.  
  5073.             Interpreting this, LIBR is the name of the  program,  k
  5074.        is  a  key  letter  denoting  the  function requested of the
  5075.        librarian (replacing, extracting or deleting modules,  list-
  5076.        ing modules or symbols), file.lib is the name of the library
  5077.        file to be operated on, and file.obj is zero or more  object
  5078.  
  5079.  
  5080.  
  5081.  
  5082.  
  5083.  
  5084.    Page 76                              HI-TECH C USER'S MANUAL
  5085.  
  5086.    file names.
  5087.  
  5088.         The key letters are:
  5089.  
  5090.         r       replace modules
  5091.         d       delete modules
  5092.         x       extract modules
  5093.         m       list module names
  5094.         s       list modules with symbols
  5095.  
  5096.  
  5097.         When replacing  or  extracting  modules,  the  file.obj
  5098.    arguments  are  the  names  of the modules to be replaced or
  5099.    extracted. If  no  such  arguments  are  supplied,  all  the
  5100.    modules in the library will be replaced or extracted respec-
  5101.    tively.  Adding a file to a library is performed by request-
  5102.    ing  the librarian to replace it in the library. Since it is
  5103.    not present, the module will be appended to the library.  If
  5104.    the r key is used and the library does not exist, it will be
  5105.    created.
  5106.  
  5107.         Under the d keyletter, the named object files  will  be
  5108.    deleted  from the library.  In this instance, it is an error
  5109.    not to give any object file names.
  5110.  
  5111.         The m and s keyletters will list the named modules and,
  5112.    in  the  case  of  the  s  keyletter, the symbols defined or
  5113.    referenced within (global symbols only are  handled  by  the
  5114.    librarian). As with the r and x keyletters, an empty list of
  5115.    modules means all the modules in the library.
  5116.  
  5117.    14.3. Examples
  5118.  
  5119.         Here are some examples of usage of the librarian.
  5120.  
  5121.    LIBR m file.lib
  5122.         List all modules in the library file.lib.
  5123.  
  5124.    LIBR s file.lib a.obj b.obj c.obj
  5125.         List the global symbols in the modules a.obj, b.obj and
  5126.         c.obj
  5127.  
  5128.    LIBR r file.lib 1.obj 2.obj
  5129.         Replace the module 1.obj in the file file.lib with  the
  5130.         contents  of  the  object  file  1.obj,  and repeat for
  5131.         2.obj. If the object module is not already  present  in
  5132.         the library, append it to the end.
  5133.  
  5134.    LIBR x file.lib
  5135.         Extract, without deletion, all the modules in  file.lib
  5136.         and write them as object files on disk.
  5137.  
  5138.    LIBR d file.lib a.obj b.obj 2.obj
  5139.         Delete the object modules a.obj, b.obj and  2.obj  from
  5140.         the library file.lib.
  5141.  
  5142.  
  5143.  
  5144.  
  5145.  
  5146.  
  5147.  
  5148.  
  5149.  
  5150.        HI-TECH C USER'S MANUAL                              Page 77
  5151.  
  5152.        14.4. Supplying Arguments
  5153.  
  5154.             Since it is often necessary to supply many object  file
  5155.        arguments  to  LIBR, and command lines are restricted to 127
  5156.        characters by CP/M and MS-DOS,  LIBR  will  accept  commands
  5157.        from  standard input if no command line arguments are given.
  5158.        If the standard input is attached to the console, LIBR  will
  5159.        prompt.  Multiple  line  input  may  be  given  by  using  a
  5160.        backslash as a continuation character on the end of a  line.
  5161.        If  standard input is redirected from a file, LIBR will take
  5162.        input from the file, without prompting. For example:
  5163.  
  5164.             LIBR
  5165.             libr> r file.lib 1.obj 2.obj 3.obj \
  5166.             libr> 4.obj 5.obj 6.obj
  5167.  
  5168.        will perform much the same as if the  .obj  files  had  been
  5169.        typed on the command line. The libr> prompts were printed by
  5170.        LIBR itself, the remainder of the text was typed as input.
  5171.  
  5172.             LIBR <lib.cmd
  5173.  
  5174.  
  5175.             Libr will read input from lib.cmd, and execute the com-
  5176.        mand found therein. This allows a virtually unlimited length
  5177.        command to be given to LIBR.
  5178.  
  5179.        14.5. Listing Format
  5180.  
  5181.             A request to LIBR to list module names will simply pro-
  5182.        duce  a list of names, one per line, on standard output. The
  5183.        s keyletter will produce the same, with a  list  of  symbols
  5184.        after  each module name. Each symbol will be preceded by the
  5185.        letter D or U, representing a definition or reference to the
  5186.        symbol  respectively. The -W option may be used to determine
  5187.        the width of the paper for this operation. For example  LIBR
  5188.        -w80 s file.lib will list all modules in file.lib with their
  5189.        global symbols, with the output formatted for an  80  column
  5190.        printer or display.
  5191.  
  5192.        14.6. Ordering of Libraries
  5193.  
  5194.             The librarian creates libraries with the modules in the
  5195.        order  in  which  they  were given on the command line. When
  5196.        updating a library the order of the  modules  is  preserved.
  5197.        Any new modules added to a library after it has been created
  5198.        will be appended to the end.
  5199.  
  5200.             The ordering of the modules in a library is significant
  5201.        to  the  linker. If a library contains a module which refer-
  5202.        ences a  symbol  defined  in  another  module  in  the  same
  5203.        library,  the  module  defining the symbol should come after
  5204.        the module referencing the symbol.
  5205.  
  5206.  
  5207.  
  5208.  
  5209.  
  5210.  
  5211.  
  5212.  
  5213.  
  5214.  
  5215.  
  5216.    Page 78                              HI-TECH C USER'S MANUAL
  5217.  
  5218.    14.7. Error Messages
  5219.  
  5220.         Libr issues  various  error  messages,  most  of  which
  5221.    represent  a  fatal  error,  while some represent a harmless
  5222.    occurence which will nonetheless be reported unless  the  -w
  5223.    option  was  used. In this case all warning messages will be
  5224.    suppressed.
  5225.  
  5226.  
  5227.  
  5228.  
  5229.  
  5230.  
  5231.  
  5232.  
  5233.  
  5234.  
  5235.  
  5236.  
  5237.  
  5238.  
  5239.  
  5240.  
  5241.  
  5242.  
  5243.  
  5244.  
  5245.  
  5246.  
  5247.  
  5248.  
  5249.  
  5250.  
  5251.  
  5252.  
  5253.  
  5254.  
  5255.  
  5256.  
  5257.  
  5258.  
  5259.  
  5260.  
  5261.  
  5262.  
  5263.  
  5264.  
  5265.  
  5266.  
  5267.  
  5268.  
  5269.  
  5270.  
  5271.  
  5272.  
  5273.  
  5274.  
  5275.  
  5276.  
  5277.  
  5278.  
  5279.  
  5280.  
  5281.  
  5282.        HI-TECH C USER'S MANUAL                              Page 79
  5283.  
  5284.  
  5285.        15. Objtohex
  5286.  
  5287.  
  5288.             The HI-TECH  linker  is  capable  of  producing  simple
  5289.        binary  files,  or  object files as output. Any other format
  5290.        required must be produced by  running  the  utility  program
  5291.        OBJTOHEX.   This  allows  conversion of object files as pro-
  5292.        duced by the linker into a  variety  of  different  formats,
  5293.        including various hex formats. The program is invoked thus:
  5294.  
  5295.             OBJTOHEX options inputfile outputfile
  5296.  
  5297.  
  5298.             All of the arguments are  optional.  If  outputfile  is
  5299.        ommitted  it defaults to l.hex or l.bin depending on whether
  5300.        the -b option is used. The inputfile defaults to l.obj.
  5301.  
  5302.             The options are:
  5303.  
  5304.        -B_a_d_d_r
  5305.             Produce a binary image output. This is similar  to  the
  5306.             -C  option  of  the  linker.   If addr is supplied, the
  5307.             start of the image file will be offset by addr. If addr
  5308.             is  omitted,  the  first  byte  in the file will be the
  5309.             lowest byte initialized. Addr may be given in  decimal,
  5310.             octal or hexadecimal. The default radix is decimal, and
  5311.             suffix letters of o or O indicate octal,  and  h  or  H
  5312.             indicate  hex.  Thus -B100H will produce a file in .COM
  5313.             format.
  5314.  
  5315.        -I   Include symbol records in the Intel format hex  output.
  5316.             Each  symbol  record  has  a  form similar to an object
  5317.             record, but with a  different  record  type.  The  data
  5318.             bytes  in  the  record  are  the  symbol  name, and the
  5319.             address is the value of the symbol.  This is useful for
  5320.             downloading to ROM debuggers.
  5321.  
  5322.        -C   Read a checksum specification from the standard  input.
  5323.             The  checksum  specification  is described below. Typi-
  5324.             cally the specification will be in a file.
  5325.  
  5326.        -E_s_t_a_c_k
  5327.             This option produces an MS-DOS .EXE  format  file.  The
  5328.             optional  stack  argument  will  determine  the maximum
  5329.             stack size the program will be allocated on  execution.
  5330.             By  default  the  program will be allocated the maximum
  5331.             stack available, up to the limit  of  64K  data.  If  a
  5332.             stack  argument  is  supplied,  the stack size will not
  5333.             exceed the argument. This is useful to limit the amount
  5334.             of  memory a program will use. The stack argument takes
  5335.             the same form as the argument to -B above.
  5336.  
  5337.        -8_s_t_a_c_k
  5338.             This option will produce a CP/M-86 .CMD file. The stack
  5339.             argument is the same as for the -E option.
  5340.  
  5341.  
  5342.  
  5343.  
  5344.  
  5345.  
  5346.  
  5347.  
  5348.    Page 80                              HI-TECH C USER'S MANUAL
  5349.  
  5350.    -A_s_t_a_c_k
  5351.         This is used when producing a.out format files for unix
  5352.         systems  (specifically Venix-86). If the stack argument
  5353.         is zero, the size of the data segment will be 64k, oth-
  5354.         erwise the stack will be placed below the data segment,
  5355.         and its size set to stack.  This must  be  co-ordinated
  5356.         with  appropriate  arguments  to  the  -p option of the
  5357.         linker.
  5358.  
  5359.    -M   This flag will instruct objtohex  to  produce  Motorola
  5360.         'S' format hex output.
  5361.  
  5362.    -L   This option is used when  producing  large  model  pro-
  5363.         grams;  the  linker  will  have  been used with the -LM
  5364.         option to retain segment relocation information in  the
  5365.         object  file.  Use  of  the  -L option to objtohex will
  5366.         cause it to convert that segment relocation information
  5367.         into  appropriate  data  in the executable file for use
  5368.         when the program is loaded. Either the operating system
  5369.         or  the  run-time  startup code will use the relocation
  5370.         data to adjust segment references  based  on  where  in
  5371.         memory  the  program  is  actually  loaded.   If the -L
  5372.         option is followed by a symbol name, then  the  reloca-
  5373.         tion   information   will  be  stored  at  the  address
  5374.         represented by that symbol in  the  output  file,  e.g.
  5375.         -L___B_b_s_s  will cause it to be stored at the base of the
  5376.         bss psect (___B_b_s_s is defined by the linker  to  be  the
  5377.         load  address  of the bss psect). If the special symbol
  5378.         _D_o_s__h_d_r is used then the relocation information will be
  5379.         stored  in the .EXE file header.  This is only valid in
  5380.         conjunction with the -E option.
  5381.  
  5382.    -S   The -S option instructs  objtohex  to  write  a  symbol
  5383.         file.  The symbol file name is given after the -S, e.g.
  5384.         -S_x_x._s_y_m.
  5385.  
  5386.         Unless  another  format  is   specifically   requested,
  5387.    objtohex  will  produce  a file in Intel hex format. This is
  5388.    suitable for down-line loading, PROM programming  etc.   The
  5389.    HP  format is useful for transferring code to an HP64000 for
  5390.    emulation or PROM programming.
  5391.  
  5392.         The checksum specification  allows  automated  checksum
  5393.    calculation.  The  checksum  specification takes the form of
  5394.    several lines, each line describing one checksum. The syntax
  5395.    of a checksum line is:
  5396.  
  5397.         addr1-addr2 where1-where2 +offset
  5398.  
  5399.  
  5400.         All of addr1, addr2, where1, where2 and offset are  hex
  5401.    numbers,  without  the  usual H suffix. Such a specification
  5402.    says that the bytes at  addr1  through  to  addr2  inclusive
  5403.    should  be summed and the sum placed in the locations where1
  5404.    through where2 inclusive. For an 8 bit  checksum  these  two
  5405.    addresses should be the same. For a checksum stored low byte
  5406.    first, where1 should be less than where2,  and  vice  versa.
  5407.    The  +offset  is optional, but if supplied, the value offset
  5408.  
  5409.  
  5410.  
  5411.  
  5412.  
  5413.  
  5414.        HI-TECH C USER'S MANUAL                              Page 81
  5415.  
  5416.        will be used to initialize the  checksum.  Otherwise  it  is
  5417.        initialized to zero. For example:
  5418.  
  5419.             0005-1FFF 3-4 +1FFF
  5420.  
  5421.  
  5422.             This will sum the bytes in 5 through  1FFFH  inclusive,
  5423.        then  add  1FFFH  to  the  sum.  The 16 bit checksum will be
  5424.        placed in locations 3 and 4, low byte in 3. The checksum  is
  5425.        initialized  with 1FFFH to provide protection against an all
  5426.        zero rom, or a rom misplaced in memory. A run time check  of
  5427.        this  checksum  would  add the last address of the rom being
  5428.        checksummed into the checksum. For the rom in question, this
  5429.        should  be 1FFFH.  The initialization value may, however, be
  5430.        used in any desired fashion.
  5431.  
  5432.  
  5433.  
  5434.  
  5435.  
  5436.  
  5437.  
  5438.  
  5439.  
  5440.  
  5441.  
  5442.  
  5443.  
  5444.  
  5445.  
  5446.  
  5447.  
  5448.  
  5449.  
  5450.  
  5451.  
  5452.  
  5453.  
  5454.  
  5455.  
  5456.  
  5457.  
  5458.  
  5459.  
  5460.  
  5461.  
  5462.  
  5463.  
  5464.  
  5465.  
  5466.  
  5467.  
  5468.  
  5469.  
  5470.  
  5471.  
  5472.  
  5473.  
  5474.  
  5475.  
  5476.  
  5477.  
  5478.  
  5479.  
  5480.    Page 82                              HI-TECH C USER'S MANUAL
  5481.  
  5482.  
  5483.  
  5484.  
  5485.                      Use this page for notes
  5486.  
  5487.  
  5488.  
  5489.  
  5490.  
  5491.  
  5492.  
  5493.  
  5494.  
  5495.  
  5496.  
  5497.  
  5498.  
  5499.  
  5500.  
  5501.  
  5502.  
  5503.  
  5504.  
  5505.  
  5506.  
  5507.  
  5508.  
  5509.  
  5510.  
  5511.  
  5512.  
  5513.  
  5514.  
  5515.  
  5516.  
  5517.  
  5518.  
  5519.  
  5520.  
  5521.  
  5522.  
  5523.  
  5524.  
  5525.  
  5526.  
  5527.  
  5528.  
  5529.  
  5530.  
  5531.  
  5532.  
  5533.  
  5534.  
  5535.  
  5536.  
  5537.  
  5538.  
  5539.  
  5540.  
  5541.  
  5542.  
  5543.  
  5544.  
  5545.  
  5546.        HI-TECH C USER'S MANUAL                              Page 83
  5547.  
  5548.  
  5549.        16. Cref
  5550.  
  5551.  
  5552.             The cross reference list utility CREF is used to format
  5553.        raw  cross-reference information produced by the compiler or
  5554.        the assembler into a sorted listing.  A raw  cross-reference
  5555.        file  is  produced  with the -CR option to the compiler. The
  5556.        assembler will generate a raw cross-reference file with a -C
  5557.        option  (Z80  or  8086  assemblers)  or  by using an OPT CRE
  5558.        directive (6800 series assemblers) or  a  REF  control  line
  5559.        (8096 assembler)..  The general form of the CREF command is:
  5560.  
  5561.             CREF options files
  5562.  
  5563.        where _o_p_t_i_o_n_s is zero or more options as described below and
  5564.        _f_i_l_e_s  is one or more raw cross-reference files.  CREF takes
  5565.        the following options:
  5566.  
  5567.        -O_o_u_t_f_i_l_e
  5568.             Allows  specification  of  the  output  file  name.  By
  5569.             default  the  listing  will  be written to the standard
  5570.             output and may  be  redirected  in  the  usual  manner.
  5571.             Alternatively  using  the -O option an output file name
  5572.             may be specified, e.g. -O_x_x_x._l_s_t.
  5573.  
  5574.        -P_w_i_d_t_h
  5575.             This option allows the specification of  the  width  to
  5576.             which  the  listing is to be formatted, e.g. -P_1_3_2 will
  5577.             format the  listing  for  a  132  column  printer.  The
  5578.             default is 80 columns.
  5579.  
  5580.        -L_l_e_n_g_t_h
  5581.             Specify the length of the paper on which the listing is
  5582.             to  be  produced, e.g.  if the listing is to be printed
  5583.             on 55 line paper you  would  use  a  -L_5_5  option.  The
  5584.             default is 66 lines.
  5585.  
  5586.        -X_p_r_e_f_i_x
  5587.             The -X option allows the exclusion of symbols from  the
  5588.             listing, based on a prefix given as argument to -X. For
  5589.             example if it was desired to exclude all symbols start-
  5590.             ing  with  the  character  sequence _x_y_z then the option
  5591.             -X_x_y_z would be used. If a digit appears in the  charac-
  5592.             ter sequence then this will match any digit in the sym-
  5593.             bol, e.g. -XX0 would exclude any symbols starting  with
  5594.             the letter _X followed by a digit.
  5595.  
  5596.        -F   -F will exclude from the listing  any  references  from
  5597.             files  with  a  full  path name. A full path name means
  5598.             either: a file name starting  with  a  slash  ('/')  or
  5599.             backslash  ('\')  or  a  file name starting with a CP/M
  5600.             user number/drive letter prefix,  e.g.  0:A:.  This  is
  5601.             intended to force omission from the listing of any sym-
  5602.             bol references derived from standard header files, e.g.
  5603.             using -F would omit any references from the header file
  5604.             STDIO.H.
  5605.  
  5606.  
  5607.  
  5608.  
  5609.  
  5610.  
  5611.  
  5612.    Page 84                              HI-TECH C USER'S MANUAL
  5613.  
  5614.    -H_s_t_r_i_n_g
  5615.         The -H option takes a string as an argument which  will
  5616.         be used as a header in the listing. The default heading
  5617.         is the name of the first raw cross-ref information file
  5618.         specified.
  5619.  
  5620.    -S_s_t_o_p_l_i_s_t
  5621.         The -S option should have as its argument the name of a
  5622.         file  containing  a list of symbols not to be listed in
  5623.         the cross-reference. Multiple stoplists may be supplied
  5624.         with multiple -S options.
  5625.  
  5626.         Cref will accept wild card filenames and  I/O  redirec-
  5627.    tion.  Long  command  lines may be supplied by invoking CREF
  5628.    with no arguments and typing the command line in response to
  5629.    the _c_r_e_f> prompt. A backslash at the end of the line will be
  5630.    interpreted to mean that more command lines follow.
  5631.  
  5632.  
  5633.  
  5634.  
  5635.  
  5636.  
  5637.  
  5638.  
  5639.  
  5640.  
  5641.  
  5642.  
  5643.  
  5644.  
  5645.  
  5646.  
  5647.  
  5648.  
  5649.  
  5650.  
  5651.  
  5652.  
  5653.  
  5654.  
  5655.  
  5656.  
  5657.  
  5658.  
  5659.  
  5660.  
  5661.  
  5662.  
  5663.  
  5664.  
  5665.  
  5666.  
  5667.  
  5668.  
  5669.  
  5670.  
  5671.  
  5672.  
  5673.  
  5674.  
  5675.  
  5676.  
  5677.  
  5678.        HI-TECH C USER'S MANUAL                              Page 85
  5679.  
  5680.                                 APPENDIX 1
  5681.  
  5682.                              Error Messages
  5683.  
  5684.  
  5685.  
  5686.             Error Messages produced  by  the  compiler  are  listed
  5687.        below.  Each  message is followed by the name of the program
  5688.        which produces it, and  some  further  description  of  what
  5689.        causes the message or what to do about it.
  5690.  
  5691.  
  5692.  
  5693.        '.' expected after '..'      P1
  5694.             The ellipsis symbol must have three dots
  5695.  
  5696.        actuals too long      CPP
  5697.             Reduce length of macro arguments
  5698.  
  5699.        argument list conflicts with prototype      P1
  5700.             The argument list in a function definition  must  agree
  5701.             with a prototype if one exists
  5702.  
  5703.        argument redeclared      P1
  5704.             This argument has been declared twice
  5705.  
  5706.        arithmetic overflow in constant expression      CGEN
  5707.             Evaluation of  this  constant  expression  produced  an
  5708.             arithmetic  overflow.  This  may or may not represent a
  5709.             true error.
  5710.  
  5711.        array index out of bounds      P1
  5712.             An array index expression evaluates to a constant which
  5713.             is  less  than  zero  or  greater  than or equal to the
  5714.             dimension of the array
  5715.  
  5716.        Assertion      CGEN
  5717.             Internal error - contact HI-TECH
  5718.  
  5719.        attempt to modify const object      P1
  5720.             An attempt has been made  to  assign  to  or  otherwise
  5721.             modify an object designated as 'const'
  5722.  
  5723.        bad bitfield type      P1
  5724.             Bitfields must be of type 'int'
  5725.  
  5726.        Bad conval      CGEN
  5727.             Internal error - contact HI-TECH
  5728.  
  5729.        Bad dimensions      CGEN
  5730.             An array has bad dimensions - probably zero
  5731.  
  5732.        Bad element count expr      CGEN
  5733.             Internal error - contact HI-TECH
  5734.  
  5735.        bad formal      CPP
  5736.             Check macro defintion syntax
  5737.  
  5738.  
  5739.  
  5740.  
  5741.  
  5742.  
  5743.  
  5744.    Page 86                              HI-TECH C USER'S MANUAL
  5745.  
  5746.    bad include syntax      CPP
  5747.         Use only "" and <> for include files
  5748.  
  5749.    Bad int. code      CGEN
  5750.         The intermediate code file has been corrupted - can  be
  5751.         caused by running out of disk space
  5752.  
  5753.    Bad -M option      CGEN
  5754.         A -M option passed to the code generator is unknown
  5755.  
  5756.    Bad mod '+' for how = c      CGEN
  5757.         Internal error - contact HI-TECH
  5758.  
  5759.    bad object code format      LINK
  5760.         This file is either corrupted or  not  a  valid  object
  5761.         file
  5762.  
  5763.    Bad op d to swaplog      CGEN
  5764.         Internal error - contact HI-TECH
  5765.  
  5766.    Bad op n to revlog      CGEN
  5767.         Internal error - contact HI-TECH
  5768.  
  5769.    bad origin format in spec      LINK
  5770.         An address in a -p option is invalid
  5771.  
  5772.    bad '-p' format      LINK
  5773.         The -p option provided is invalid
  5774.  
  5775.    Bad pragma c      CGEN
  5776.         The code generator has been passed a pragma it does not
  5777.         know about
  5778.  
  5779.    Bad putwsize      CGEN
  5780.         Internal error - contact HI-TECH
  5781.  
  5782.    bad storage class      P1, CGEN
  5783.         The speficied storage class is illegal
  5784.  
  5785.    Bad U usage      CGEN
  5786.         Internal error - contact HI-TECH
  5787.  
  5788.    Bit field too large (n bits)      CGEN
  5789.         A bit field may not be larger than an int
  5790.  
  5791.    Cannot get memory      LINK
  5792.         The linker has run out of dynamic memory
  5793.  
  5794.    Can't be both far and near      P1
  5795.         The 'far' and 'near' keywords cannot appear in the same
  5796.         type specifier
  5797.  
  5798.    can't be long      P1
  5799.         Chars and shorts cannot be long
  5800.  
  5801.    can't be register      P1
  5802.         An extern or static variable may not be register
  5803.  
  5804.  
  5805.  
  5806.  
  5807.  
  5808.  
  5809.  
  5810.        HI-TECH C USER'S MANUAL                              Page 87
  5811.  
  5812.        can't be short      P1
  5813.             Float and char cannot be short
  5814.  
  5815.        can't be unsigned      P1
  5816.             Float cannot be unsigned
  5817.  
  5818.        can't call an interrupt function      P1
  5819.             A function qualified 'interrupt' can only be called  by
  5820.             hardware, not by an ordinary function call
  5821.  
  5822.        Can't create filename      CGEN
  5823.             The file specified could not be created
  5824.  
  5825.        Can't create xref file      P1
  5826.             The cross reference file specified could not be created
  5827.  
  5828.        Can't create      CPP
  5829.             Output file could not be created
  5830.  
  5831.        Can't create      LINK
  5832.             The linker cannot create a file
  5833.  
  5834.        Can't find include file      CPP
  5835.             Check and correct the include file name  -  spaces  are
  5836.             not allowed in file names
  5837.  
  5838.        Can't find register for bits      CGEN
  5839.             Internal error - contact HI-TECH
  5840.  
  5841.        Can't generate code for this expression      CGEN
  5842.             The code generator is unable to generate code for  this
  5843.             expression - simplifying the expression (e.g. computing
  5844.             values into temporary variables) will  usually  correct
  5845.             it, otherwise contact HI-TECH
  5846.  
  5847.        can't have array of functions      P1
  5848.             You cannot have an array of functions - you can have an
  5849.             array of pointers to functions
  5850.  
  5851.        Can't have 'port' variable      CGEN
  5852.             You cannot declare a variable to be qualified 'port'  -
  5853.             you  can  only use port to qualify pointers or typecast
  5854.             constant values
  5855.  
  5856.        can't have storage class      P1
  5857.             A storage class may not appear in a prototype argument
  5858.  
  5859.        can't initialise auto aggregates      P1
  5860.             You cannot initialise a structure  or  array  inside  a
  5861.             function unless it is static
  5862.  
  5863.        can't initialize arg      P1
  5864.             An argument cannot have an initializer
  5865.  
  5866.        can't mix proto and non-proto args      P1
  5867.             You cannot mix prototype  and  non-prototype  arguments
  5868.             even in a function definition
  5869.  
  5870.  
  5871.  
  5872.  
  5873.  
  5874.  
  5875.  
  5876.    Page 88                              HI-TECH C USER'S MANUAL
  5877.  
  5878.    Can't open filename      CGEN
  5879.         The file specified could not be opened for reading
  5880.  
  5881.    Can't open      LINK
  5882.         The linker cannot open a file
  5883.  
  5884.    Can't seek      LINK
  5885.         The linker could not seek in file
  5886.  
  5887.    can't take address of register variable      P1
  5888.         You can't take the address of a variable in a register
  5889.  
  5890.    can't take sizeof func      CGEN
  5891.         You can't take the size of a function. You can take the
  5892.         size of a function call
  5893.  
  5894.    can't take this address      P1
  5895.         The expression does not have an address
  5896.  
  5897.    'case' not in switch      P1
  5898.         A 'case' label is permitted only inside a switch
  5899.  
  5900.    char const too long      P1
  5901.         A character constant may have only one character in it
  5902.  
  5903.    close error (disk space?)      P1
  5904.         Probably out of disk space
  5905.  
  5906.    common symbol psect conflict      LINK
  5907.         A common symbol is defined to be in more than one psect
  5908.  
  5909.    constant conditional branch      CGEN
  5910.         You have a program structure testing a constant expres-
  5911.         sion, e.g. while(1). You should substitute for this the
  5912.         more efficient for(;;)
  5913.  
  5914.    constant expression required      P1
  5915.         A constant expression is  required  in  e.g.  an  array
  5916.         dimension
  5917.  
  5918.    constant operand to || or &&      CGEN
  5919.         A logical operator has a  constant  operand  which  has
  5920.         been optimized out
  5921.  
  5922.    declarator too complex      P1
  5923.         This declaration is too complex  for  the  compiler  to
  5924.         handle
  5925.  
  5926.    default case redefined      P1
  5927.         Only one default case is permitted in a switch
  5928.  
  5929.    'default' not in switch      P1
  5930.         A 'default' label is permitted only inside a switch
  5931.  
  5932.    digit out of range      P1
  5933.         An octal constant may not contain 7 or 8, and a decimal
  5934.         constant may not contain A-F
  5935.  
  5936.  
  5937.  
  5938.  
  5939.  
  5940.  
  5941.  
  5942.        HI-TECH C USER'S MANUAL                              Page 89
  5943.  
  5944.        dimension required      P1
  5945.             A dimension is required for all except the most  signi-
  5946.             ficant in an array declaration
  5947.  
  5948.        Division by zero      CGEN
  5949.             Attempt to divide by zero in this expression
  5950.  
  5951.        Duplicate case label n      CGEN
  5952.             There are two case labels in this switch that have  the
  5953.             same value
  5954.  
  5955.        Duplicate -d flag      LINK
  5956.             Only one -d flag is allowed to the linker
  5957.  
  5958.        duplicate label      P1
  5959.             This label is defined twice
  5960.  
  5961.        Duplicate -m flag      LINK
  5962.             Only one -m flag is allowed to the linker
  5963.  
  5964.        duplicate qualifier      P1
  5965.             The same qualifier appears more than once in this  type
  5966.             specifier
  5967.  
  5968.        entry point multiply defined      LINK
  5969.             A program can only have one entry point (start address)
  5970.  
  5971.        EOF in #asm      P1
  5972.             End of file was encounterd  after  #asm  and  before  a
  5973.             #endasm was seen
  5974.  
  5975.        Error closing output file      CGEN,CPP
  5976.             Probably means you have run out of disk space
  5977.  
  5978.        excessive -I file ignored      CPP
  5979.             Use fewer -I options
  5980.  
  5981.        expand - bad how      CGEN
  5982.             Internal error - contact HI-TECH
  5983.  
  5984.        expand - bad which      CGEN
  5985.             Internal error - contact HI-TECH
  5986.  
  5987.        exponent expected      P1
  5988.             An exponent is expected after  the  'e'  or  'E'  in  a
  5989.             floating point constant. The exponent must contain only
  5990.             +, - and digits 0-9
  5991.  
  5992.        Expression error      CGEN
  5993.             Internal error - contact HI-TECH
  5994.  
  5995.        expression generates no code      CGEN
  5996.             This expression has no side effects and thus  generates
  5997.             no code. It has been optimized out
  5998.  
  5999.        expression syntax      P1
  6000.             The expression is badly formed
  6001.  
  6002.  
  6003.  
  6004.  
  6005.  
  6006.  
  6007.  
  6008.    Page 90                              HI-TECH C USER'S MANUAL
  6009.  
  6010.    expression too complex      P1
  6011.         The expression has too many nested parantheses or other
  6012.         nested constructs
  6013.  
  6014.    Fixup overflow referencing      LINK
  6015.         The linker has relocated a reference to a psect or sym-
  6016.         bol  and  the  relocated address is too big to fit into
  6017.         the space, e.g. a relocated one  byte  address  exceeds
  6018.         256 or a relocated 16 bit address exceeds 65536
  6019.  
  6020.    float param coerced to double      P1
  6021.         This float parameter has been converted to double  -  a
  6022.         prototype will override this coercion
  6023.  
  6024.    function() declared implicit int      P1
  6025.         This function  has  been  called  without  an  explicit
  6026.         declaration. It is wise to explicitly declare all func-
  6027.         tions, preferably with a  prototype.  This  will  avoid
  6028.         many potential errors where your program comprises more
  6029.         than one source file
  6030.  
  6031.    function does not take arguments      P1
  6032.         The prototype for this function indicates it  takes  no
  6033.         arguments
  6034.  
  6035.    function or function pointer required      P1
  6036.         A  function  identifier  or  pointer  to  function   is
  6037.         required for a function call.
  6038.  
  6039.    functions can't return arrays      P1
  6040.         A function cannot return an array -  it  can  return  a
  6041.         pointer
  6042.  
  6043.    functions can't return functions      P1
  6044.         A function cannot return a function - it can  return  a
  6045.         pointer to function
  6046.  
  6047.    hex digit expected      P1
  6048.         A hex digit is expected after '0x'
  6049.  
  6050.    identifier is a structure tag      P1
  6051.         A structure tag  has  been  used  in  a  context  where
  6052.         another  kind  of  tag  is expected, e.g. saying struct
  6053.         fred where fred has previously been declared  as  union
  6054.         fred.
  6055.  
  6056.    identifier is a union tag      P1
  6057.         Similar to the above error
  6058.  
  6059.    identifier is an enum tag      P1
  6060.         Similar to the above error
  6061.  
  6062.    identifier: large offset      CGEN
  6063.         Z80 only: This identifier has a large offset  from  the
  6064.         stack  frame and thus access to it is inefficient. In a
  6065.         function any arrays should be declared after any simple
  6066.         variables
  6067.  
  6068.  
  6069.  
  6070.  
  6071.  
  6072.  
  6073.  
  6074.        HI-TECH C USER'S MANUAL                              Page 91
  6075.  
  6076.        identifier redeclared      P1
  6077.             The  identifier  has  been  redeclared  with  different
  6078.             attributes
  6079.  
  6080.        identifier redefined      P1
  6081.             An identifier has been defined twice
  6082.  
  6083.        If-less else      CPP
  6084.             Check #if usage
  6085.  
  6086.        If-less endif      CPP
  6087.             Check #if usage
  6088.  
  6089.        illegal '#' directive      P1
  6090.             A # directive passed through to the first pass is  unk-
  6091.             nown.  If  this occurs with a #include it may be caused
  6092.             by a previous include file not  having  a  <CR><LF>  or
  6093.             newline on the last line.
  6094.  
  6095.        Illegal character in preprocessor if      CPP
  6096.             Check for strange character
  6097.  
  6098.        illegal character      P1
  6099.             A character unknown to the compiler  has  been  encoun-
  6100.             tered.  The value given is the octal value of the char-
  6101.             acter
  6102.  
  6103.        illegal conversion between pointer types      P1
  6104.             The expression causes one pointer type to be  converted
  6105.             to another incompatible type
  6106.  
  6107.        illegal conversion of integer to pointer      P1
  6108.             An integer is used where a pointer is expected
  6109.  
  6110.        illegal conversion of pointer to integer      P1
  6111.             A pointer is used where an integer is expected
  6112.  
  6113.        illegal conversion      P1
  6114.             The type conversion here is illegal
  6115.  
  6116.        Illegal flag      LINK
  6117.             This option is illegal
  6118.  
  6119.        illegal function qualifier(s)      P1
  6120.             A function cannot have 'const' qualification
  6121.  
  6122.        illegal initialisation      P1
  6123.             The initialisation of this variable is illegal
  6124.  
  6125.        Illegal number      CPP
  6126.             Check number syntax
  6127.  
  6128.        illegal type for array dimension      P1
  6129.             An array dimension must be an integral quantity
  6130.  
  6131.        illegal type for index expression      P1
  6132.             An array index must be a simple integral expression
  6133.  
  6134.  
  6135.  
  6136.  
  6137.  
  6138.  
  6139.  
  6140.    Page 92                              HI-TECH C USER'S MANUAL
  6141.  
  6142.    illegal type for switch expression      P1
  6143.         The expression in a 'switch' must be integral
  6144.  
  6145.    illegal use of void expression      P1
  6146.         Void expressions may not be used in any way
  6147.  
  6148.    implicit conversion of float to integer      P1
  6149.         A floating point value has been converted to integer  -
  6150.         truncation may occur
  6151.  
  6152.    implicit return at end of non-void function      P1
  6153.         A function with a non-void type has returned without  a
  6154.         return statement
  6155.  
  6156.    implict signed to unsigned conversion      P1
  6157.         Unwanted sign extension may occur here. Add an explicit
  6158.         typecast to force exactly the conversion you want
  6159.  
  6160.    inappropriate break/continue      P1
  6161.  
  6162.    inappropriate 'else'      P1
  6163.         An 'else' has appeared without a matching 'if'
  6164.  
  6165.    inconsistent storage class      P1
  6166.         Only one storage class may be specified in  a  declara-
  6167.         tion
  6168.  
  6169.    inconsistent type      P1
  6170.         Only one basic type may be specified in a declaration
  6171.  
  6172.    initialisation illegal in arg list      P1
  6173.         You cannot initialise a function parameter
  6174.  
  6175.    initialisation syntax      P1
  6176.         The syntax of this initialisation is illegal
  6177.  
  6178.    initializer in 'extern' declaration      P1
  6179.         A declaration with the 'extern' keyword has an initial-
  6180.         izer;  this  is not permitted as the extern declaration
  6181.         reserves no storage
  6182.  
  6183.    integer constant expected      P1
  6184.         An integer constant was expected here
  6185.  
  6186.    integer expression required      P1
  6187.         An integral expression is required here
  6188.  
  6189.    integral type required      P1
  6190.         An integral type is required here
  6191.  
  6192.    large offset      CGEN
  6193.         Z80 only: This identifier has a large offset  from  the
  6194.         stack  frame and thus access to it is inefficient. In a
  6195.         function any arrays should be declared after any simple
  6196.         variables
  6197.  
  6198.  
  6199.  
  6200.  
  6201.  
  6202.  
  6203.  
  6204.  
  6205.  
  6206.        HI-TECH C USER'S MANUAL                              Page 93
  6207.  
  6208.        Line too long      P1
  6209.             The source line  is  too  long,  or  does  not  have  a
  6210.             <CR><LF> or newline at the end
  6211.  
  6212.        local  psect  conflicts  with  global  psect  of  same  name
  6213.             LINK
  6214.             A local psect cannot have the same  name  as  a  global
  6215.             psect
  6216.  
  6217.        logical type required      P1
  6218.             A logical type (i.e. an integral type) is  required  as
  6219.             the subject of a conditional expression
  6220.  
  6221.        lvalue required      P1
  6222.             An lvalue, i.e. something which can be assigned to,  is
  6223.             required after an '&' or on the left hand of an assign-
  6224.             ment
  6225.  
  6226.        macro recursion      CPP
  6227.             A preprocessor macro has attempted  to  expand  itself.
  6228.             This would create infinite recursion
  6229.  
  6230.        member is not a member of the struct/union      P1
  6231.             This member is not in the structure or union with which
  6232.             it is used
  6233.  
  6234.        members cannot be functions      P1
  6235.             A member cannot be a function - it can be a pointer  to
  6236.             function
  6237.  
  6238.        Missing arg to -u      LINK
  6239.             -u requires an argument
  6240.  
  6241.        Missing arg to -w      LINK
  6242.             -w requires an argument
  6243.  
  6244.        missing )      CPP
  6245.             Put correct ) in expression
  6246.  
  6247.        Missing number after % in -p option      LINK
  6248.             After % in a -p option there must be a number
  6249.  
  6250.        Missing number after pragma 'pack'      P1
  6251.             The correct syntax is #pragma pack(n) where n is  1,  2
  6252.             or 4.
  6253.  
  6254.        module has code below file base      LINK
  6255.             A -C option was specified  but  the  program  has  code
  6256.             below  the  address specified as the base of the binary
  6257.             file
  6258.  
  6259.        multiply defined symbol      LINK
  6260.             A symbol is defined more than once
  6261.  
  6262.        name is a union, struct or enum      P1
  6263.             A union, struct or enum tag has been re-used in a  dif-
  6264.             ferent context
  6265.  
  6266.  
  6267.  
  6268.  
  6269.  
  6270.  
  6271.  
  6272.    Page 94                              HI-TECH C USER'S MANUAL
  6273.  
  6274.    No case labels      CGEN
  6275.         This switch has no case labels
  6276.  
  6277.    no identifier in declaration      P1
  6278.         This declaration should have an identifier in it
  6279.  
  6280.    No room      CGEN
  6281.         The code generator has run out of dynamic  memory.  You
  6282.         will  need  to  reduce the number of symbols and/or the
  6283.         complexity of expressions
  6284.  
  6285.    No source file      CPP
  6286.         Source file could not be found - check spelling, direc-
  6287.         tory paths etc.
  6288.  
  6289.    no space      CPP
  6290.         Reduce number/size of macro definitions
  6291.  
  6292.    no start record: entry point defaults to zero      LINK
  6293.         No start address has been specified  for  the  program;
  6294.         the linker has set the start address to 0
  6295.  
  6296.    Non-constant case label      CGEN
  6297.         This case label does not evaluate to an  integral  con-
  6298.         stant
  6299.  
  6300.    non-void function returns no value      P1
  6301.         A function which should return a value has  a  'return'
  6302.         statement with no value
  6303.  
  6304.    not a variable identifier      P1
  6305.         The identifier is not a variable - it  may  be  e.g.  a
  6306.         label or structure tag
  6307.  
  6308.    not an argument      P1
  6309.         This identifier is not in the argument  list  for  this
  6310.         function
  6311.  
  6312.    only functions may be qualified interrupt      P1
  6313.         The type qualifier 'interrupt' may be applied  only  to
  6314.         functions, not variables.
  6315.  
  6316.    only functions may be void      P1
  6317.         Only functions, not variables, may be declared void
  6318.  
  6319.    only lvalues may be assigned to or modified      P1
  6320.         You have attempted to modify an expression  which  does
  6321.         not identify a storage location
  6322.  
  6323.    only register storage class allowed      P1
  6324.         A parameter may only be auto or register
  6325.  
  6326.    operands of operator not same pointer type      P1
  6327.         The operands to the named operator  in  the  expression
  6328.         are both pointers but are not the same pointer type
  6329.  
  6330.  
  6331.  
  6332.  
  6333.  
  6334.  
  6335.  
  6336.  
  6337.  
  6338.        HI-TECH C USER'S MANUAL                              Page 95
  6339.  
  6340.        operands of operator not same type      P1
  6341.             The operands to the named operator  in  the  expression
  6342.             are incompatible types
  6343.  
  6344.        pointer required      P1
  6345.             A pointer is required after a '*' (indirection)  opera-
  6346.             tor
  6347.  
  6348.        popreg - bad reg      CGEN
  6349.             Internal error - contact HI-TECH
  6350.  
  6351.        portion of expression has no effect      CGEN
  6352.             A portion of this expression has no effect on its value
  6353.             and no side effects
  6354.  
  6355.        probable missing '}' in previous block      P1
  6356.             A declaration has been encountered where an  expression
  6357.             was expected. The likely cause of this is that you have
  6358.             omitted a closing '}' in the function above this point.
  6359.  
  6360.        psect cannot be in classes a and b      LINK
  6361.             A psect can only be in one class
  6362.  
  6363.        psect exceeds max size      LINK
  6364.             This psect is larger than a specified maximum size
  6365.  
  6366.        psect is absolute      LINK
  6367.             This psect is absolute and cannot have a  link  address
  6368.             specified in a -p option
  6369.  
  6370.        Psect not loaded on 0xhexnum boundary       LINK
  6371.             This psect must be loaded on a specific boundary
  6372.  
  6373.        Psect not relocated on 0xhexnum boundary      LINK
  6374.             This psect must be linked on a specific boundary
  6375.  
  6376.        psect origin multiply defined      LINK
  6377.             This psect has its link address defined more than once
  6378.  
  6379.        pushreg - bad reg      CGEN
  6380.             Internal error - contact HI-TECH
  6381.  
  6382.        redundant & applied to array      P1
  6383.             An array type has an '&' operator applied to it. It has
  6384.             been ignored since use of an array implicitly gives its
  6385.             address
  6386.  
  6387.        regused - bad arg to G      CGEN
  6388.             Internal error - contact HI-TECH
  6389.  
  6390.        signatures do not matchLINK
  6391.             An extern function has been declared with an  incorrect
  6392.             prototype.  For example if an argument is declared as a
  6393.             long in an extern declaration, but is really an int,  a
  6394.             signature mismatch will occur.
  6395.  
  6396.  
  6397.  
  6398.  
  6399.  
  6400.  
  6401.  
  6402.  
  6403.  
  6404.    Page 96                              HI-TECH C USER'S MANUAL
  6405.  
  6406.    signed bitfields not supported      P1
  6407.         Only unsigned bitfields are supported
  6408.  
  6409.    simple type required      P1
  6410.         An array or structure type cannot be used here
  6411.  
  6412.    Sizeof yields 0      CGEN
  6413.         The size of an object has evaluated to zero in  a  con-
  6414.         text where this is illegal, e.g. incrementing a pointer
  6415.         to a zero length object.
  6416.  
  6417.    storage class illegal      P1
  6418.         A storage class may not be specified here
  6419.  
  6420.    struct/union member expected      P1
  6421.         A structure or union member is required after a  '.  or
  6422.         '->'
  6423.  
  6424.    struct/union redefined      P1
  6425.         This structure or union has been defined twice
  6426.  
  6427.    struct/union required      P1
  6428.         A structure or union identifier is  required  before  a
  6429.         '.'
  6430.  
  6431.    Switch on long!      CGEN
  6432.         Switching on a long expression is not supported
  6433.  
  6434.    symbol cannot be global      LINK
  6435.         Stack, filename or line number symbols cannot be global
  6436.  
  6437.    Syntax error in checksum list      LINK
  6438.         The checksum list provided is invalid
  6439.  
  6440.    token too long      CPP
  6441.         Shorten token (e.g. identifier)
  6442.  
  6443.    too few arguments      P1
  6444.         The protype for this function lists more arguments than
  6445.         have been supplied
  6446.  
  6447.    too many arguments      P1
  6448.         More arguments have been supplied than  listed  in  the
  6449.         prototype for this function
  6450.  
  6451.    Too many cases in switch      CGEN,P1
  6452.         There are too many cases in this switch
  6453.  
  6454.    too many -D options      CPP
  6455.         Use fewer -D options
  6456.  
  6457.    too many defines      CPP
  6458.         Reduce number of macro definitions
  6459.  
  6460.    Too many errors      CGEN
  6461.         CGEN has given up because there were too many errors.
  6462.  
  6463.  
  6464.  
  6465.  
  6466.  
  6467.  
  6468.  
  6469.  
  6470.        HI-TECH C USER'S MANUAL                              Page 97
  6471.  
  6472.        too many formals      CPP
  6473.             Reduce number of parameters to this macro definition
  6474.  
  6475.        Too many initializers      CGEN
  6476.             There are too many initializers for this object
  6477.  
  6478.        Too many psects      LINK
  6479.             There are too many psects for the symbol table
  6480.  
  6481.        Too many symbols      LINK
  6482.             There are too many symbols for the linker symbol table
  6483.  
  6484.        too many -U options      CPP
  6485.             Use fewer -U options
  6486.  
  6487.        too much defining      CPP
  6488.             Reduce number/size of macros
  6489.  
  6490.        too much indirection      P1
  6491.             Too many '*'s in this declaration
  6492.  
  6493.        too much pushback      CPP
  6494.             Simplify macro usage
  6495.  
  6496.        type conflict      P1
  6497.             There is a conflict of types in this  expression,  e.g.
  6498.             attempting to assign a structure to a simple type
  6499.  
  6500.        type specifier reqd. for proto arg      P1
  6501.             A prototype argument must have a basic type
  6502.  
  6503.        undefined control      CPP
  6504.             Check use of #
  6505.  
  6506.        undefined enum tag      P1
  6507.             This enumerated type tag has not been defined
  6508.  
  6509.        undefined identifier      P1
  6510.             This identifier has not been defined before use
  6511.  
  6512.        undefined struct/union      P1
  6513.             The structure or union used has not been defined
  6514.  
  6515.        undefined symbol      LINK
  6516.             A list of undefined symbols follows.  If  some  of  the
  6517.             symbols should be in a library which was linked, it may
  6518.             be caused by a library ordering problem. In  this  case
  6519.             rebuild  the  library  with  the  correct  ordering  or
  6520.             specify the library more than once in the link command
  6521.  
  6522.        unexpected EOF      P1
  6523.             End of file was encountered in the middle of a  C  con-
  6524.             struct.  This is commonly caused by omission of a clos-
  6525.             ing '}' earlier in the program.
  6526.  
  6527.        Unknown predicate      CGEN
  6528.             Internal error - contact HI-TECH
  6529.  
  6530.  
  6531.  
  6532.  
  6533.  
  6534.  
  6535.  
  6536.    Page 98                              HI-TECH C USER'S MANUAL
  6537.  
  6538.    unknown psect      LINK
  6539.         The psect specifed in a -p option is not present in the
  6540.         program.  Check the spelling and check the case - upper
  6541.         case does not match lower case
  6542.  
  6543.    unreachable code      P1
  6544.         This section of code can never be executed as there  is
  6545.         no possible path to reach it
  6546.  
  6547.    Unreasonable include nesting      CPP
  6548.         Reduce number of include files
  6549.  
  6550.    Unreasonable matching depth      CGEN
  6551.         Internal error - contact HI-TECH
  6552.  
  6553.    unterminated macro call      CPP
  6554.         Probably missing )
  6555.  
  6556.    void function cannot return value      P1
  6557.         A function declared void cannot return a value
  6558.  
  6559.    Write error (out of disk space?)      LINK
  6560.         Probably means the disk is full
  6561.  
  6562.  
  6563.  
  6564.  
  6565.  
  6566.  
  6567.  
  6568.  
  6569.  
  6570.  
  6571.  
  6572.  
  6573.  
  6574.  
  6575.  
  6576.  
  6577.  
  6578.  
  6579.  
  6580.  
  6581.  
  6582.  
  6583.  
  6584.  
  6585.  
  6586.  
  6587.  
  6588.  
  6589.  
  6590.  
  6591.  
  6592.  
  6593.  
  6594.  
  6595.  
  6596.  
  6597.  
  6598.  
  6599.  
  6600.  
  6601.  
  6602.        HI-TECH C USER'S MANUAL                              Page 99
  6603.  
  6604.                                   APPENDIX 2
  6605.  
  6606.                           Standard Library Functions
  6607.  
  6608.  
  6609.  
  6610.             The functions accessible to user programs in the  stan-
  6611.        dard  library  libc.lib are listed below, by category with a
  6612.        short comment, then alphabetically with  a  longer  descrip-
  6613.        tion.  In  the  detailed  description  of each function, the
  6614.        SYNOPSIS section  describes  the  function  in  roughly  the
  6615.        manner in which the function would be declared in the source
  6616.        file defining it.  Where an  include  file  is  shown,  this
  6617.        implies  that  that  include  file  must  be included in any
  6618.        source file using that function.
  6619.  
  6620.             Where an include file is not provided, it will normally
  6621.        be necessary for an extern declaration of the function to be
  6622.        included in any source module using it, to ensure  that  the
  6623.        type  of the function is correct.  For example, if the func-
  6624.        tion _l_s_e_e_k() was to be used, a declaration of the form
  6625.  
  6626.             extern long  lseek();
  6627.  
  6628.        should be in either the source file  itself  or  an  include
  6629.        file included in the source file. This ensures that the com-
  6630.        piler knows that _l_s_e_e_k() returns a long value  and  not  the
  6631.        default int.
  6632.  
  6633.             Where reference is made to STDIO, this means the  group
  6634.        of functions under the heading STANDARD I/O below. These all
  6635.        have one thing in common; they  operate  on  pointers  to  a
  6636.        defined  data  type  called  FILE.  Such  a pointer is often
  6637.        referred to as a _s_t_r_e_a_m pointer. The concept of a stream  is
  6638.        central  to these routines. Essentially a stream is a source
  6639.        or sink of data bytes. To the operating system  and  library
  6640.        routines  this  stream is featureless, i.e. no record struc-
  6641.        ture is implied or assumed. Some routines do however  recog-
  6642.        nize end of line characters.
  6643.  
  6644.  
  6645.  
  6646.                                    STANDARD I/O
  6647.  
  6648.        fopen(name, mode)                  Open file for I/O
  6649.        freopen(name, mode, stream)        Re-open existing stream
  6650.        fdopen(fd, mode)                   Associate a  stream  with  a  file
  6651.                                           descriptor
  6652.        fclose(stream)                     Close open file
  6653.        fflush(stream)                     Flush buffered data
  6654.        getc(stream)                       Read byte from stream
  6655.        fgetc(stream)                      Same as getc
  6656.        ungetc(c, stream)                  Push char back onto stream
  6657.        putc(c, stream)                    Write byte to stream
  6658.        fputc(c, stream)                   Same as putc()
  6659.        getchar()                          Read byte from standard input
  6660.        putchar(c)                         Write byte to standard output
  6661.        getw(stream)                       Read word from stream
  6662.  
  6663.  
  6664.  
  6665.  
  6666.  
  6667.  
  6668.    Page 100                             HI-TECH C USER'S MANUAL
  6669.  
  6670.    putw(w, stream)                    Write word to stream
  6671.    gets(s)                            Read line from standard input
  6672.    fgets(s, n, stream)                Read string from stream
  6673.    puts(s)                            Write string to standard output
  6674.    fputs(s, stream)                   Write string to stream
  6675.    fread(buf, size, cnt, stream)      Binary read from stream
  6676.    fwrite(buf, size, cnt, stream)     Binary write to stream
  6677.    fseek(stream, offs, wh)            Random access positioning
  6678.    ftell(stream)                      Current file read/write position
  6679.    rewind(stream)                     Reposition file pointer to start
  6680.    setvbuf(stream, buf, mode, size)   Enable/disable buffering of stream
  6681.    fprintf(stream, fmt, args)         Formatted output on stream
  6682.    printf(fmt, args)                  Formatted standard output
  6683.    sprintf(buf, fmt, args)            Formatted output to a string
  6684.    vfprintf(stream, fmt, va_ptr)      Formatted output on stream
  6685.    vprintf(fmt, va_ptr)               Formatted standard output
  6686.    vsprintf(buf, fmt, va_ptr)         Formatted output to a string
  6687.    fscanf(stream, fmt, args)          Formatted input from stream
  6688.    scanf(fmt, args)                   Formatted standard input
  6689.    sscanf(buf, fmt, va_ptr)           Formatted input from a string
  6690.    vfscanf(stream, fmt, va_ptr)       Formatted input from stream
  6691.    vscanf(fmt, args)                  Formatted standard input
  6692.    vsscanf(buf, fmt, va_ptr)          Formatted input from a string
  6693.    feof(stream)                       True if stream at EOF
  6694.    ferror(stream)                     True if error on stream
  6695.    clrerr(stream)                     Reset error status on stream
  6696.    fileno(stream)                     Return fd from stream
  6697.    remove(name)                       Remove (delete) file
  6698.  
  6699.  
  6700.  
  6701.                            STRING HANDLING
  6702.  
  6703.    atoi(s)              Convert ASCII decimal to integer
  6704.    atol(s)              Convert ASCII decimal to long integer
  6705.    atof(s)              Convert ASCII decimal to float
  6706.    xtoi(s)              Convert ASCII hexadecimal to integer
  6707.    memchr(s, c, n)      Find char in memory block
  6708.    memcmp(s1, s2, n)    Compare n bytes of memory
  6709.    memcpy(s1, s2, n)    Copy n bytes from s2 to s1
  6710.    memmove(s1, s2, n)   Copy n bytes from s2 to s1
  6711.    memset(s, c, n)      Set n bytes at s to c
  6712.    strcat(s1, s2)       Append string 2 to string 1
  6713.    strncat(s1, s2, n)   Append at most n chars to string 1
  6714.    strcmp(s1, s2)       Compare strings
  6715.    strncmp(s1, s2, n)   Compare n bytes of strings
  6716.    strcpy(s1, s2)       Copy s2 to s1
  6717.    strncpy(s1, s2, n)   Copy at most n bytes of s2
  6718.    strerror(errnum)     Map errnum to an error message string
  6719.    strlen(s)            Length of string
  6720.    strchr(s, c)         Find char in string
  6721.    strrchr(s, c)        Find rightmost char in string
  6722.    strspn(s1, s2)       Length of s1 composed of chars from s2
  6723.    strcspn(s1, s2)      Length of s2 composed of chars not from  s2
  6724.    strstr(s1, s2)       Locate the first occurence of s2 in s1
  6725.  
  6726.  
  6727.  
  6728.  
  6729.  
  6730.  
  6731.  
  6732.  
  6733.  
  6734.        HI-TECH C USER'S MANUAL                             Page 101
  6735.  
  6736.                               LOW LEVEL I/O
  6737.  
  6738.        open(name, mode)        Open a file
  6739.        close(fd)               Close a file
  6740.        creat(name)             Create a file
  6741.        dup(fd)                 Duplicate file descriptor
  6742.        lseek(fd, offs, wh)     Random access positioning
  6743.        read(fd, buf, cnt)      Read from file
  6744.        rename(name1, name2)    Rename file
  6745.        unlink(name)            Remove file from directory
  6746.        write(fd, buf, cnt)     Write to file
  6747.        isatty(fd)              True if fd refers to tty-like device
  6748.        stat(name, buf)         Get information about a file
  6749.        chmod(name, mode)       Set file attributes
  6750.  
  6751.  
  6752.  
  6753.                             CHARACTER TESTING
  6754.  
  6755.        isalpha(c)           True if c is a letter
  6756.        isupper(c)           Upper case letter
  6757.        islower(c)           Lower case letter
  6758.        isdigit(c)           Digit
  6759.        isalnum(c)           Alphnumeric character
  6760.        isspace(c)           Space, tab, newline, return or formfeed
  6761.        ispunct(c)           Punctuation character
  6762.        isprint(c)           Printable character
  6763.        isgraph(c)           Printable non-space character
  6764.        iscntrl(c)           Control character
  6765.        isascii(c)           Ascii character (0-127)
  6766.  
  6767.  
  6768.  
  6769.                               FLOATING POINT
  6770.  
  6771.        cos(f)                      Cosine function
  6772.        sin(f)                      Sine function
  6773.        tan(f)                      Tangent function
  6774.        acos(f)                     Arc cosine function
  6775.        asin(f)                     Arc sine function
  6776.        atan(f)                     Arc tangent function
  6777.        exp(f)                      Exponential of f
  6778.        log(f)                      Natural log of f
  6779.        log10(f)                    Base 10 log of f
  6780.        pow(x,y)                    X to the y'th power
  6781.        sqrt(f)                     Square root
  6782.        fabs(f)                     Floating absolute value
  6783.        ceil(f)                     Smallest integral value >= f
  6784.        floor(f)                    Largest integral value <= f
  6785.        sinh(f)                     Hyperbolic sine
  6786.        cosh(f)                     Hyperbolic cosine
  6787.        tanh(f)                     Hyperbolic tangent
  6788.        frexp(y, p)                 Split into mantissa and exponent
  6789.        ldexp(y, i)                 Load new exponent
  6790.  
  6791.  
  6792.  
  6793.                                CONSOLE I/O
  6794.  
  6795.  
  6796.  
  6797.  
  6798.  
  6799.  
  6800.    Page 102                             HI-TECH C USER'S MANUAL
  6801.  
  6802.  
  6803.    getch()                       Get single character
  6804.    getche()                      Get single character with echo
  6805.    putch(c)                      Put single character
  6806.    ungetch(c)                    Push character back
  6807.    kbhit()                       Test for key pressed
  6808.    cgets(s)                      Get line from console
  6809.    cputs(s)                      Put string to console
  6810.  
  6811.  
  6812.  
  6813.  
  6814.                      DATE AND TIME FUNCTIONS
  6815.  
  6816.    time(p)                    Get current date/time
  6817.    gmtime(p)                  Get broken down Universal time
  6818.    localtime(p)               Get broken down local time
  6819.    asctime(t)                 Convert broken down time to ascii
  6820.    ctime(p)                   Convert time to ascii
  6821.  
  6822.  
  6823.  
  6824.                                  MISCELLANEOUS
  6825.  
  6826.    execl(name, args)               Execute another program
  6827.    execv(name, argp)               Execute another program
  6828.    spawnl(name, arg, ...)          Execute a subprogram
  6829.    spawnv(name, argp)              Execute a subprogram
  6830.    system(s)                       Execute system command
  6831.    atexit(func)                    Install func to be executed on termination
  6832.    exit(status)                    Terminate execution
  6833.    _exit(status)                   Terminate execution immediately
  6834.    getuid()                        Get user id (CP/M)
  6835.    setuid(uid)                     Set user id (CP/M)
  6836.    chdir(s)                        Change directory (MS-DOS)
  6837.    mkdir(s)                        Create directory (MS-DOS)
  6838.    rmdir(s)                        Remove directory (MS-DOS)
  6839.    getcwd(drive)                   Get current working directory (MS-DOS)
  6840.    signal(sig, func)               Set trap for interrupt condition
  6841.    brk(addr)                       Set memory allocation
  6842.    sbrk(incr)                      Adjust memory allocation
  6843.    malloc(cnt)                     Dynamic memory allocation
  6844.    free(ptr)                       Dynamic memory release
  6845.    realloc(ptr, cnt)               Dynamic memory reallocation
  6846.    calloc(cnt, size)               Dynamic memory allocation zeroed
  6847.    perror(s)                       Print error message
  6848.    qsort(base, nel, width, func)   Quick sort
  6849.    srand(seed)                     Initialize random number generator
  6850.    rand()                          Get next random number
  6851.    setjmp(buf)                     Setup for non-local goto
  6852.    longjmp(buf, val)               Non-local goto
  6853.    _getargs(buf, name)             Wild card expansion and i/o redirection
  6854.    inp(port)                       Read port
  6855.    outp(port, data)                Write data to port
  6856.    bdos(func, val)                 Perform bdos call (CP/M)
  6857.    msdos(func, val, val, ...)      Perform msdos call
  6858.    msdoscx(func, val, val, ...)    Alternate msdos call
  6859.    intdos(ip, op)                  Execute DOS interrupt
  6860.  
  6861.  
  6862.  
  6863.  
  6864.  
  6865.  
  6866.        HI-TECH C USER'S MANUAL                             Page 103
  6867.  
  6868.        intdosx(ip, op, sp)             Execute DOS interrupt
  6869.        segread(sp)                     Get segment register values
  6870.        int86(int, ip, op)              Execute software interrupt
  6871.        int86x(int, ip, op, sp)         Execute software interrupt
  6872.        bios(n, c)                      Call bios entry (CP/M)
  6873.        ei()                            Enable interrupts
  6874.        di()                            Disable interrupts
  6875.        set_vector(vec, func)           Set an interrupt vector
  6876.        assert(e)                       Run time assertion
  6877.        getenv(s)                       Get environment string (MS-DOS)
  6878.  
  6879.  
  6880.  
  6881.  
  6882.  
  6883.                          ACOS, ASIN, ATAN, ATAN2
  6884.        SYNOPSIS
  6885.  
  6886.             #include  <math.h>
  6887.  
  6888.             double    acos(double f)
  6889.             double    asin(double f)
  6890.             double    atan(double f)
  6891.  
  6892.             double    atan2(double x, double y)
  6893.  
  6894.  
  6895.        DESCRIPTION
  6896.             These functions are the converse  of  the  trignometric
  6897.             functions cos, sin and tan. Acos and asin are undefined
  6898.             for arguments whose absolute value is greater than 1.0.
  6899.             The  returned  value  is  in radians, and always in the
  6900.             range -pi/2 to +pi/2, except for _c_o_s(), which returns a
  6901.             value  in  the  range  0  to  pi.   _A_t_a_n_2() returns the
  6902.             inverse tan of x/y but uses the signs of its  arguments
  6903.             to return a value in the range -pi to +pi.
  6904.  
  6905.        SEE ALSO
  6906.  
  6907.             sin, cos, tan
  6908.  
  6909.  
  6910.  
  6911.  
  6912.  
  6913.  
  6914.  
  6915.  
  6916.  
  6917.  
  6918.  
  6919.  
  6920.  
  6921.  
  6922.  
  6923.  
  6924.  
  6925.  
  6926.  
  6927.  
  6928.  
  6929.  
  6930.  
  6931.  
  6932.    Page 104                             HI-TECH C USER'S MANUAL
  6933.  
  6934.                               ATEXIT
  6935.    SYNOPSIS
  6936.  
  6937.         #include  <stdlib.h>
  6938.  
  6939.         int atexit(void (*func)(void));
  6940.  
  6941.  
  6942.    DESCRIPTION
  6943.         The _a_t_e_x_i_t() function registers the function pointed to
  6944.         by  func, to be called without arguments at normal pro-
  6945.         gram termination.  _A_t_e_i_x_t() returns zero if the  regis-
  6946.         tration succeeds, nonzero if it fails.  On program ter-
  6947.         mination, all  functions  registered  by  _a_t_e_x_i_t()  are
  6948.         called, in the reverse order of their registration.
  6949.  
  6950.    SEE ALSO
  6951.  
  6952.         exit
  6953.  
  6954.  
  6955.  
  6956.  
  6957.  
  6958.                              ASCTIME
  6959.    SYNOPSIS
  6960.  
  6961.         #include  <time.h>
  6962.  
  6963.         char *    asctime(time_t t)
  6964.  
  6965.  
  6966.    DESCRIPTION
  6967.         _A_s_c_t_i_m_e() takes the broken down time pointed to by  its
  6968.         argument,  and returns a 26 character string describing
  6969.         the current date and time in the format
  6970.  
  6971.              Sun Sep 16 01:03:52 1973\n\0
  6972.  
  6973.         Note the newline at the end of the string. The width of
  6974.         each field in the string is fixed.
  6975.  
  6976.    SEE ALSO
  6977.  
  6978.         ctime, time, gmtime, localtime
  6979.  
  6980.  
  6981.  
  6982.  
  6983.  
  6984.  
  6985.  
  6986.  
  6987.  
  6988.  
  6989.  
  6990.  
  6991.  
  6992.  
  6993.  
  6994.  
  6995.  
  6996.  
  6997.  
  6998.        HI-TECH C USER'S MANUAL                             Page 105
  6999.  
  7000.                                   ASSERT
  7001.        SYNOPSIS
  7002.  
  7003.             #include  <assert.h>
  7004.  
  7005.             void      assert(int e)
  7006.  
  7007.  
  7008.        DESCRIPTION
  7009.             This macro is used for debugging  purposes;  the  basic
  7010.             method  of  usage  is  to  place  assertions  liberally
  7011.             throughout your code at points where correct  operation
  7012.             of  the code depends upon certain conditions being true
  7013.             initially. An _a_s_s_e_r_t() may be used  to  ensure  at  run
  7014.             time  that that assumption holds. For example, the fol-
  7015.             lowing statement asserts that the pointer  tp  is  non-
  7016.             null:
  7017.  
  7018.                  assert(tp);
  7019.  
  7020.             If at run time the expression evaluates to  false,  the
  7021.             program  will  abort  with  a  message  identifying the
  7022.             source file and line number of the assertion,  and  the
  7023.             expression  used as an argument to it. A fuller discus-
  7024.             sion of the uses of assert  is  impossible  in  limited
  7025.             space,  but  it is closely linked to methods of proving
  7026.             program correctness.
  7027.  
  7028.  
  7029.  
  7030.  
  7031.                              ATOF, ATOI, ATOL
  7032.        SYNOPSIS
  7033.  
  7034.             #include  <math.h>
  7035.  
  7036.             double    atof(char * s)
  7037.             int atoi(char * s)
  7038.  
  7039.             #include  <stdlib.h>
  7040.  
  7041.             long      atol(char * s)
  7042.  
  7043.  
  7044.        DESCRIPTION
  7045.             These routines convert a decimal number in the argument
  7046.             string  s  into a double float, integer or long integer
  7047.             respectively. Leading blanks are skipped over.  In  the
  7048.             case  of  _a_t_o_f(), the number may be in scientific nota-
  7049.             tion.
  7050.  
  7051.  
  7052.  
  7053.  
  7054.  
  7055.  
  7056.  
  7057.  
  7058.  
  7059.  
  7060.  
  7061.  
  7062.  
  7063.  
  7064.    Page 106                             HI-TECH C USER'S MANUAL
  7065.  
  7066.                          BDOS (CP/M only)
  7067.    SYNOPSIS
  7068.  
  7069.         #include  <cpm.h>
  7070.  
  7071.         char      bdos(int func, int arg)
  7072.  
  7073.         short bdoshl(int func, int arg)(CP/M-80 only)
  7074.  
  7075.  
  7076.    DESCRIPTION
  7077.         _B_d_o_s() calls the CP/M BDOS with func in register C  (CL
  7078.         for  CP/M-86)  and  arg in register DE (DX). The return
  7079.         value is the byte returned by the BDOS  in  register  A
  7080.         (AX).   _B_d_o_s_h_l()  is  the  same, except that the return
  7081.         value is the value returned by the BDOS  in  HL.   Con-
  7082.         stant  values  for the various BDOS function values are
  7083.         defined in cpm.h.
  7084.  
  7085.         These functions should be avoided  except  in  programs
  7086.         which  are not intended to be used on an operating sys-
  7087.         tem other than CP/M. The standard I/O routines  are  to
  7088.         be preferred, since they are portable.
  7089.  
  7090.    SEE ALSO
  7091.  
  7092.         bios, msdos
  7093.  
  7094.  
  7095.  
  7096.  
  7097.  
  7098.                          BIOS (CP/M only)
  7099.    SYNOPSIS
  7100.  
  7101.         #includ   <cpm.h>
  7102.  
  7103.         char bios(int n, int a1, int a2)
  7104.  
  7105.  
  7106.    DESCRIPTION
  7107.         This function will call the n'th bios entry point (cold
  7108.         boot  =  0,  warm boot = 1, etc.) with register BC (CX)
  7109.         set to the argument a1 and DE (DX) set to the  argument
  7110.         a2. The return value is the contents of register A (AX)
  7111.         after the bios call. On CP/M-86, bdos  function  50  is
  7112.         used  to  perform  the bios call.  This function should
  7113.         not be used unless  unavoidable,  since  it  is  highly
  7114.         non-portable. There is even no guarantee of portability
  7115.         of bios calls between differing CP/M systems.
  7116.  
  7117.    SEE ALSO
  7118.  
  7119.         bdos
  7120.  
  7121.  
  7122.  
  7123.  
  7124.  
  7125.  
  7126.  
  7127.  
  7128.  
  7129.  
  7130.        HI-TECH C USER'S MANUAL                             Page 107
  7131.  
  7132.                                   CALLOC
  7133.        SYNOPSIS
  7134.  
  7135.             #include  <stdlib.h>
  7136.  
  7137.             char * calloc(size_t cnt, size_t size)
  7138.  
  7139.  
  7140.        DESCRIPTION
  7141.             _C_a_l_l_o_c() attempts  to  obtain  a  contiguous  block  of
  7142.             dynamic  memory  which  will  hold cnt objects, each of
  7143.             length size.  The  block  is  filled  with  zeroes.   A
  7144.             pointer  to  the  block is returned, or 0 if the memory
  7145.             could not be allocated.
  7146.  
  7147.        SEE ALSO
  7148.  
  7149.             brk, sbrk, malloc, free
  7150.  
  7151.  
  7152.  
  7153.  
  7154.  
  7155.                                CGETS, CPUTS
  7156.        SYNOPSIS
  7157.  
  7158.             #include  <conio.h>
  7159.  
  7160.             char *    cgets(char * s)
  7161.  
  7162.             void      cputs(char * s)
  7163.  
  7164.  
  7165.        DESCRIPTION
  7166.             _C_p_u_t_s() will read one line of input  from  the  console
  7167.             into  the  buffer  passed as an argument. It does so by
  7168.             repeated calls to _g_e_t_c_h_e().  _C_p_u_t_s() writes  its  argu-
  7169.             ment string to the console, outputting carriage returns
  7170.             before each newline in the  string.  It  calls  _p_u_t_c_h()
  7171.             repeatedly.
  7172.  
  7173.        SEE ALSO
  7174.  
  7175.             getch, getche, putch
  7176.  
  7177.  
  7178.  
  7179.  
  7180.  
  7181.  
  7182.  
  7183.  
  7184.  
  7185.  
  7186.  
  7187.  
  7188.  
  7189.  
  7190.  
  7191.  
  7192.  
  7193.  
  7194.  
  7195.  
  7196.    Page 108                             HI-TECH C USER'S MANUAL
  7197.  
  7198.                               CHDIR
  7199.    SYNOPSIS
  7200.  
  7201.         #include  <sys.h>
  7202.  
  7203.         int chdir(char * s)
  7204.  
  7205.  
  7206.    DESCRIPTION
  7207.         This function is availble only under MS-DOS. It changes
  7208.         the current working directory to the path name supplied
  7209.         as argument. This path  name  be  be  absolute,  as  in
  7210.         A:\FRED, or relative, as in ..\SOURCES.  A return value
  7211.         of -1 indicates that the requested change could not  be
  7212.         performed.
  7213.  
  7214.    SEE ALSO
  7215.  
  7216.         mkdir, rmdir, getcwd
  7217.  
  7218.  
  7219.  
  7220.  
  7221.  
  7222.                               CHMOD
  7223.    SYNOPSIS
  7224.  
  7225.         #include  <stat.h>
  7226.  
  7227.         int chmod(char * name, int )
  7228.         char *    name;
  7229.         int mode;
  7230.  
  7231.  
  7232.    DESCRIPTION
  7233.         This function changes the file attributes (or modes) of
  7234.         the  named  file.   The  argument name may be any valid
  7235.         file name. The  mode  argument  may  include  all  bits
  7236.         defined  in _s_t_a_t._h except those relating to the type of
  7237.         the file, e.g. S_IFDIR. Note however that not all  bits
  7238.         may  be  changed under all operating systems, e.g. nei-
  7239.         ther DOS nor CP/M permit a file to be made  unreadable,
  7240.         thus  even  if  mode  does not include S_IREAD the file
  7241.         will still be readable (and _s_t_a_t()  will  still  return
  7242.         S_IREAD in flags).
  7243.  
  7244.    SEE ALSO
  7245.  
  7246.         stat, creat
  7247.  
  7248.  
  7249.  
  7250.  
  7251.  
  7252.  
  7253.  
  7254.  
  7255.  
  7256.  
  7257.  
  7258.  
  7259.  
  7260.  
  7261.  
  7262.        HI-TECH C USER'S MANUAL                             Page 109
  7263.  
  7264.                                   CLOSE
  7265.        SYNOPSIS
  7266.  
  7267.             #include  <unixio.h>
  7268.  
  7269.             int close(int fd)
  7270.  
  7271.  
  7272.        DESCRIPTION
  7273.             This routine closes the file associated with  the  file
  7274.             descriptor fd, which will have been previously obtained
  7275.             from a call to _o_p_e_n(). _C_l_o_s_e() returns 0 for a success-
  7276.             ful close, or -1 otherwise.
  7277.  
  7278.        SEE ALSO
  7279.  
  7280.             open, read, write, seek
  7281.  
  7282.  
  7283.  
  7284.  
  7285.  
  7286.                               CLRERR, CLREOF
  7287.        SYNOPSIS
  7288.  
  7289.             #include  <stdio.h>
  7290.             void clrerr(FILE * stream)
  7291.             void clreof(FILE * stream)
  7292.  
  7293.  
  7294.        DESCRIPTION
  7295.             These are macros, defined in stdio.h, which  reset  the
  7296.             error and end of file flags respectively for the speci-
  7297.             fied stream. They should be used with care;  the  major
  7298.             valid use is for clearing an EOF status on input from a
  7299.             terminal-like device, where it may be valid to continue
  7300.             to read after having seen an end-of-file indication.
  7301.  
  7302.        SEE ALSO
  7303.  
  7304.             fopen, fclose
  7305.  
  7306.  
  7307.  
  7308.  
  7309.  
  7310.  
  7311.  
  7312.  
  7313.  
  7314.  
  7315.  
  7316.  
  7317.  
  7318.  
  7319.  
  7320.  
  7321.  
  7322.  
  7323.  
  7324.  
  7325.  
  7326.  
  7327.  
  7328.    Page 110                             HI-TECH C USER'S MANUAL
  7329.  
  7330.                                COS
  7331.    SYNOPSIS
  7332.  
  7333.         #include  <math.h>
  7334.  
  7335.         double    cos(double f)
  7336.  
  7337.  
  7338.    DESCRIPTION
  7339.         This function yields the cosine of its argument.
  7340.  
  7341.    SEE ALSO
  7342.  
  7343.         sin, tan, asin, acos, atan
  7344.  
  7345.  
  7346.  
  7347.  
  7348.  
  7349.                          COSH, SINH, TANH
  7350.    SYNOPSIS
  7351.  
  7352.         #include  <math.h>
  7353.  
  7354.         double    cosh(double f)
  7355.         double    sinh(double f)
  7356.         double    tanh(double f)
  7357.  
  7358.  
  7359.    DESCRIPTION
  7360.         These functions implement  the  hyperbolic  trig  func-
  7361.         tions.
  7362.  
  7363.  
  7364.  
  7365.  
  7366.  
  7367.  
  7368.  
  7369.  
  7370.  
  7371.  
  7372.  
  7373.  
  7374.  
  7375.  
  7376.  
  7377.  
  7378.  
  7379.  
  7380.  
  7381.  
  7382.  
  7383.  
  7384.  
  7385.  
  7386.  
  7387.  
  7388.  
  7389.  
  7390.  
  7391.  
  7392.  
  7393.  
  7394.        HI-TECH C USER'S MANUAL                             Page 111
  7395.  
  7396.                                   CREAT
  7397.        SYNOPSIS
  7398.  
  7399.             #include  <stat.h>
  7400.  
  7401.             int creat(char * name, int mode)
  7402.  
  7403.  
  7404.        DESCRIPTION
  7405.             This routine attempts to create the file named by name.
  7406.             If the file exists and is writeable, it will be removed
  7407.             and re-created. The return value is -1  if  the  create
  7408.             failed, or a small non-negative number if it succeeded.
  7409.             This number is a valuable token which must be  used  to
  7410.             write  to or close the file subsequently.  Mode is used
  7411.             to initialize the attributes of the created file.   The
  7412.             allowable  bits  are  the  same as for _c_h_m_o_d(), but for
  7413.             Unix compatibility it is recommended  that  a  mode  of
  7414.             0666  or 0600 be used. Under CP/M the mode is ignored -
  7415.             the only way to set  a  files  attributes  is  via  the
  7416.             _c_h_m_o_d() function.
  7417.  
  7418.        SEE ALSO
  7419.  
  7420.             open, close, read, write, seek, stat, chmod
  7421.  
  7422.  
  7423.  
  7424.  
  7425.  
  7426.                                   CTIME
  7427.        SYNOPSIS
  7428.  
  7429.             #include  <time.h>
  7430.  
  7431.             char *    ctime(time_t t)
  7432.  
  7433.  
  7434.        DESCRIPTION
  7435.             _C_t_i_m_e() converts the time in seconds pointed to by  its
  7436.             argument  to a string of the same form as described for
  7437.             asctime.  Thus the following program prints the current
  7438.             time and date:
  7439.  
  7440.  
  7441.                  #include  <time.h>
  7442.  
  7443.                  main()
  7444.                  {
  7445.                      time_t      t;
  7446.  
  7447.                      time(&t);
  7448.                      printf("%s", ctime(&t));
  7449.                  }
  7450.  
  7451.  
  7452.  
  7453.  
  7454.  
  7455.  
  7456.  
  7457.  
  7458.  
  7459.  
  7460.    Page 112                             HI-TECH C USER'S MANUAL
  7461.  
  7462.    SEE ALSO
  7463.  
  7464.         gmtime, localtime, asctime, time
  7465.  
  7466.  
  7467.  
  7468.  
  7469.  
  7470.                             DIV, LDIV
  7471.    SYNOPSIS
  7472.  
  7473.         #include  <stdlib.h>
  7474.  
  7475.         div_t     div(int numer, int denom)
  7476.         ldiv_t    ldiv(long numer, long denom)
  7477.  
  7478.  
  7479.    DESCRIPTION
  7480.         The _d_i_v() function computes the quotient and  remainder
  7481.         of  the  divison of numer by denom.  The _d_i_v() function
  7482.         returns a structure of type div_t, containing both  the
  7483.         quotient  and  remainder.   _l_d_i_v()  is similar to _d_i_v()
  7484.         except it takes arguments of type long  and  returns  a
  7485.         structure  of  type ldiv_t.  The types div_t and ldiv_t
  7486.         are defined in <stdlib.h> as follows:
  7487.  
  7488.         typedef struct {
  7489.              intquot, rem;
  7490.         } div_t;
  7491.  
  7492.         typedef struct {
  7493.              longquot, rem;
  7494.         } ldiv_t;
  7495.  
  7496.  
  7497.  
  7498.  
  7499.  
  7500.  
  7501.  
  7502.  
  7503.  
  7504.  
  7505.  
  7506.  
  7507.  
  7508.  
  7509.  
  7510.  
  7511.  
  7512.  
  7513.  
  7514.  
  7515.  
  7516.  
  7517.  
  7518.  
  7519.  
  7520.  
  7521.  
  7522.  
  7523.  
  7524.  
  7525.  
  7526.        HI-TECH C USER'S MANUAL                             Page 113
  7527.  
  7528.                                   DI, EI
  7529.        SYNOPSIS
  7530.  
  7531.             void ei(void);
  7532.             void di(void);
  7533.  
  7534.  
  7535.        DESCRIPTION
  7536.             _E_i() and _d_i() enable  and  disable  interrupts  respec-
  7537.             tivly.
  7538.  
  7539.  
  7540.  
  7541.  
  7542.                                    DUP
  7543.        SYNOPSIS
  7544.  
  7545.             #include  <unixio.h>
  7546.  
  7547.             int dup(int fd)
  7548.  
  7549.  
  7550.        DESCRIPTION
  7551.             Given a file descriptor, such as  returned  by  _o_p_e_n(),
  7552.             this  routine will return another file descriptor which
  7553.             will refer to the same open file.  -1  is  returned  if
  7554.             the  fd  argument is a bad descriptor or does not refer
  7555.             to an open file.
  7556.  
  7557.        SEE ALSO
  7558.  
  7559.             open, close, creat, read, write
  7560.  
  7561.  
  7562.  
  7563.  
  7564.  
  7565.  
  7566.  
  7567.  
  7568.  
  7569.  
  7570.  
  7571.  
  7572.  
  7573.  
  7574.  
  7575.  
  7576.  
  7577.  
  7578.  
  7579.  
  7580.  
  7581.  
  7582.  
  7583.  
  7584.  
  7585.  
  7586.  
  7587.  
  7588.  
  7589.  
  7590.  
  7591.  
  7592.    Page 114                             HI-TECH C USER'S MANUAL
  7593.  
  7594.                            EXECL, EXECV
  7595.    SYNOPSIS
  7596.  
  7597.         #include  <sys.h>
  7598.  
  7599.         int execl(char * name, pname, ...)
  7600.         int execv(char * name, ppname)
  7601.  
  7602.  
  7603.    DESCRIPTION
  7604.         _E_x_e_c_l() and _e_x_e_c_v() load and execute the program speci-
  7605.         fied  by  the  string name. _E_x_e_c_l() takes the arguments
  7606.         for the program from the zero-terminated list of string
  7607.         arguments.  _E_x_e_c_v()  is passed a pointer to an array of
  7608.         strings.  The array must  be  zero-terminated.  If  the
  7609.         named  program  is found and can be read, the call does
  7610.         not return. Thus any return from these routines may  be
  7611.         treated as an error.
  7612.  
  7613.    SEE ALSO
  7614.  
  7615.         spawnl, spawnv, system
  7616.  
  7617.  
  7618.  
  7619.  
  7620.  
  7621.                                EXIT
  7622.    SYNOPSIS
  7623.  
  7624.         #include  <stdlib.h>
  7625.  
  7626.         void      exit(int status)
  7627.  
  7628.  
  7629.    DESCRIPTION
  7630.         This call will close all open files and exit  from  the
  7631.         program.  On  CP/M,  this  means a return to CCP level.
  7632.         Status will be stored in a known place for  examination
  7633.         by  other  programs. This is only useful if the program
  7634.         executing was actually invoked by another program which
  7635.         is trapping warm boots. The status value will be stored
  7636.         on CP/M at 80H.  This call will never return.
  7637.  
  7638.    SEE ALSO
  7639.  
  7640.         atexit
  7641.  
  7642.  
  7643.  
  7644.  
  7645.  
  7646.  
  7647.  
  7648.  
  7649.  
  7650.  
  7651.  
  7652.  
  7653.  
  7654.  
  7655.  
  7656.  
  7657.  
  7658.        HI-TECH C USER'S MANUAL                             Page 115
  7659.  
  7660.                                   _EXIT
  7661.        SYNOPSIS
  7662.  
  7663.             #include  <stdlib.h>
  7664.             void      _exit(int status)
  7665.  
  7666.  
  7667.        DESCRIPTION
  7668.             This function will cause an  immediate  exit  from  the
  7669.             program,  without  the normal flushing of stdio buffers
  7670.             that is performed by _e_x_i_t().
  7671.  
  7672.        SEE ALSO
  7673.  
  7674.             exit
  7675.  
  7676.  
  7677.  
  7678.  
  7679.  
  7680.                            EXP, LOG, LOG10, POW
  7681.        SYNOPSIS
  7682.  
  7683.             #include  <math.h>
  7684.  
  7685.             double    exp(double f)
  7686.             double    log(double f)
  7687.             double    log10(double f)
  7688.             double    pow(double x, y)
  7689.  
  7690.  
  7691.        DESCRIPTION
  7692.             _E_x_p() returns the exponential function of its argument,
  7693.             _l_o_g() the natural logarithm of f, and _l_o_g_1_0() the loga-
  7694.             rithm to base 10. _P_o_w() returns the value of  x  raised
  7695.             to the y'th power.
  7696.  
  7697.  
  7698.  
  7699.  
  7700.  
  7701.  
  7702.  
  7703.  
  7704.  
  7705.  
  7706.  
  7707.  
  7708.  
  7709.  
  7710.  
  7711.  
  7712.  
  7713.  
  7714.  
  7715.  
  7716.  
  7717.  
  7718.  
  7719.  
  7720.  
  7721.  
  7722.  
  7723.  
  7724.    Page 116                             HI-TECH C USER'S MANUAL
  7725.  
  7726.                         FABS, CEIL, FLOOR
  7727.    SYNOPSIS
  7728.  
  7729.         #include  <math.h>
  7730.  
  7731.         double    fabs(double f)
  7732.         double    ceil(double f)
  7733.         double    floor(double f)
  7734.  
  7735.  
  7736.    DESCRIPTION
  7737.         These routines return respectively the  absolute  value
  7738.         of  f, the smallest integral value not less than f, and
  7739.         the largest integral value not greater than f.
  7740.  
  7741.  
  7742.  
  7743.  
  7744.                               FCLOSE
  7745.    SYNOPSIS
  7746.  
  7747.         #include  <stdio.h>
  7748.  
  7749.         int fclose(FILE * stream)
  7750.  
  7751.  
  7752.    DESCRIPTION
  7753.         This routine closes the specified  i/o  stream.  Stream
  7754.         should  be  a  token  returned  by  a  previous call to
  7755.         _f_o_p_e_n().  NULL is returned on a successful  close,  EOF
  7756.         otherwise.
  7757.  
  7758.    SEE ALSO
  7759.  
  7760.         fopen, fread, fwrite
  7761.  
  7762.  
  7763.  
  7764.  
  7765.  
  7766.  
  7767.  
  7768.  
  7769.  
  7770.  
  7771.  
  7772.  
  7773.  
  7774.  
  7775.  
  7776.  
  7777.  
  7778.  
  7779.  
  7780.  
  7781.  
  7782.  
  7783.  
  7784.  
  7785.  
  7786.  
  7787.  
  7788.  
  7789.  
  7790.        HI-TECH C USER'S MANUAL                             Page 117
  7791.  
  7792.                                FEOF, FERROR
  7793.        SYNOPSIS
  7794.  
  7795.             #include  <stdio.h>
  7796.  
  7797.             feof(FILE * stream)
  7798.             ferror(FILE * stream)
  7799.  
  7800.  
  7801.        DESCRIPTION
  7802.             These macros test the status of the EOF and ERROR  bits
  7803.             respectively  for  the  specified  stream. Each will be
  7804.             true if the corresponding flag is set. The  macros  are
  7805.             defined  in stdio.h. Stream must be a token returned by
  7806.             a previous _f_o_p_e_n() call.
  7807.  
  7808.        SEE ALSO
  7809.  
  7810.             fopen, fclose
  7811.  
  7812.  
  7813.  
  7814.  
  7815.  
  7816.                                   FFLUSH
  7817.        SYNOPSIS
  7818.  
  7819.             #include  <stdio.h>
  7820.  
  7821.             int fflush(FILE * stream)
  7822.  
  7823.  
  7824.        DESCRIPTION
  7825.             _F_f_l_u_s_h() will output to the disk file or  other  device
  7826.             currently  open on the specified stream the contents of
  7827.             the associated  buffer.  This  is  typically  used  for
  7828.             flushing buffered standard output in interactive appli-
  7829.             cations.
  7830.  
  7831.        SEE ALSO
  7832.  
  7833.             fopen, fclose
  7834.  
  7835.  
  7836.  
  7837.  
  7838.  
  7839.  
  7840.  
  7841.  
  7842.  
  7843.  
  7844.  
  7845.  
  7846.  
  7847.  
  7848.  
  7849.  
  7850.  
  7851.  
  7852.  
  7853.  
  7854.  
  7855.  
  7856.    Page 118                             HI-TECH C USER'S MANUAL
  7857.  
  7858.                               FGETC
  7859.    SYNOPSIS
  7860.  
  7861.         #include  <stdio.h>
  7862.  
  7863.         int fgetc(FILE * stream)
  7864.  
  7865.  
  7866.    DESCRIPTION
  7867.         _F_g_e_t_c() returns  the  next  character  from  the  input
  7868.         stream.   If  end-of-file  is  encountered  EOF will be
  7869.         returned instead. It is for this reason that the  func-
  7870.         tion is declared as int. The integer EOF is not a valid
  7871.         byte, thus end-of-file is distinguishable from  reading
  7872.         a  byte  of  all  1 bits from the file.  _F_g_e_t_c() is the
  7873.         non-macro version of _g_e_t_c().
  7874.  
  7875.    SEE ALSO
  7876.  
  7877.         fopen, fclose, fputc, getc, putc
  7878.  
  7879.  
  7880.  
  7881.  
  7882.  
  7883.                               FGETS
  7884.    SYNOPSIS
  7885.  
  7886.         #include  <stdio.h>
  7887.  
  7888.         char * fgets(char * s, size_t n, char * stream)
  7889.  
  7890.  
  7891.    DESCRIPTION
  7892.         _F_g_e_t_s() places in the buffer s  up  to  n-1  characters
  7893.         from  the  input  stream.  If  a newline is seen in the
  7894.         input before the correct number of characters is  read,
  7895.         then  _f_g_e_t_s() will return immediately. The newline will
  7896.         be left in the buffer. The buffer  will  be  null  ter-
  7897.         minated  in any case.  A successful _f_g_e_t_s() will return
  7898.         its first argument; NULL is returned on end-of-file  or
  7899.         error.
  7900.  
  7901.  
  7902.  
  7903.  
  7904.  
  7905.  
  7906.  
  7907.  
  7908.  
  7909.  
  7910.  
  7911.  
  7912.  
  7913.  
  7914.  
  7915.  
  7916.  
  7917.  
  7918.  
  7919.  
  7920.  
  7921.  
  7922.        HI-TECH C USER'S MANUAL                             Page 119
  7923.  
  7924.                                   FILENO
  7925.        SYNOPSIS
  7926.  
  7927.             fileno(FILE * stream)
  7928.  
  7929.  
  7930.        DESCRIPTION
  7931.             _F_i_l_e_n_o() is a macro from stdio.h which yields the  file
  7932.             descriptor  associated  with  stream. It is mainly used
  7933.             when it is desired to perform some low-level  operation
  7934.             on a file opened as a stdio stream.
  7935.  
  7936.        SEE ALSO
  7937.  
  7938.             fopen, fclose, open, close
  7939.  
  7940.  
  7941.  
  7942.  
  7943.  
  7944.                                   FOPEN
  7945.        SYNOPSIS
  7946.  
  7947.             #include  <stdio.h>
  7948.  
  7949.             FILE * fopen(char * name, char * mode);
  7950.  
  7951.  
  7952.        DESCRIPTION
  7953.  
  7954.  
  7955.        DESCRIPTION
  7956.             _F_o_p_e_n() attempts to open file for  reading  or  writing
  7957.             (or  both)  according to the mode string supplied.  The
  7958.             mode string is interpreted as follows:
  7959.  
  7960.        r    The file is opend for reading if it exists. If the file
  7961.             does not exist the call fails.
  7962.  
  7963.        r+   If the file exists it is opened for reading  and  writ-
  7964.             ing. If the file does not already exist the call fails.
  7965.  
  7966.        w    The file is created if it does not exist, or  truncated
  7967.             if it does. It is then opened for writing.
  7968.  
  7969.        w+   The file is created if it does not  already  exist,  or
  7970.             truncated  if  it does.  The file is opened for reading
  7971.             and writing.
  7972.  
  7973.        a    The file is created if it does not already  exist,  and
  7974.             opened  for  writing.   All  writes will be dynamically
  7975.             forced to the end of file, thus this mode is  known  as
  7976.             _a_p_p_e_n_d mode.
  7977.  
  7978.        a+   The file is created if it does not already  exist,  and
  7979.             opened  for reading and writing. All writes to the file
  7980.             will be dynamically forced to the end of the file, i.e.
  7981.             while  any  portion of the file may be read, all writes
  7982.  
  7983.  
  7984.  
  7985.  
  7986.  
  7987.  
  7988.    Page 120                             HI-TECH C USER'S MANUAL
  7989.  
  7990.         will take place at the end of the  file  and  will  not
  7991.         overwrite  any  existing  data.   Calling _f_s_e_e_k() in an
  7992.         attempt to write at any other place in  the  file  will
  7993.         not be effective.
  7994.  
  7995.         The "b" modifier may be appended to any  of  the  above
  7996.    modes,  e.g.  "r+b"  or "rb+" are equivalent. Adding the "b"
  7997.    modifier will cause the file to be opened in  binary  rather
  7998.    than  ASCII  mode.  Opening  in ASCII mode ensures that text
  7999.    files are read in a manner compatible with the  Unix-derived
  8000.    conventions  for  C  programs,  i.e. that text files contain
  8001.    lines delimited by newline characters.  The  special  treat-
  8002.    ment of read or written characters varies with the operating
  8003.    system, but includes some or all of the following:
  8004.  
  8005.    NEWLINE (LINE FEED)
  8006.         Converted to carriage return, line feed on output.
  8007.  
  8008.    RETURN
  8009.         Ignored on input, inserted before NEWLINE on output.
  8010.  
  8011.    CTRL-Z
  8012.         Signals EOF on input, appended on fclose on  output  if
  8013.         necessary on CP/M.
  8014.  
  8015.         Opening a file in binary mode will allow each character
  8016.         to  be read just as written, but because the exact size
  8017.         of a file is not known to CP/M, the  file  may  contain
  8018.         more  bytes  than were written to it.  See _o_p_e_n() for a
  8019.         description of what constitutes a file name.
  8020.  
  8021.         When using one of the  read/write  modes  (with  a  '+'
  8022.    character  in the string), although they permits reading and
  8023.    writing on the same stream, it  is  not  possible  to  arbi-
  8024.    trarily  mix  input  and output calls to the same stream. At
  8025.    any given time a stream opened with a "+" mode  will  be  in
  8026.    either  an  input  or  output  state.  The state may only be
  8027.    changed when the associated buffer is empty, which  is  only
  8028.    guaranteed  immediately  after  a call to _f_f_l_u_s_h() or one of
  8029.    the file positioning  functions  _f_s_e_e_k()  or  _r_e_w_i_n_d().  The
  8030.    buffer will also be empty after encountering EOF while read-
  8031.    ing a binary stream, but it is recommended that an  explicit
  8032.    call  to  _f_f_l_u_s_h()  be  used  to ensure this situation. Thus
  8033.    after reading from a stream  you  should  call  _f_f_l_u_s_h()  or
  8034.    _f_s_e_e_k()  before attempting to write on that stream, and vice
  8035.    versa.
  8036.  
  8037.    SEE ALSO
  8038.  
  8039.         fclose, fgetc, fputc, freopen
  8040.  
  8041.  
  8042.  
  8043.  
  8044.  
  8045.  
  8046.  
  8047.  
  8048.  
  8049.  
  8050.  
  8051.  
  8052.  
  8053.  
  8054.        HI-TECH C USER'S MANUAL                             Page 121
  8055.  
  8056.                                  FPRINTF
  8057.        SYNOPSIS
  8058.  
  8059.             #include  <stdio.h>
  8060.  
  8061.             fprintf(FILE * stream, char * fmt, ...);
  8062.             vfprintf(FILE * stream, va_list va_arg);
  8063.  
  8064.  
  8065.        DESCRIPTION
  8066.             _F_p_r_i_n_t_f() performs formatted printing on the  specified
  8067.             stream. Refer to _p_r_i_n_t_f() for the details of the avail-
  8068.             able formats.  _V_f_p_r_i_n_t_f() is similar to  _f_p_r_i_n_t_f()  but
  8069.             takes  a  variable  argument list pointer rather than a
  8070.             list of arguments. See the  description  of  _v_a__s_t_a_r_t()
  8071.             for more information on variable argument lists.
  8072.  
  8073.        SEE ALSO
  8074.  
  8075.             printf, fscanf, sscanf
  8076.  
  8077.  
  8078.  
  8079.  
  8080.  
  8081.                                   FPUTC
  8082.        SYNOPSIS
  8083.  
  8084.             #include  <stdio.h>
  8085.  
  8086.             int fputc(int c, FILE * stream)
  8087.  
  8088.  
  8089.        DESCRIPTION
  8090.             The character c is written to the supplied stream. This
  8091.             is  the  non-macro  version of _p_u_t_c(). The character is
  8092.             returned  if  it  was  successfully  written,  EOF   is
  8093.             returned  otherwise.  Note that "written to the stream"
  8094.             may mean only placing the character in the buffer asso-
  8095.             ciated with the stream.
  8096.  
  8097.        SEE ALSO
  8098.  
  8099.             putc, fgetc, fopen, fflush
  8100.  
  8101.  
  8102.  
  8103.  
  8104.  
  8105.  
  8106.  
  8107.  
  8108.  
  8109.  
  8110.  
  8111.  
  8112.  
  8113.  
  8114.  
  8115.  
  8116.  
  8117.  
  8118.  
  8119.  
  8120.    Page 122                             HI-TECH C USER'S MANUAL
  8121.  
  8122.                               FPUTS
  8123.    SYNOPSIS
  8124.  
  8125.         #include  <stdio.h>
  8126.  
  8127.         int fputs(char * s, FILE * stream)
  8128.  
  8129.  
  8130.    DESCRIPTION
  8131.         The null-terminated string s is written to the  stream.
  8132.         No  newline is appended (cf. _p_u_t_s() ). The error return
  8133.         is EOF.
  8134.  
  8135.    SEE ALSO
  8136.  
  8137.         puts, fgets, fopen, fclose
  8138.  
  8139.  
  8140.  
  8141.  
  8142.  
  8143.                               FREAD
  8144.    SYNOPSIS
  8145.  
  8146.         #include  <stdio.h>
  8147.  
  8148.         int fread(void * buf, size_t size, size_t cnt,
  8149.                  FILE * stream)
  8150.  
  8151.  
  8152.    DESCRIPTION
  8153.         Up to cnt objects, each of length size, are  read  into
  8154.         memory  at buf from the stream. The return value is the
  8155.         number of objects read. If none  is  read,  0  will  be
  8156.         returned.   Note that a return value less than cnt, but
  8157.         greater  than  0,  may  not  represent  an  error  (cf.
  8158.         _f_w_r_i_t_e() ).  No word alignment in the stream is assumed
  8159.         or necessary. The read is done via successive _g_e_t_c()'s.
  8160.  
  8161.    SEE ALSO
  8162.  
  8163.         fwrite, fopen, fclose, getc
  8164.  
  8165.  
  8166.  
  8167.  
  8168.  
  8169.  
  8170.  
  8171.  
  8172.  
  8173.  
  8174.  
  8175.  
  8176.  
  8177.  
  8178.  
  8179.  
  8180.  
  8181.  
  8182.  
  8183.  
  8184.  
  8185.  
  8186.        HI-TECH C USER'S MANUAL                             Page 123
  8187.  
  8188.                                    FREE
  8189.        SYNOPSIS
  8190.  
  8191.             #include  <stdlib.h>
  8192.  
  8193.             void      free(void * ptr)
  8194.  
  8195.  
  8196.        DESCRIPTION
  8197.             _F_r_e_e() deallocates the block of memory  at  ptr,  which
  8198.             must have been obtained from a call to _m_a_l_l_o_c() or _c_a_l_-
  8199.             _l_o_c().
  8200.  
  8201.        SEE ALSO
  8202.  
  8203.             malloc, calloc
  8204.  
  8205.  
  8206.  
  8207.  
  8208.  
  8209.                                  FREOPEN
  8210.        SYNOPSIS
  8211.  
  8212.             #include  <stdio.h>
  8213.  
  8214.             FILE * freopen(char * name, char * mode, FILE * stream)
  8215.  
  8216.  
  8217.        DESCRIPTION
  8218.             _F_r_e_o_p_e_n() closes the given stream (if  open)  then  re-
  8219.             opens  the  stream  attached  to  the file described by
  8220.             name. The mode of opening is given by mode.  It  either
  8221.             returns  the stream argument, if successful, or NULL if
  8222.             not. See _f_o_p_e_n() for more information.
  8223.  
  8224.        SEE ALSO
  8225.  
  8226.             fopen, fclose
  8227.  
  8228.  
  8229.  
  8230.  
  8231.  
  8232.  
  8233.  
  8234.  
  8235.  
  8236.  
  8237.  
  8238.  
  8239.  
  8240.  
  8241.  
  8242.  
  8243.  
  8244.  
  8245.  
  8246.  
  8247.  
  8248.  
  8249.  
  8250.  
  8251.  
  8252.    Page 124                             HI-TECH C USER'S MANUAL
  8253.  
  8254.                            FREXP, LDEXP
  8255.    SYNOPSIS
  8256.  
  8257.         #include  <math.h>
  8258.  
  8259.         double    frexp(double f, int * p)
  8260.  
  8261.         double    ldexp(double f, int i)
  8262.  
  8263.  
  8264.    DESCRIPTION
  8265.         _F_r_e_x_p() breaks a floating point number into  a  normal-
  8266.         ized  fraction  and an integral power of 2. The integer
  8267.         is stored into the int object pointed  to  by  p.   Its
  8268.         return  value  x is in the interval [0.5, 1.0) or zero,
  8269.         and f equals x times 2 raised to the  power  stored  in
  8270.         *p.   If  f is zero, both parts of the result are zero.
  8271.         _L_d_e_x_p() performs the reverse operation; the  integer  i
  8272.         is  added  to  the exponent of the floating point f and
  8273.         the resultant value returned.
  8274.  
  8275.  
  8276.  
  8277.  
  8278.                               FSCANF
  8279.    SYNOPSIS
  8280.  
  8281.         #include  <stdio.h>
  8282.  
  8283.         int fscanf(FILE * stream, char * fmt, ...)
  8284.  
  8285.  
  8286.    DESCRIPTION
  8287.         This routine performs formatted input from  the  speci-
  8288.         fied  stream. See _s_c_a_n_f() for a full description of the
  8289.         behaviour of the  routine.   _V_f_s_c_a_n_f()  is  similar  to
  8290.         _f_s_c_a_n_f()  but  takes  a  variable argument list pointer
  8291.         rather than a list of arguments. See the description of
  8292.         _v_a__s_t_a_r_t()  for  more  information on variable argument
  8293.         lists.
  8294.  
  8295.    SEE ALSO
  8296.  
  8297.         scanf, sscanf, fopen, fclose
  8298.  
  8299.  
  8300.  
  8301.  
  8302.  
  8303.  
  8304.  
  8305.  
  8306.  
  8307.  
  8308.  
  8309.  
  8310.  
  8311.  
  8312.  
  8313.  
  8314.  
  8315.  
  8316.  
  8317.  
  8318.        HI-TECH C USER'S MANUAL                             Page 125
  8319.  
  8320.                                   FSEEK
  8321.        SYNOPSIS
  8322.  
  8323.             #include  <stdio.h>
  8324.  
  8325.             int fseek(FILE * stream, long offs, int wh)
  8326.  
  8327.  
  8328.        DESCRIPTION
  8329.             _F_s_e_e_k() positions the "file pointer" (i.e. a pointer to
  8330.             the next character to be read or written) of the speci-
  8331.             fied stream as follows:
  8332.  
  8333.                          _____________________________
  8334.                         |_w_h__|____r_e_s_u_l_t_a_n_t__l_o_c_a_t_i_o_n____|
  8335.                         | 0 |  offs                  |
  8336.                         | 1 |  offs+previous location|
  8337.                         | 2 |  offs+length of file   |
  8338.                         |____|_________________________|
  8339.  
  8340.  
  8341.             It should be noted that offs is a  signed  value.  Thus
  8342.             the  3  allowed  modes  give postioning relative to the
  8343.             beginning of the file, the current file pointer and the
  8344.             end  of  the  file respectively. EOF is returned if the
  8345.             positioning request could not be satisfied.  Note  how-
  8346.             ever  that  positioning  beyond  the end of the file is
  8347.             legal, but will result  in  an  EOF  indication  if  an
  8348.             attempt  is  made  to  read  data there. It is quite in
  8349.             order to write data beyond the previous  end  of  file.
  8350.             _F_s_e_e_k() correctly accounts for any buffered data.
  8351.  
  8352.        SEE ALSO
  8353.  
  8354.             lseek, fopen, fclose
  8355.  
  8356.  
  8357.  
  8358.  
  8359.  
  8360.  
  8361.  
  8362.  
  8363.  
  8364.  
  8365.  
  8366.  
  8367.  
  8368.  
  8369.  
  8370.  
  8371.  
  8372.  
  8373.  
  8374.  
  8375.  
  8376.  
  8377.  
  8378.  
  8379.  
  8380.  
  8381.  
  8382.  
  8383.  
  8384.    Page 126                             HI-TECH C USER'S MANUAL
  8385.  
  8386.                               FTELL
  8387.    SYNOPSIS
  8388.  
  8389.         #include  <stdio.h>
  8390.  
  8391.         long      ftell(FILE * stream)
  8392.  
  8393.  
  8394.    DESCRIPTION
  8395.         This function returns the current position of the  con-
  8396.         ceptual  read/write  pointer  associated  with  stream.
  8397.         This is the position relative to the beginning  of  the
  8398.         file of the next byte to be read from or written to the
  8399.         file.
  8400.  
  8401.    SEE ALSO
  8402.  
  8403.         fseek
  8404.  
  8405.  
  8406.  
  8407.  
  8408.  
  8409.                               FWRITE
  8410.    SYNOPSIS
  8411.  
  8412.         #include  <stdio.h>
  8413.  
  8414.         int fwrite(void * buf, size_t size, size_t cnt,
  8415.                 FILE * stream)
  8416.  
  8417.  
  8418.    DESCRIPTION
  8419.         Cnt objects of length size bytes will be  written  from
  8420.         memory  at  buf, to the specified stream. The number of
  8421.         whole objects written will be returned, or  0  if  none
  8422.         could  be  written.  Any  return value not equal to cnt
  8423.         should be treated as an error (cf. _f_r_e_a_d() ).
  8424.  
  8425.    SEE ALSO
  8426.  
  8427.         fread, fopen, fclose
  8428.  
  8429.  
  8430.  
  8431.  
  8432.  
  8433.  
  8434.  
  8435.  
  8436.  
  8437.  
  8438.  
  8439.  
  8440.  
  8441.  
  8442.  
  8443.  
  8444.  
  8445.  
  8446.  
  8447.  
  8448.  
  8449.  
  8450.        HI-TECH C USER'S MANUAL                             Page 127
  8451.  
  8452.                                  _GETARGS
  8453.        SYNOPSIS
  8454.  
  8455.             #include  <sys.h>
  8456.  
  8457.             char ** _getargs(char * buf, char * name)
  8458.             extern int _argc_;
  8459.  
  8460.  
  8461.        DESCRIPTION
  8462.             This routine performs I/O redirection (CP/M  only)  and
  8463.             wild  card  expansion.  Under MS-DOS I/O redirection is
  8464.             performed by the operating system. It  is  called  from
  8465.             startup  code  to operate on the command line if the -R
  8466.             option is used to the C command, but may also be called
  8467.             by  user-written  code. If the buf argument is null, it
  8468.             will read lines of text from  standard  input.  If  the
  8469.             standard  input is a terminal (usually the console) the
  8470.             name argument will be written  to  the  standard  error
  8471.             stream as a prompt. If the buf argument is not null, it
  8472.             will be used as the source of the  string  to  be  pro-
  8473.             cessed.  The returned value is a pointer to an array of
  8474.             strings, exactly as would be pointed  to  by  the  argv
  8475.             argument  to the main() function. The number of strings
  8476.             in the array may be obtained from  the  global  _argc_.
  8477.             For example, a typical use of this function would be:
  8478.  
  8479.             #include  <sys.h>
  8480.  
  8481.             main(argc, argv)
  8482.             char ** argv;
  8483.             {
  8484.                 extern char ** _getargs();
  8485.                 extern int  _argc_;
  8486.  
  8487.                 if(argc == 1) {/* no arguments */
  8488.                 argv = _getargs(0, "myname");
  8489.                 argc = _argc_;
  8490.                 }
  8491.                 .
  8492.                 .
  8493.                 .
  8494.             }
  8495.  
  8496.             There will be one string in the array for each word  in
  8497.             the  buffer  processed.   Quotes,  either single (') or
  8498.             double (") may  be  used  to  include  white  space  in
  8499.             "words". If any wild card characters (? or *) appear in
  8500.             a non-quoted word, it will be expanded into a string of
  8501.             words,  one  for each file matching the word. The usual
  8502.             CP/M conventions are followed for  this  expansion.  On
  8503.             CP/M  any occurence of the redirection characters > and
  8504.             < outside quotes  will  be  handled  in  the  following
  8505.             manner:
  8506.  
  8507.        > name
  8508.             will cause standard output to be redirected to the file
  8509.             name.
  8510.  
  8511.  
  8512.  
  8513.  
  8514.  
  8515.  
  8516.    Page 128                             HI-TECH C USER'S MANUAL
  8517.  
  8518.    < name
  8519.         will cause standard input to  be  redirected  from  the
  8520.         file name.
  8521.  
  8522.    >> name
  8523.         will cause standard output to append to file name.
  8524.  
  8525.         White space is optional between the >  or  <  character
  8526.         and  the  file  name,  however  it  is  an  error for a
  8527.         redirection character not to  be  followed  by  a  file
  8528.         name.   It  is also an error if a file cannot be opened
  8529.         for input or created for output.  An append redirection
  8530.         (>>) will create the file if it does not exist.  If the
  8531.         source of text  to  be  processed  is  standard  input,
  8532.         several  lines  may  be  supplied  by  ending each line
  8533.         (except the last) with a backslash (\).  This serves as
  8534.         a continuation character. Note that the newline follow-
  8535.         ing the backslash is ignored, and not treated as  white
  8536.         space.
  8537.  
  8538.  
  8539.  
  8540.  
  8541.                                GETC
  8542.    SYNOPSIS
  8543.  
  8544.         #include  <stdio.h>
  8545.  
  8546.         int getc(FILE * stream)
  8547.         FILE * stream;
  8548.  
  8549.  
  8550.    DESCRIPTION
  8551.         One character is read from  the  specified  stream  and
  8552.         returned. EOF will be returned on end-of-file or error.
  8553.         This is the macro version of _f_g_e_t_c(), and is defined in
  8554.         stdio.h.
  8555.  
  8556.  
  8557.  
  8558.  
  8559.  
  8560.  
  8561.  
  8562.  
  8563.  
  8564.  
  8565.  
  8566.  
  8567.  
  8568.  
  8569.  
  8570.  
  8571.  
  8572.  
  8573.  
  8574.  
  8575.  
  8576.  
  8577.  
  8578.  
  8579.  
  8580.  
  8581.  
  8582.        HI-TECH C USER'S MANUAL                             Page 129
  8583.  
  8584.                       GETCH, GETCHE, UNGETCH, PUTCH
  8585.        SYNOPSIS
  8586.  
  8587.             #include  <conio.h>
  8588.  
  8589.             char      getch(void)
  8590.             char      getche(void)
  8591.             void      putch(int c)
  8592.  
  8593.  
  8594.        DESCRIPTION
  8595.             _G_e_t_c_h() reads a single character from the console  key-
  8596.             board  and  returns  it  without  echoing.  _G_e_t_c_h_e() is
  8597.             similar but does echo the character  typed.   _U_n_g_e_t_c_h()
  8598.             will push back one character such that the next call to
  8599.             _g_e_t_c_h()  or  _g_e_t_c_h_e()  will  return   that   character.
  8600.             _P_u_t_c_h()  outputs the character c to the console screen,
  8601.             prepending a carriage return if the character is a new-
  8602.             line.
  8603.  
  8604.        SEE ALSO
  8605.  
  8606.             cgets, cputs
  8607.  
  8608.  
  8609.  
  8610.  
  8611.  
  8612.                                  GETCHAR
  8613.        SYNOPSIS
  8614.  
  8615.             #include  <stdio.h>
  8616.  
  8617.             int getchar(void)
  8618.  
  8619.  
  8620.        DESCRIPTION
  8621.             _G_e_t_c_h_a_r() is a _g_e_t_c(_s_t_d_i_n) operation.  It  is  a  macro
  8622.             defined   in  stdio.h.  Note  that  under  normal  cir-
  8623.             cumstances getchar() will NOT return unless a  carriage
  8624.             return  has  been typed on the console. To get a single
  8625.             character immediately from the console, use the routine
  8626.             _g_e_t_c_h().
  8627.  
  8628.        SEE ALSO
  8629.  
  8630.             getc, fgetc, freopen, fclose
  8631.  
  8632.  
  8633.  
  8634.  
  8635.  
  8636.  
  8637.  
  8638.  
  8639.  
  8640.  
  8641.  
  8642.  
  8643.  
  8644.  
  8645.  
  8646.  
  8647.  
  8648.    Page 130                             HI-TECH C USER'S MANUAL
  8649.  
  8650.                        GETCWD (MS-DOS only)
  8651.    SYNOPSIS
  8652.  
  8653.         #include  <sys.h>
  8654.  
  8655.         char *    getcwd(int drive)
  8656.  
  8657.  
  8658.    DESCRIPTION
  8659.         _G_e_t_c_w_d() returns the path name of the  current  working
  8660.         directory  on  the  specified  drive,  where drive == 0
  8661.         represents the current drive, drive == 1 represents A:,
  8662.         drive  ==  2  represents B: etc.  The return value is a
  8663.         pointer to a  static  area  of  memory  which  will  be
  8664.         overwritten on the next call to _g_e_t_c_w_d().
  8665.  
  8666.    SEE ALSO
  8667.  
  8668.         chdir
  8669.  
  8670.  
  8671.  
  8672.  
  8673.  
  8674.                               GETENV
  8675.    SYNOPSIS
  8676.  
  8677.         #include  <stdlib.h>
  8678.  
  8679.         char *    getenv(char * s)
  8680.         extern char **  environ;
  8681.  
  8682.  
  8683.    DESCRIPTION
  8684.         _G_e_t_e_n_v() will search the vector of environment  strings
  8685.         for  one matching the argument supplied, and return the
  8686.         value part of that environment string. For example,  if
  8687.         the environment contains the string
  8688.  
  8689.              COMSPEC=A:\COMMAND.COM
  8690.  
  8691.         then _g_e_t_e_n_v("_C_O_M_S_P_E_C") will return A:\COMMAND.COM.  The
  8692.         global  variable  environ  is  a pointer to an array of
  8693.         pointers to environment strings, terminated by  a  null
  8694.         pointer.  This  array  is  initialized  at startup time
  8695.         under MS-DOS from the environment pointer supplied when
  8696.         the  program was executed.  Under CP/M no such environ-
  8697.         ment is supplied, so the first call  to  _g_e_t_e_n_v()  will
  8698.         attempt  to  open  a file in the current user number on
  8699.         the current drive called ENVIRON. This file should con-
  8700.         tain  definitions for any environment variables desired
  8701.         to be accessible to the program, e.g.
  8702.  
  8703.         HITECH=0:C:
  8704.  
  8705.         Each variable definition should be on a separate  line,
  8706.         consisting  of the variable name (conventionally all in
  8707.         upper case) followed without intervening white space by
  8708.  
  8709.  
  8710.  
  8711.  
  8712.  
  8713.  
  8714.        HI-TECH C USER'S MANUAL                             Page 131
  8715.  
  8716.             an  equal  sign  ('=') then the value to be assigned to
  8717.             that variable.
  8718.  
  8719.  
  8720.  
  8721.  
  8722.                                    GETS
  8723.        SYNOPSIS
  8724.  
  8725.             #include  <stdio.h>
  8726.  
  8727.             char * gets(char * s)
  8728.  
  8729.  
  8730.        DESCRIPTION
  8731.             _G_e_t_s() reads a line from standard input into the buffer
  8732.             at  s,  deleting the newline (cf. _f_g_e_t_s() ). The buffer
  8733.             is null terminated. It returns its argument, or NULL on
  8734.             end-of-file.
  8735.  
  8736.        SEE ALSO
  8737.  
  8738.             fgets, freopen
  8739.  
  8740.  
  8741.  
  8742.  
  8743.  
  8744.                             GETUID (CP/M only)
  8745.        SYNOPSIS
  8746.  
  8747.             #include  <sys.h>
  8748.  
  8749.             int getuid(void)
  8750.  
  8751.  
  8752.        DESCRIPTION
  8753.             _G_e_t_u_i_d() returns the current user number.  On CP/M, the
  8754.             current  user number determines the user number associ-
  8755.             ated with an opened or created file, unless  overridden
  8756.             by an explicit user number prefix in the file name.
  8757.  
  8758.        SEE ALSO
  8759.  
  8760.             setuid, open
  8761.  
  8762.  
  8763.  
  8764.  
  8765.  
  8766.  
  8767.  
  8768.  
  8769.  
  8770.  
  8771.  
  8772.  
  8773.  
  8774.  
  8775.  
  8776.  
  8777.  
  8778.  
  8779.  
  8780.    Page 132                             HI-TECH C USER'S MANUAL
  8781.  
  8782.                                GETW
  8783.    SYNOPSIS
  8784.  
  8785.         #include  <stdio.h>
  8786.  
  8787.         int getw(FILE * stream)
  8788.  
  8789.  
  8790.    DESCRIPTION
  8791.         _G_e_t_w() returns one word (16 bits for the Z80 and  8086)
  8792.         from  the  nominated stream. EOF is returned on end-of-
  8793.         file, but since this is  a  perfectly  good  word,  the
  8794.         _f_e_o_f()  macro  should  be  used for testing for end-of-
  8795.         file.  When reading the word, no special  alignment  in
  8796.         the  file is necessary, as the read is done by two con-
  8797.         secutive _g_e_t_c()'s.  The byte ordering is however  unde-
  8798.         fined.  The word read should in general have been writ-
  8799.         ten by _p_u_t_w().
  8800.  
  8801.    SEE ALSO
  8802.  
  8803.         putw, getc, fopen, fclose
  8804.  
  8805.  
  8806.  
  8807.  
  8808.  
  8809.                         GMTIME, LOCALTIME
  8810.    SYNOPSIS
  8811.  
  8812.         #include  <time.h>
  8813.  
  8814.         struct tm *     gmtime(time_t * t)
  8815.         struct tm *     localtime(time_t * t)
  8816.  
  8817.  
  8818.    DESCRIPTION
  8819.         These functions convert the time pointed to by t  which
  8820.         is  in  seconds  since  00:00:00 on Jan 1, 1970, into a
  8821.         broken down time stored in a structure  as  defined  in
  8822.         _t_i_m_e._h.  _G_m_t_i_m_e() performs a straight conversion, while
  8823.         _l_o_c_a_l_t_i_m_e() takes into account the contents of the glo-
  8824.         bal  integer time_zone.  This should contain the number
  8825.         of minutes that the local  time  zone  is  WESTWARD  of
  8826.         Greenwich.  Since there is no way under MS-DOS of actu-
  8827.         ally pre-determining this value, by default _l_o_c_a_l_t_i_m_e()
  8828.         will return the same result as _g_m_t_i_m_e().
  8829.  
  8830.    SEE ALSO
  8831.  
  8832.         ctime, asctime, time
  8833.  
  8834.  
  8835.  
  8836.  
  8837.  
  8838.  
  8839.  
  8840.  
  8841.  
  8842.  
  8843.  
  8844.  
  8845.  
  8846.        HI-TECH C USER'S MANUAL                             Page 133
  8847.  
  8848.                                 INP, OUTP
  8849.        SYNOPSIS
  8850.  
  8851.             char inp(unsigned port)
  8852.  
  8853.             void outp(unsigned, unsigned data)
  8854.  
  8855.  
  8856.        DESCRIPTION
  8857.             These routines read and write bytes  to  and  from  I/O
  8858.             ports.   _I_n_p()  returns  the  data  byte  read from the
  8859.             specified port, and _o_u_t_p() outputs the data byte to the
  8860.             specified port.
  8861.  
  8862.  
  8863.  
  8864.  
  8865.                       INT86, INT86X, INTDOS, INTDOSX
  8866.        SYNOPSIS
  8867.  
  8868.             #include  <dos.h>
  8869.  
  8870.             int int86(int intno, union REGS * inregs,
  8871.                 union REGS * outregs)
  8872.             int int86x(int intno, union REGS inregs,
  8873.                 union REGS outregs, struct SREGS * segregs)
  8874.             int intdos(union REGS * inregs, union REGS * outregs)
  8875.             int intdosx(union REGS * inregs, union REGS * outregs,
  8876.                 struct SREGS * segregs)
  8877.  
  8878.  
  8879.        DESCRIPTION
  8880.             These functions allow calling  of  software  interrupts
  8881.             from  C  programs.   _I_n_t_8_6()  and  _i_n_t_8_6_x() execute the
  8882.             software interrupt specified by  _i_n_t_n_o  while  _i_n_t_d_o_s()
  8883.             and  _i_n_t_d_o_s_x()  execute interrupt 21(hex), which is the
  8884.             MS-DOS  system  call  interrupt.   The  inregs  pointer
  8885.             should  point  to a union containing values for each of
  8886.             the general purpose registers to be set when  executing
  8887.             the  interrupt,  and  the  values  of  the registers on
  8888.             return are copied into the union pointed to by outregs.
  8889.             The  _x  versions  of the calls also take a pointer to a
  8890.             union defining the segment register values to be set on
  8891.             execution  of  the interrupt, though only ES and DS are
  8892.             actually set from this structure.
  8893.  
  8894.        SEE ALSO
  8895.  
  8896.             segread
  8897.  
  8898.  
  8899.  
  8900.  
  8901.  
  8902.  
  8903.  
  8904.  
  8905.  
  8906.  
  8907.  
  8908.  
  8909.  
  8910.  
  8911.  
  8912.    Page 134                             HI-TECH C USER'S MANUAL
  8913.  
  8914.             ISALNUM, ISALPHA, ISDIGIT, ISLOWER et. al.
  8915.    SYNOPSIS
  8916.  
  8917.         #include <ctype.h>
  8918.  
  8919.         isalnum(char c)
  8920.         isalpha(char c)
  8921.         isascii(char c)
  8922.         iscntrl(char c)
  8923.         isdigit(char c)
  8924.         islower(char c)
  8925.         isprint(char c)
  8926.         isgraph(char c)
  8927.         ispunct(char c)
  8928.         isspace(char c)
  8929.         isupper(char c)
  8930.         char c;
  8931.  
  8932.  
  8933.    DESCRIPTION
  8934.         These macros, defined in  ctype.h,  test  the  supplied
  8935.         character  for membership in one of several overlapping
  8936.         groups of characters. Note that all except isascii  are
  8937.         defined for _c iff _i_s_a_s_c_i_i(_c) is true.
  8938.  
  8939.              isalnum(c)      c is alphanumeric
  8940.              isalpha(c)      c is in A-Z or a-z
  8941.              isascii(c)      c is a 7 bit ascii character
  8942.              iscntrl(c)      c is a control character
  8943.              isdigit(c)      c is a decimal digit
  8944.              islower(c)      c is in a-z
  8945.              isprint(c)      c is a printing char
  8946.              isgraph(c)      c is a non-space printable character
  8947.              ispunct(c)      c is not alphanumeric
  8948.              isspace(c)      c is a space, tab or newline
  8949.              isupper(c)      c is in A-Z
  8950.              isxdigit(c)     c is in 0-9 or a-f or A-F
  8951.  
  8952.  
  8953.    SEE ALSO
  8954.  
  8955.         toupper, tolower, toascii
  8956.  
  8957.  
  8958.  
  8959.  
  8960.  
  8961.  
  8962.  
  8963.  
  8964.  
  8965.  
  8966.  
  8967.  
  8968.  
  8969.  
  8970.  
  8971.  
  8972.  
  8973.  
  8974.  
  8975.  
  8976.  
  8977.  
  8978.        HI-TECH C USER'S MANUAL                             Page 135
  8979.  
  8980.                                   ISATTY
  8981.        SYNOPSIS
  8982.  
  8983.             #include  <unixio.h>
  8984.  
  8985.             int isatty(int fd)
  8986.  
  8987.  
  8988.        DESCRIPTION
  8989.             This tests the type of the file associated with fd.  It
  8990.             returns true if the file is attached to a tty-like dev-
  8991.             ice. This would normally be used for testing  if  stan-
  8992.             dard  input  is  coming from a file or the console. For
  8993.             testing STDIO streams, use _i_s_a_t_t_y(_f_i_l_e_n_o(_s_t_r_e_a_m)).
  8994.  
  8995.  
  8996.  
  8997.  
  8998.                                   KBHIT
  8999.        SYNOPSIS
  9000.  
  9001.             #include  <conio.h>
  9002.  
  9003.             int kbhit(void)
  9004.  
  9005.  
  9006.        DESCRIPTION
  9007.             This function returns 1 if a character has been pressed
  9008.             on  the  console  keyboard,  0  otherwise. Normally the
  9009.             character would then be read via _g_e_t_c_h().
  9010.  
  9011.        SEE ALSO
  9012.  
  9013.             getch, getche
  9014.  
  9015.  
  9016.  
  9017.  
  9018.  
  9019.  
  9020.  
  9021.  
  9022.  
  9023.  
  9024.  
  9025.  
  9026.  
  9027.  
  9028.  
  9029.  
  9030.  
  9031.  
  9032.  
  9033.  
  9034.  
  9035.  
  9036.  
  9037.  
  9038.  
  9039.  
  9040.  
  9041.  
  9042.  
  9043.  
  9044.    Page 136                             HI-TECH C USER'S MANUAL
  9045.  
  9046.                              LONGJMP
  9047.    SYNOPSIS
  9048.  
  9049.         #include <setjmp.h>
  9050.  
  9051.         void      longjmp(jmp_buf buf, int val)
  9052.  
  9053.  
  9054.    DESCRIPTION
  9055.         _L_o_n_g_j_m_p(), in conjunction  with  _s_e_t_j_m_p(),  provides  a
  9056.         mechanism  for  non-local  gotos. To use this facility,
  9057.         _s_e_t_j_m_p() should be called with a  jmp_buf  argument  in
  9058.         some  outer level function. The call from _s_e_t_j_m_p() will
  9059.         return  0.  To  return  to  this  level  of  execution,
  9060.         _l_o_n_j_m_p()  may  be called with the same jmp_buf argument
  9061.         from an inner level of execution. Note however that the
  9062.         function  which  called  _s_e_t_j_m_p()  must still be active
  9063.         when _l_o_n_g_j_m_p() is called.  Breach  of  this  rule  will
  9064.         cause  disaster,  due  to the use of a stack containing
  9065.         invalid data. The val argument to _l_o_n_g_j_m_p() will be the
  9066.         value  apparently  returned  from  the  _s_e_t_j_m_p().  This
  9067.         should normally be non-zero, to distinguish it from the
  9068.         genuine _s_e_t_j_m_p() call. For example:
  9069.  
  9070.         #include <setjmp.h>
  9071.  
  9072.         static jmp_buf  jb_err;
  9073.  
  9074.         main()
  9075.         {
  9076.             if(setjmp(jb_err)) {
  9077.             printf("An error occured0);
  9078.             exit(1);
  9079.             }
  9080.             a_func();
  9081.         }
  9082.  
  9083.         a_func()
  9084.         {
  9085.             if(do_whatever() != 0)
  9086.             longjmp(jb_err, 1);
  9087.             if(do_something_else() != 0)
  9088.             longjmp(jb_err, 2);
  9089.         }
  9090.  
  9091.  
  9092.         The calls to _l_o_n_g_j_m_p() above will never return;  rather
  9093.         the  call to _s_e_t_j_m_p() will appear to return, but with a
  9094.         return  value  equal  to  the  argument   supplied   to
  9095.         _l_o_n_g_j_m_p().
  9096.  
  9097.    SEE ALSO
  9098.  
  9099.         setjmp
  9100.  
  9101.  
  9102.  
  9103.  
  9104.  
  9105.  
  9106.  
  9107.  
  9108.  
  9109.  
  9110.        HI-TECH C USER'S MANUAL                             Page 137
  9111.  
  9112.                                   LSEEK
  9113.        SYNOPSIS
  9114.  
  9115.             #include  <unixio.h>
  9116.  
  9117.             long lseek(int fd, long offs, int wh)
  9118.  
  9119.  
  9120.        DESCRIPTION
  9121.             This  function  operates  in  an  analogous  manner  to
  9122.             _f_s_e_e_k(), however it does so on unbuffered low-level i/o
  9123.             file descriptors, rather than on STDIO streams. It also
  9124.             returns  the resulting pointer location. Thus _l_s_e_e_k(_f_d,
  9125.             _0_L, _1) returns the  current  pointer  location  without
  9126.             moving it.  -1 is returned on error.
  9127.  
  9128.        SEE ALSO
  9129.  
  9130.             open, close, read, write
  9131.  
  9132.  
  9133.  
  9134.  
  9135.  
  9136.                                   MALLOC
  9137.        SYNOPSIS
  9138.  
  9139.             #include  <stdlib.h>
  9140.  
  9141.             void * malloc(size_t cnt)
  9142.  
  9143.  
  9144.        DESCRIPTION
  9145.             _M_a_l_l_o_c() attempts to allocate cnt bytes of memory  from
  9146.             the "heap", the dynamic memory allocation area. If suc-
  9147.             cessful, it returns a pointer to the block, otherwise 0
  9148.             is  returned. The memory so allocated may be freed with
  9149.             _f_r_e_e(), or changed  in  size  via  _r_e_a_l_l_o_c().  _M_a_l_l_o_c()
  9150.             calls _s_b_r_k() to obtain memory, and is in turn called by
  9151.             _c_a_l_l_o_c().  _M_a_l_l_o_c()  does  not  clear  the  memory   it
  9152.             obtains.
  9153.  
  9154.        SEE ALSO
  9155.  
  9156.             calloc, free, realloc
  9157.  
  9158.  
  9159.  
  9160.  
  9161.  
  9162.  
  9163.  
  9164.  
  9165.  
  9166.  
  9167.  
  9168.  
  9169.  
  9170.  
  9171.  
  9172.  
  9173.  
  9174.  
  9175.  
  9176.    Page 138                             HI-TECH C USER'S MANUAL
  9177.  
  9178.                  MEMSET, MEMCPY, MEMCMP, MEMMOVE
  9179.    SYNOPSIS
  9180.  
  9181.         #include  <string.h>
  9182.  
  9183.         void      memset(void s, char c, size_t n)
  9184.         void *    memcpy(void * d, void * s, size_t n)
  9185.         int memcmp(void * s1, void * s2, size_t n)
  9186.         void *    memmove(void * s1, void * s2, size_t n)
  9187.         void *    memchr(void * s, int c, size_t n)
  9188.  
  9189.  
  9190.    DESCRIPTION
  9191.         _M_e_m_s_e_t() initializes n bytes of memory starting at  the
  9192.         location pointed to by s with the character c. _M_e_m_c_p_y()
  9193.         copies n bytes of memory  starting  from  the  location
  9194.         pointed to by s to the block of memory pointed to by d.
  9195.         The result of copying overlapping blocks is  undefined.
  9196.         _M_e_m_c_m_p()  compares  two  blocks of memory, of length n,
  9197.         and returns a signed value similar to _s_t_r_n_c_m_p(). Unlike
  9198.         _s_t_r_n_c_m_p() the comparision does not stop on a null char-
  9199.         acter. The ascii collating sequence  is  used  for  the
  9200.         comparision,  but  the  effect  of  including non-ascii
  9201.         characters in the memory blocks on  the  sense  of  the
  9202.         return  value is indeterminate. _M_e_m_m_o_v_e() is similar to
  9203.         _m_e_m_c_p_y() except copying of overlapping blocks  is  han-
  9204.         dled correctly. The _m_e_m_c_h_r() function locates the first
  9205.         occurence of c (converted to unsigned char) in the ini-
  9206.         tial n characters of the object pointed to by s.
  9207.  
  9208.    SEE ALSO
  9209.  
  9210.         strncpy, strncmp, strchr
  9211.  
  9212.  
  9213.  
  9214.  
  9215.  
  9216.  
  9217.  
  9218.  
  9219.  
  9220.  
  9221.  
  9222.  
  9223.  
  9224.  
  9225.  
  9226.  
  9227.  
  9228.  
  9229.  
  9230.  
  9231.  
  9232.  
  9233.  
  9234.  
  9235.  
  9236.  
  9237.  
  9238.  
  9239.  
  9240.  
  9241.  
  9242.        HI-TECH C USER'S MANUAL                             Page 139
  9243.  
  9244.                                MKDIR, RMDIR
  9245.        SYNOPSIS
  9246.  
  9247.             #include  <sys.h>
  9248.  
  9249.             int mkdir(char * s)
  9250.             int rmdir(char * s)
  9251.  
  9252.  
  9253.        DESCRIPTION
  9254.             These functions allow the creation (_m_k_d_i_r()) and  dele-
  9255.             tion  (_r_m_d_i_r())  of  sub-directories  under  the MS-DOS
  9256.             operating system. The argument s may  be  an  arbitrary
  9257.             pathname,  and the return value will be -1 if the crea-
  9258.             tion or removal was unsuccessful.
  9259.  
  9260.        SEE ALSO
  9261.  
  9262.             chdir
  9263.  
  9264.  
  9265.  
  9266.  
  9267.  
  9268.                               MSDOS, MSDOSCX
  9269.        SYNOPSIS
  9270.  
  9271.             #include  <dos.h>
  9272.  
  9273.             long      msdos(int ax, int dx, int cx,
  9274.                 int bx, int si, int di)
  9275.             long      msdoscx(int ax, int dx, int cx,
  9276.                 int bx, int si, int di)
  9277.  
  9278.  
  9279.        DESCRIPTION
  9280.             These functions allow direct access  to  MS-DOS  system
  9281.             calls.  The  arguments  will be placed in the registers
  9282.             implied by their names, while the return value will  be
  9283.             the contents of AX and DX (for _m_s_d_o_s()) or the contents
  9284.             of DX and CX (for _m_s_d_o_s_c_x()).  Only as  many  arguments
  9285.             as  necessary  need be supplied, e.g. if only AH and DX
  9286.             need have specified valued, then only 2 argument  would
  9287.             be  required.  The  following  piece  of code outputs a
  9288.             form-feed to the printer.
  9289.  
  9290.                  msdos(0x500, '\f');
  9291.  
  9292.             Note that the system call number (in this case 5)  must
  9293.             be  multiplied  by  0x100 since MS-DOS expects the call
  9294.             number in AH, the high byte of AX.
  9295.  
  9296.        SEE ALSO
  9297.  
  9298.             intdos, intdosx, int86, int86x
  9299.  
  9300.  
  9301.  
  9302.  
  9303.  
  9304.  
  9305.  
  9306.  
  9307.  
  9308.    Page 140                             HI-TECH C USER'S MANUAL
  9309.  
  9310.                                OPEN
  9311.    SYNOPSIS
  9312.  
  9313.         #include  <unixio.h>
  9314.  
  9315.         int open(char * name, int mode)
  9316.  
  9317.  
  9318.    DESCRIPTION
  9319.         _O_p_e_n() is the fundamental means of  opening  files  for
  9320.         reading  and  writing.   The  file specified by name is
  9321.         sought, and if found is opened for reading, writing  or
  9322.         both. Mode is encoded as follows:
  9323.  
  9324.              Mode      Meaning
  9325.              0   Open for reading only
  9326.              1   Open for writing only
  9327.              2   Open for both reading and writing
  9328.  
  9329.  
  9330.         The file must already exist - if it does  not,  _c_r_e_a_t()
  9331.         should  be  used to create it.  On a successful open, a
  9332.         file descriptor is returned.  This  is  a  non-negative
  9333.         integer  which  may  be  used to refer to the open file
  9334.         subsequently.  If the open fails, -1 is returned.   The
  9335.         syntax of a CP/M filename is:
  9336.  
  9337.              [uid:][drive:]name.type
  9338.  
  9339.  
  9340.         where uid is a decimal number  0  to  15,  drive  is  a
  9341.         letter  A to P or a to p, name is 1 to 8 characters and
  9342.         type is  0  to  3  characters.  Though  there  are  few
  9343.         inherent restrictions on the characters in the name and
  9344.         type, it is recommended that they be restricted to  the
  9345.         alphanumerics and standard printing characters.  Use of
  9346.         strange characters  may  cause  problems  in  accessing
  9347.         and/or deleting the file.
  9348.  
  9349.         One or both of uid: and drive: may be omitted; if  both
  9350.         are supplied, the uid: must come first. Note that the [
  9351.         and ] are meta-symbols only. Some examples are:
  9352.  
  9353.              fred.dat
  9354.              file.c
  9355.              0:xyz.com
  9356.              0:a:file1.p
  9357.              a:file2.
  9358.  
  9359.  
  9360.         If the uid: is omitted, the file will  be  sought  with
  9361.         uid  equal  to  the current user number, as returned by
  9362.         getuid(). If drive: is omitted, the file will be sought
  9363.         on  the currently selected drive. The following special
  9364.         file names are recognized:
  9365.  
  9366.  
  9367.  
  9368.  
  9369.  
  9370.  
  9371.  
  9372.  
  9373.  
  9374.        HI-TECH C USER'S MANUAL                             Page 141
  9375.  
  9376.  
  9377.                  lst:      Accesses the list device - write only
  9378.                  pun:      Accesses the punch device - write only
  9379.                  rdr:      Accesses the reader device - read only
  9380.                  con:      Accesses the system console - read/write
  9381.  
  9382.  
  9383.             File names may be in any case - they are  converted  to
  9384.             upper case during processing of the name.
  9385.  
  9386.             MS-DOS filenames may be any valid MS-DOS 2.xx filename,
  9387.             e.g.
  9388.  
  9389.                  fred.nrk
  9390.                  A:\HITECH\STDIO.H
  9391.  
  9392.  
  9393.             The special device  names  (e.g.  CON,  LST)  are  also
  9394.             recognized.  These do not require (and should not have)
  9395.             a trailing colon.
  9396.  
  9397.        SEE ALSO
  9398.  
  9399.             close, fopen, fclose, read, write, creat
  9400.  
  9401.  
  9402.  
  9403.  
  9404.  
  9405.                                   PERROR
  9406.        SYNOPSIS
  9407.  
  9408.             #include  <stdio.h>
  9409.  
  9410.             void      perror(char * s)
  9411.  
  9412.  
  9413.        DESCRIPTION
  9414.             This routine will print on the stderr stream the  argu-
  9415.             ment s, followed by a descriptive message detailing the
  9416.             last error returned from an open, close read  or  write
  9417.             call.  Unfortunately  CP/M  does not provide definitive
  9418.             information relating to the error, except in  the  case
  9419.             of a random read or write. Thus this routine is of lim-
  9420.             ited usefulness under CP/M. MS-DOS provides  much  more
  9421.             information  however,  and use of _p_e_r_r_o_r() after MS-DOS
  9422.             file handling calls will certainly give useful diagnos-
  9423.             tics.
  9424.  
  9425.        SEE ALSO
  9426.  
  9427.             open, close, read, write
  9428.  
  9429.  
  9430.  
  9431.  
  9432.  
  9433.  
  9434.  
  9435.  
  9436.  
  9437.  
  9438.  
  9439.  
  9440.    Page 142                             HI-TECH C USER'S MANUAL
  9441.  
  9442.                          PRINTF, VPRINTF
  9443.    SYNOPSIS
  9444.  
  9445.         #include  <stdio.h>
  9446.  
  9447.         int printf(char * fmt, ...)
  9448.         int vprintf(char * fmt, va_list va_arg)
  9449.  
  9450.  
  9451.    DESCRIPTION
  9452.         _P_r_i_n_t_f() is a formatted output  routine,  operating  on
  9453.         stdout. There are corresponding routines operating on a
  9454.         given  stream  (_f_p_r_i_n_t_f())  or  into  a  string  buffer
  9455.         (_s_p_r_i_n_t_f()).  _P_r_i_n_t_f()  is passed a format string, fol-
  9456.         lowed by a list of zero or more arguments. In the  for-
  9457.         mat string are conversion specifications, each of which
  9458.         is used to print out one of the argument  list  values.
  9459.         Each  conversion  specification  is  of  the form %m.nc
  9460.         where the percent symbol  %  introduces  a  conversion,
  9461.         followed by an optional width specification m.  n is an
  9462.         optional precision  specification  (introduced  by  the
  9463.         dot)  and  c  is  a  letter  specifying the type of the
  9464.         conversion.  A minus sign ('-') preceding  m  indicates
  9465.         left  rather  than  right  adjustment  of the converted
  9466.         value in the field. Where the  field  width  is  larger
  9467.         than required for the conversion, blank padding is per-
  9468.         formed at the left or right as specified.  Where  right
  9469.         adjustment  of  a  numeric conversion is specified, and
  9470.         the first digit of m is 0, then padding  will  be  per-
  9471.         formed with zeroes rather than blanks.
  9472.  
  9473.         If the character * is used in place of a  decimal  con-
  9474.         stant,  e.g.  in the format %*d, then one integer argu-
  9475.         ment will be taken from the list to provide that value.
  9476.         The types of conversion are:
  9477.  
  9478.    f    Floating point - m is the total  width  and  n  is  the
  9479.         number  of  digits  after  the  decimal point.  If n is
  9480.         omitted it defaults to 6.
  9481.  
  9482.    e    Print the corresponding argument  in  scientific  nota-
  9483.         tion. Otherwise similar to f.
  9484.  
  9485.    g    Use e or f format, whichever gives maximum precision in
  9486.         minimum width.
  9487.  
  9488.    o x X u d
  9489.         Integer conversion -  in  radices  8,  16,  10  and  10
  9490.         respectively.  The  conversion is signed in the case of
  9491.         d, unsigned otherwise. The precision value is the total
  9492.         number  of  digits  to  print, and may be used to force
  9493.         leading zeroes. E.g. %8.4x will print at  least  4  hex
  9494.         digits  in  an  8 wide field.  Preceding the key letter
  9495.         with an l indicates that the value argument is  a  long
  9496.         integer  or  unsigned  value.   The letter X prints out
  9497.         hexadecimal numbers using the upper  case  letters  _A-_F
  9498.         rather than _a-_f as would be printed when using x.
  9499.  
  9500.  
  9501.  
  9502.  
  9503.  
  9504.  
  9505.  
  9506.        HI-TECH C USER'S MANUAL                             Page 143
  9507.  
  9508.        s    Print a string - the value argument is assumed to be  a
  9509.             character pointer. At most n characters from the string
  9510.             will be printed, in a field m characters wide.
  9511.  
  9512.        c    The argument is assumed to be a single character and is
  9513.             printed literally.
  9514.  
  9515.             Any other characters used as conversion  specifications
  9516.             will  be printed. Thus %% will produce a single percent
  9517.             sign.  Some examples:
  9518.  
  9519.             printf("Total = %4d%%", 23)
  9520.                 yields 'Total =23%'
  9521.             printf("Size is %lx" , size)
  9522.                 where size is a long, prints size
  9523.                 as hexadecimal.
  9524.             printf("Name = %.8s", "a1234567890")
  9525.                 yields 'Name = a1234567'
  9526.             printf("xx%*d", 3, 4)
  9527.                 yields 'xx  4'
  9528.  
  9529.  
  9530.             Printf returns EOF on error, 0 otherwise.  _V_p_r_i_n_t_f() is
  9531.             similar  to _p_r_i_n_t_f() but takes a variable argument list
  9532.             pointer rather  than  a  list  of  arguments.  See  the
  9533.             description of _v_a__s_t_a_r_t() for more information on vari-
  9534.             able argument lists.
  9535.  
  9536.        SEE ALSO
  9537.  
  9538.             fprintf, sprintf
  9539.  
  9540.  
  9541.  
  9542.  
  9543.  
  9544.  
  9545.  
  9546.  
  9547.  
  9548.  
  9549.  
  9550.  
  9551.  
  9552.  
  9553.  
  9554.  
  9555.  
  9556.  
  9557.  
  9558.  
  9559.  
  9560.  
  9561.  
  9562.  
  9563.  
  9564.  
  9565.  
  9566.  
  9567.  
  9568.  
  9569.  
  9570.  
  9571.  
  9572.    Page 144                             HI-TECH C USER'S MANUAL
  9573.  
  9574.                                PUTC
  9575.    SYNOPSIS
  9576.  
  9577.         #include  <stdio.h>
  9578.  
  9579.         int putc(int c, FILE * stream)
  9580.  
  9581.  
  9582.    DESCRIPTION
  9583.         _P_u_t_c() is the macro version of _f_p_u_t_c() and  is  defined
  9584.         in  stdio.h.  See  _f_p_u_t_c()  for  a  description  of its
  9585.         behaviour.
  9586.  
  9587.    SEE ALSO
  9588.  
  9589.         fputc, getc, fopen, fclose
  9590.  
  9591.  
  9592.  
  9593.  
  9594.  
  9595.                              PUTCHAR
  9596.    SYNOPSIS
  9597.  
  9598.         #include  <stdio.h>
  9599.  
  9600.         int putchar(int c)
  9601.  
  9602.  
  9603.    DESCRIPTION
  9604.         _P_u_t_c_h_a_r() is a _p_u_t_c() operation on stdout,  defined  in
  9605.         stdio.h.
  9606.  
  9607.    SEE ALSO
  9608.  
  9609.         putc, getc, freopen, fclose
  9610.  
  9611.  
  9612.  
  9613.  
  9614.  
  9615.  
  9616.  
  9617.  
  9618.  
  9619.  
  9620.  
  9621.  
  9622.  
  9623.  
  9624.  
  9625.  
  9626.  
  9627.  
  9628.  
  9629.  
  9630.  
  9631.  
  9632.  
  9633.  
  9634.  
  9635.  
  9636.  
  9637.  
  9638.        HI-TECH C USER'S MANUAL                             Page 145
  9639.  
  9640.                                    PUTS
  9641.        SYNOPSIS
  9642.  
  9643.             #include  <stdio.h>
  9644.  
  9645.             int puts(char * s)
  9646.  
  9647.  
  9648.        DESCRIPTION
  9649.             _P_u_t_s() writes  the  string  s  to  the  stdout  stream,
  9650.             appending a newline. The null terminating the string is
  9651.             not copied.  EOF is returned on error.
  9652.  
  9653.        SEE ALSO
  9654.  
  9655.             fputs, gets, freopen, fclose
  9656.  
  9657.  
  9658.  
  9659.  
  9660.  
  9661.                                    PUTW
  9662.        SYNOPSIS
  9663.  
  9664.             #include  <stdio.h>
  9665.  
  9666.             int putw(int w, FILE * stream)
  9667.  
  9668.  
  9669.        DESCRIPTION
  9670.             _P_u_t_w() copies the  word  w  to  the  given  stream.  It
  9671.             returns  w,  except  on  error,  in  which  case EOF is
  9672.             returned. Since this is a good integer, _f_e_r_r_o_r() should
  9673.             be used to check for errors.
  9674.  
  9675.        SEE ALSO
  9676.  
  9677.             getw, fopen, fclose
  9678.  
  9679.  
  9680.  
  9681.  
  9682.  
  9683.  
  9684.  
  9685.  
  9686.  
  9687.  
  9688.  
  9689.  
  9690.  
  9691.  
  9692.  
  9693.  
  9694.  
  9695.  
  9696.  
  9697.  
  9698.  
  9699.  
  9700.  
  9701.  
  9702.  
  9703.  
  9704.    Page 146                             HI-TECH C USER'S MANUAL
  9705.  
  9706.                               QSORT
  9707.    SYNOPSIS
  9708.  
  9709.         #include  <stdlib.h>
  9710.  
  9711.         void      qsort(void * base, size_t nel,
  9712.             size_t width, int (*func)())
  9713.  
  9714.  
  9715.    DESCRIPTION
  9716.         _Q_s_o_r_t() is an implementation  of  the  quicksort  algo-
  9717.         rithm.  It  sorts an array of nel items, each of length
  9718.         width bytes, located contiguously in  memory  at  base.
  9719.         Func is a pointer to a function used by _q_s_o_r_t() to com-
  9720.         pare items. It calls func with pointers to two items to
  9721.         be  compared.   If  the  first item is considered to be
  9722.         greater than, equal to or less  than  the  second  then
  9723.         _f_u_n_c()  should  return a value greater than zero, equal
  9724.         to zero or less than zero respectively.
  9725.  
  9726.         static short    array[100];
  9727.  
  9728.         #define SIZE  sizeof array/sizeof array[0]
  9729.         a_func(p1, p2)
  9730.         short * p1, * p2;
  9731.         {
  9732.             return *p1 - *p2;
  9733.         }
  9734.  
  9735.         sort_em()
  9736.         {
  9737.             qsort(array, SIZE,
  9738.                   sizeof array[0], a_func);
  9739.         }
  9740.  
  9741.  
  9742.         This will sort the array into  ascending  values.  Note
  9743.         the  use  of sizeof to make the code independent of the
  9744.         size of a short, or  the  number  of  elements  in  the
  9745.         array.
  9746.  
  9747.  
  9748.  
  9749.  
  9750.  
  9751.  
  9752.  
  9753.  
  9754.  
  9755.  
  9756.  
  9757.  
  9758.  
  9759.  
  9760.  
  9761.  
  9762.  
  9763.  
  9764.  
  9765.  
  9766.  
  9767.  
  9768.  
  9769.  
  9770.        HI-TECH C USER'S MANUAL                             Page 147
  9771.  
  9772.                                    RAND
  9773.        SYNOPSIS
  9774.  
  9775.             #include  <stdlib.h>
  9776.  
  9777.             int rand(void)
  9778.  
  9779.  
  9780.        DESCRIPTION
  9781.             _R_a_n_d() is a pseudo-random number generator. It  returns
  9782.             an  integer in the range 0 to 32767, which changes in a
  9783.             pseudo-random fashion on each call.
  9784.  
  9785.        SEE ALSO
  9786.  
  9787.             srand
  9788.  
  9789.  
  9790.  
  9791.  
  9792.  
  9793.                                    READ
  9794.        SYNOPSIS
  9795.  
  9796.             #include  <unixio.h>
  9797.  
  9798.             int read(int fd, void * buf, size_t cnt)
  9799.  
  9800.  
  9801.        DESCRIPTION
  9802.             _R_e_a_d() will read from the file associated with fd up to
  9803.             cnt  bytes into a buffer located at buf. It returns the
  9804.             number of bytes actually read. A zero return  indicates
  9805.             end-of-file.  A  negative  return  indicates  error. Fd
  9806.             should have been  obtained  from  a  previous  call  to
  9807.             _o_p_e_n().  It is possible for _r_e_a_d() to return less bytes
  9808.             than requested, e.g. when reading from the console,  in
  9809.             which case _r_e_a_d() will read one line of input.
  9810.  
  9811.        SEE ALSO
  9812.  
  9813.             open, close, write
  9814.  
  9815.  
  9816.  
  9817.  
  9818.  
  9819.  
  9820.  
  9821.  
  9822.  
  9823.  
  9824.  
  9825.  
  9826.  
  9827.  
  9828.  
  9829.  
  9830.  
  9831.  
  9832.  
  9833.  
  9834.  
  9835.  
  9836.    Page 148                             HI-TECH C USER'S MANUAL
  9837.  
  9838.                              REALLOC
  9839.    SYNOPSIS
  9840.  
  9841.         void * realloc(void * ptr, size_t cnt)
  9842.  
  9843.  
  9844.    DESCRIPTION
  9845.         _R_e_a_l_l_o_c() frees the  block  of  memory  at  ptr,  which
  9846.         should  have  been  obtained by a previous call to _m_a_l_-
  9847.         _l_o_c(), _c_a_l_l_o_c() or _r_e_a_l_l_o_c(), then attempts to allocate
  9848.         cnt  bytes  of dynamic memory, and if successful copies
  9849.         the contents of the block of memory located at ptr into
  9850.         the new block.  At most, _r_e_a_l_l_o_c() will copy the number
  9851.         of bytes which were in the old block, but  if  the  new
  9852.         block  is  smaller,  will  only copy cnt bytes.  If the
  9853.         block could not be allocated, 0 is returned.
  9854.  
  9855.    SEE ALSO
  9856.  
  9857.         malloc, calloc, realloc
  9858.  
  9859.  
  9860.  
  9861.  
  9862.  
  9863.                               REMOVE
  9864.    SYNOPSIS
  9865.  
  9866.         #include  <stdio.h>
  9867.  
  9868.         int remove(char * s)
  9869.  
  9870.  
  9871.    DESCRIPTION
  9872.         _R_e_m_o_v_e() will attempt to remove the file named  by  the
  9873.         argument  s  from  the  directory. A return value of -1
  9874.         indicates that the attempt failed.
  9875.  
  9876.    SEE ALSO
  9877.  
  9878.         unlink
  9879.  
  9880.  
  9881.  
  9882.  
  9883.  
  9884.  
  9885.  
  9886.  
  9887.  
  9888.  
  9889.  
  9890.  
  9891.  
  9892.  
  9893.  
  9894.  
  9895.  
  9896.  
  9897.  
  9898.  
  9899.  
  9900.  
  9901.  
  9902.        HI-TECH C USER'S MANUAL                             Page 149
  9903.  
  9904.                                   RENAME
  9905.        SYNOPSIS
  9906.  
  9907.             #include  <stdio.h>
  9908.  
  9909.             int rename(char * name1, char * name2)
  9910.  
  9911.  
  9912.        DESCRIPTION
  9913.             The file named by name1 will be renamed  to  name2.  -1
  9914.             will be returned if the rename was not successful. Note
  9915.             that renames across user numbers or drives are not per-
  9916.             mitted.
  9917.  
  9918.        SEE ALSO
  9919.  
  9920.             open, close, unlink
  9921.  
  9922.  
  9923.  
  9924.  
  9925.  
  9926.                                   REWIND
  9927.        SYNOPSIS
  9928.  
  9929.             #include  <stdio.h>
  9930.  
  9931.             int rewind(FILE * stream)
  9932.  
  9933.  
  9934.        DESCRIPTION
  9935.             This  function  will   attempt   to   re-position   the
  9936.             read/write  pointer  of  the  nominated  stream  to the
  9937.             beginning of the file. A return value of  -1  indicates
  9938.             that  the  attempt  was not successful, perhaps because
  9939.             the stream is associated with a non-random access  file
  9940.             such as a character device.
  9941.  
  9942.        SEE ALSO
  9943.  
  9944.             fseek, ftell
  9945.  
  9946.  
  9947.  
  9948.  
  9949.  
  9950.  
  9951.  
  9952.  
  9953.  
  9954.  
  9955.  
  9956.  
  9957.  
  9958.  
  9959.  
  9960.  
  9961.  
  9962.  
  9963.  
  9964.  
  9965.  
  9966.  
  9967.  
  9968.    Page 150                             HI-TECH C USER'S MANUAL
  9969.  
  9970.                                SBRK
  9971.    SYNOPSIS
  9972.  
  9973.         char *    sbrk(int incr)
  9974.  
  9975.  
  9976.    DESCRIPTION
  9977.         _S_b_r_k() increments the current highest  memory  location
  9978.         allocated  to  the program by incr bytes.  It returns a
  9979.         pointer to the previous highest location. Thus  _s_b_r_k(_0)
  9980.         returns  a  pointer  to  the  current highest location,
  9981.         without altering its value.  If there  is  insufficient
  9982.         memory to satisfy the request, -1 is returned.
  9983.  
  9984.    SEE ALSO
  9985.  
  9986.         brk, malloc, calloc, realloc, free
  9987.  
  9988.  
  9989.  
  9990.  
  9991.  
  9992.                               SCANF
  9993.    SYNOPSIS
  9994.  
  9995.         #include  <stdio.h>
  9996.  
  9997.         int scanf(char * fmt, ...)
  9998.         int vscanf(char *, va_list ap);
  9999.  
  10000.  
  10001.    DESCRIPTION
  10002.         _S_c_a_n_f() performs formatted  input  ("de-editing")  from
  10003.         the  stdin  stream. Similar functions are available for
  10004.         streams in general,  and  for  strings.   The  function
  10005.         _v_s_c_a_n_f() is similar, but takes a pointer to an argument
  10006.         list rather than a series of additional arguments. This
  10007.         pointer  should  have been initialized with _v_a__s_t_a_r_t().
  10008.         The input conversions are performed  according  to  the
  10009.         fmt string; in general a character in the format string
  10010.         must match a character in the input;  however  a  space
  10011.         character  in the format string will match zero or more
  10012.         "white space" characters in  the  input,  i.e.  spaces,
  10013.         tabs or newlines.  A conversion specification takes the
  10014.         form of the character  %,  optionally  followed  by  an
  10015.         assignment suppression character ('*'), optionally fol-
  10016.         lowed by a numerical maximum field width, followed by a
  10017.         conversion  specification  character.  Each  conversion
  10018.         specification, unless it  incorporates  the  assignment
  10019.         suppression character, will assign a value to the vari-
  10020.         able pointed at by the next argument. Thus if there are
  10021.         two  conversion specifications in the fmt string, there
  10022.         should  be  two  additional  pointer  arguments.    The
  10023.         conversion characters are as follows:
  10024.  
  10025.    o x d
  10026.         Skip white space, then convert a number in base  8,  16
  10027.         or   10  radix  respectively.  If  a  field  width  was
  10028.  
  10029.  
  10030.  
  10031.  
  10032.  
  10033.  
  10034.        HI-TECH C USER'S MANUAL                             Page 151
  10035.  
  10036.             supplied, take at most that many  characters  from  the
  10037.             input. A leading minus sign will be recognized.
  10038.  
  10039.        f    Skip white space, then convert  a  floating  number  in
  10040.             either  conventional or scientific notation.  The field
  10041.             width applies as above.
  10042.  
  10043.        s    Skip white space, then copy a maximal  length  sequence
  10044.             of  non-white-space  characters.  The  pointer argument
  10045.             must be a pointer to char.  The field width will  limit
  10046.             the  number  of characters copied. The resultant string
  10047.             will be null-terminated.
  10048.  
  10049.        c    Copy the next character from  the  input.  The  pointer
  10050.             argument is assumed to be a pointer to char. If a field
  10051.             width is specified, then  copy  that  many  characters.
  10052.             This differs from the s format in that white space does
  10053.             not terminate the character sequence.
  10054.  
  10055.             The conversion characters o, x, u, d and f may be  pre-
  10056.             ceded  by  an  l  to  indicate  that  the corresponding
  10057.             pointer argument is a pointer  to  long  or  double  as
  10058.             appropriate.  A  preceding  h  will  indicate  that the
  10059.             pointer argument is a pointer to short rather than int.
  10060.  
  10061.             _S_c_a_n_f() returns the number of  successful  conversions;
  10062.             EOF  is  returned  if  end-of-file  was seen before any
  10063.             conversions were performed. Some examples are:
  10064.  
  10065.                  scanf("%d %s", &a, &s)
  10066.                      with input "12s"
  10067.                  will assign 12 to a, and "s" to s.
  10068.  
  10069.                  scanf("%4cd %lf", &c, &f)
  10070.                      with input " abcd -3.5"
  10071.                  will assign " abc" to c, and -3.5 to f.
  10072.  
  10073.  
  10074.        SEE ALSO
  10075.  
  10076.             fscanf, sscanf, printf, va_arg
  10077.  
  10078.  
  10079.  
  10080.  
  10081.  
  10082.  
  10083.  
  10084.  
  10085.  
  10086.  
  10087.  
  10088.  
  10089.  
  10090.  
  10091.  
  10092.  
  10093.  
  10094.  
  10095.  
  10096.  
  10097.  
  10098.  
  10099.  
  10100.    Page 152                             HI-TECH C USER'S MANUAL
  10101.  
  10102.                              SEGREAD
  10103.    SYNOPSIS
  10104.  
  10105.         #include  <dos.h>
  10106.         int segread(struct SREGS * segregs)
  10107.  
  10108.  
  10109.    DESCRIPTION
  10110.         _S_e_g_r_e_a_d() copies the values of  the  segment  registers
  10111.         into the structure pointed to by segregs.
  10112.  
  10113.    SEE ALSO
  10114.  
  10115.         int86, int86x, intdos, intdosx
  10116.  
  10117.  
  10118.  
  10119.  
  10120.  
  10121.                               SETJMP
  10122.    SYNOPSIS
  10123.  
  10124.         #include <setjmp.h>
  10125.         int setjmp(jmp_buf buf)
  10126.  
  10127.  
  10128.    DESCRIPTION
  10129.         _S_e_t_j_m_p() is used with _l_o_n_g_j_m_p()  for  non-local  gotos.
  10130.         See _l_o_n_g_j_m_p() for further information.
  10131.  
  10132.    SEE ALSO
  10133.  
  10134.         longjmp
  10135.  
  10136.  
  10137.  
  10138.  
  10139.  
  10140.  
  10141.  
  10142.  
  10143.  
  10144.  
  10145.  
  10146.  
  10147.  
  10148.  
  10149.  
  10150.  
  10151.  
  10152.  
  10153.  
  10154.  
  10155.  
  10156.  
  10157.  
  10158.  
  10159.  
  10160.  
  10161.  
  10162.  
  10163.  
  10164.  
  10165.  
  10166.        HI-TECH C USER'S MANUAL                             Page 153
  10167.  
  10168.                             SETUID (CP/M only)
  10169.        SYNOPSIS
  10170.  
  10171.             #include  <sys.h>
  10172.  
  10173.             void setuid(int uid)
  10174.  
  10175.  
  10176.        DESCRIPTION
  10177.             _S_e_t_u_i_d() will set the current user number to  uid.  Uid
  10178.             should be a number in the range 0-15.
  10179.  
  10180.        SEE ALSO
  10181.  
  10182.             getuid
  10183.  
  10184.  
  10185.  
  10186.  
  10187.  
  10188.                              SETVBUF, SETBUF
  10189.        SYNOPSIS
  10190.  
  10191.             #include  <stdio.h>
  10192.  
  10193.             int setvbuf(FILE * stream, char * buf,
  10194.                 int mode, size_t size);
  10195.             void      setbuf(FILE * stream, char * buf)
  10196.  
  10197.  
  10198.        DESCRIPTION
  10199.             The _s_e_t_v_b_u_f() function allows the  buffering  behaviour
  10200.             of  a  STDIO  stream  to  be altered. It supersedes the
  10201.             function _s_e_t_b_u_f() which is retained for backwards  com-
  10202.             patibility.  The arguments to _s_e_t_v_b_u_f() are as follows:
  10203.             stream designates the STDIO stream to be affected;  buf
  10204.             is  a  pointer  to  a buffer which will be used for all
  10205.             subsequent I/O operations on this  stream.  If  buf  is
  10206.             null,  then the routine will allocate a buffer from the
  10207.             heap  if  necessary,  of  size  BUFSIZ  as  defined  in
  10208.             <stdio.h>.   mode  may  take the values _IONBF, to turn
  10209.             buffering off completely, _IOFBF, for  full  buffering,
  10210.             or _IOLBF for line buffering. Full buffering means that
  10211.             the associated buffer will only be flushed  when  full,
  10212.             while  line  buffering  means  that  the buffer will be
  10213.             flushed at the end  of  each  line  or  when  input  is
  10214.             requested  from  another STDIO stream. size is the size
  10215.             of the buffer supplied. For example:
  10216.  
  10217.               setvbuf(stdout, my_buf, _IOLBF, sizeof my_buf);
  10218.  
  10219.             If a buffer is supplied by the caller, that buffer will
  10220.             remain  associated  with that stream even over_f_c_l_o_s_e(),
  10221.             _f_o_p_e_n() calls until another _s_e_t_v_b_u_f() changes it.
  10222.  
  10223.  
  10224.  
  10225.  
  10226.  
  10227.  
  10228.  
  10229.  
  10230.  
  10231.  
  10232.    Page 154                             HI-TECH C USER'S MANUAL
  10233.  
  10234.    SEE ALSO
  10235.  
  10236.         fopen, freopen, fclose
  10237.  
  10238.  
  10239.  
  10240.  
  10241.  
  10242.                             SET_VECTOR
  10243.    SYNOPSIS
  10244.  
  10245.         #include  <intrpt.h>
  10246.         typedef interrupt void (*isr)();
  10247.         isr set_vector(isr * vector, isr func);
  10248.  
  10249.  
  10250.    DESCRIPTION
  10251.         This routine allows an interrupt vector to be  initial-
  10252.         ized.  The  first argument should be the address of the
  10253.         interrupt vector (not the vector number but the  actual
  10254.         address) cast to a pointer to _i_s_r, which is a typedef'd
  10255.         pointer to an interrupt function. The  second  argument
  10256.         should  be  the  function  which you want the interrupt
  10257.         vector to point to. This must  be  declared  using  the
  10258.         _i_n_t_e_r_r_u_p_t   type   qualifier.   The   return  value  of
  10259.         _s_e_t__v_e_c_t_o_r() is the previous contents of the vector.
  10260.  
  10261.    SEE ALSO
  10262.  
  10263.         di(), ei()
  10264.  
  10265.  
  10266.  
  10267.  
  10268.  
  10269.  
  10270.  
  10271.  
  10272.  
  10273.  
  10274.  
  10275.  
  10276.  
  10277.  
  10278.  
  10279.  
  10280.  
  10281.  
  10282.  
  10283.  
  10284.  
  10285.  
  10286.  
  10287.  
  10288.  
  10289.  
  10290.  
  10291.  
  10292.  
  10293.  
  10294.  
  10295.  
  10296.  
  10297.  
  10298.        HI-TECH C USER'S MANUAL                             Page 155
  10299.  
  10300.                                   SIGNAL
  10301.        SYNOPSIS
  10302.  
  10303.             #include <signal.h>
  10304.             void (* signal)(int sig, void (*func)());
  10305.  
  10306.  
  10307.        DESCRIPTION
  10308.             _S_i_g_n_a_l() provides a mechanism for catching  control-C's
  10309.             (ctrl-BREAK  for  MS-DOS)  typed  on the console during
  10310.             I/O. Under CP/M the console is polled whenever  an  I/O
  10311.             call is performed, while for MS-DOS the polling depends
  10312.             on the setting of the BREAK command.  If a control-C is
  10313.             detected  certain action will be performed. The default
  10314.             action is to exit summarily; this may be modified  with
  10315.             _s_i_g_n_a_l(). The sig argument to signal may at the present
  10316.             time be only SIGINT, signifying an interrupt condition.
  10317.             The  func  argument may be one of SIG_DFL, representing
  10318.             the default action, SIG_IGN, to ignore control-C's com-
  10319.             pletely,  or  the  address  of a function which will be
  10320.             called with one argument,  the  number  of  the  signal
  10321.             caught,  when  a  control-C is seen. As the only signal
  10322.             supported is SIGINT, this will always be the  value  of
  10323.             the argument to the called function.
  10324.  
  10325.        SEE ALSO
  10326.  
  10327.             exit
  10328.  
  10329.  
  10330.  
  10331.  
  10332.  
  10333.                                    SIN
  10334.        SYNOPSIS
  10335.  
  10336.             #include  <math.h>
  10337.  
  10338.             double    sin(double f);
  10339.  
  10340.  
  10341.        DESCRIPTION
  10342.             This function returns the sine function  of  its  argu-
  10343.             ment.
  10344.  
  10345.        SEE ALSO
  10346.  
  10347.             cos, tan, asin, acos, atan
  10348.  
  10349.  
  10350.  
  10351.  
  10352.  
  10353.  
  10354.  
  10355.  
  10356.  
  10357.  
  10358.  
  10359.  
  10360.  
  10361.  
  10362.  
  10363.  
  10364.    Page 156                             HI-TECH C USER'S MANUAL
  10365.  
  10366.                      SPAWNL, SPAWNV, SPAWNVE
  10367.    SYNOPSIS
  10368.  
  10369.         int spawnl(char * n, char * argv0, ...);
  10370.         int spawnv(cahr * n, char ** v)
  10371.         int spawnve(char * n, char ** v, char ** e)
  10372.  
  10373.  
  10374.    DESCRIPTION
  10375.         These functions will load and  execute  a  sub-program,
  10376.         named  by  the  argument n. The calling conventions are
  10377.         similar to  the  functions  _e_x_e_c_l()  and  _e_x_e_c_v(),  the
  10378.         difference being that the spawn functions return to the
  10379.         calling program after termination of  the  sub-program,
  10380.         while  the  exec  functions  return only if the program
  10381.         could not be executed.  _S_p_a_w_n_v_e() takes an  environment
  10382.         list in the same format as the argument list which will
  10383.         be supplied to the executed program as its environment.
  10384.  
  10385.    SEE ALSO
  10386.  
  10387.         execl, execv
  10388.  
  10389.  
  10390.  
  10391.  
  10392.  
  10393.                              SPRINTF
  10394.    SYNOPSIS
  10395.  
  10396.         #include  <stdio.h>
  10397.  
  10398.         int sprintf(char * buf, char * fmt, ...);
  10399.         int vsprintf(char * buf, char * fmt, va_list ap);
  10400.  
  10401.  
  10402.    DESCRIPTION
  10403.         _S_p_r_i_n_t_f() operates in a similar  fashion  to  _p_r_i_n_t_f(),
  10404.         except  that instead of placing the converted output on
  10405.         the stdout stream, the characters  are  placed  in  the
  10406.         buffer  at  buf.  The  resultant  string  will be null-
  10407.         terminated, and the number of characters in the  buffer
  10408.         will  be  returned.  _V_s_p_r_i_n_t_f takes an argument pointer
  10409.         rather than a list of arguments.
  10410.  
  10411.    SEE ALSO
  10412.  
  10413.         printf, fprintf, sscanf
  10414.  
  10415.  
  10416.  
  10417.  
  10418.  
  10419.  
  10420.  
  10421.  
  10422.  
  10423.  
  10424.  
  10425.  
  10426.  
  10427.  
  10428.  
  10429.  
  10430.        HI-TECH C USER'S MANUAL                             Page 157
  10431.  
  10432.                                    SQRT
  10433.        SYNOPSIS
  10434.  
  10435.             #include  <math.h>
  10436.  
  10437.             double    sqrt(double f)
  10438.  
  10439.  
  10440.        DESCRIPTION
  10441.             _S_q_r_t() implements a square root function using Newton's
  10442.             approximation.
  10443.  
  10444.        SEE ALSO
  10445.  
  10446.             exp
  10447.  
  10448.  
  10449.  
  10450.  
  10451.  
  10452.                                   SSCANF
  10453.        SYNOPSIS
  10454.  
  10455.             #include  <stdio.h>
  10456.  
  10457.             int sscanf(char * buf, char * fmt, ...);
  10458.             int vsscanf(char * buf, char * fmt, va_list ap);
  10459.  
  10460.  
  10461.        DESCRIPTION
  10462.             _S_s_c_a_n_f() operates  in  a  similar  manner  to  _s_c_a_n_f(),
  10463.             except that instead of the conversions being taken from
  10464.             stdin, they are taken from the string at buf.
  10465.  
  10466.        SEE ALSO
  10467.  
  10468.             scanf, fscanf, sprintf
  10469.  
  10470.  
  10471.  
  10472.  
  10473.  
  10474.  
  10475.  
  10476.  
  10477.  
  10478.  
  10479.  
  10480.  
  10481.  
  10482.  
  10483.  
  10484.  
  10485.  
  10486.  
  10487.  
  10488.  
  10489.  
  10490.  
  10491.  
  10492.  
  10493.  
  10494.  
  10495.  
  10496.    Page 158                             HI-TECH C USER'S MANUAL
  10497.  
  10498.                               SRAND
  10499.    SYNOPSIS
  10500.  
  10501.         #include  <stdlib.h>
  10502.  
  10503.         void srand(int seed)
  10504.  
  10505.  
  10506.    DESCRIPTION
  10507.         _S_r_a_n_d()  initializes  the   random   number   generator
  10508.         accessed by _r_a_n_d() with the given seed. This provides a
  10509.         mechanism  for  varying  the  starting  point  of   the
  10510.         pseudo-random sequence yielded by _r_a_n_d(). On the z80, a
  10511.         good place to get a  truly  random  seed  is  from  the
  10512.         refresh  register. Otherwise timing a response from the
  10513.         console will do.
  10514.  
  10515.    SEE ALSO
  10516.  
  10517.         rand
  10518.  
  10519.  
  10520.  
  10521.  
  10522.  
  10523.                                STAT
  10524.    SYNOPSIS
  10525.  
  10526.         #include  <stat.h>
  10527.  
  10528.         int stat(char * name, struct stat * statbuf)
  10529.  
  10530.  
  10531.    DESCRIPTION
  10532.         This routine returns  information  about  the  file  by
  10533.         name.  The  information  returned  is  operating system
  10534.         dependent, but may include file attributes (e.g.   read
  10535.         only), file size in bytes, and file modification and/or
  10536.         access times.  The argument name should be the name  of
  10537.         the  file,  and  may include path names under DOS, user
  10538.         numbers under CP/M, etc.  The argument  statbuf  should
  10539.         be  the  address  of  a  structure as defined in _s_t_a_t._h
  10540.         which will be filled in with the information about  the
  10541.         file. The structure of _s_t_r_u_c_t _s_t_a_t is as follows:
  10542.  
  10543.         struct stat
  10544.         {
  10545.          short    st_mode;  /* flags */
  10546.          long     st_atime; /* access time */
  10547.          long     st_mtime; /* modification time */
  10548.          long     st_size;  /* file size */
  10549.         };
  10550.  
  10551.  
  10552.         The access and modification times (under DOS these
  10553.         are  both  set  to  the  modification time) are in
  10554.         seconds since 00:00:00 Jan 1  1970.  The  function
  10555.         _c_t_i_m_e()  may be used to convert this to a readable
  10556.  
  10557.  
  10558.  
  10559.  
  10560.  
  10561.  
  10562.        HI-TECH C USER'S MANUAL                             Page 159
  10563.  
  10564.             value.  The file size  is  self  explanatory.  The
  10565.             flag bits are as follows:
  10566.  
  10567.                      Flag              Meaning
  10568.                    ____________________________________
  10569.                    S_IFMT      mask for file type
  10570.                    S_IFDIR     file is a directory
  10571.                    S_IFREG     file is a regular file
  10572.                    S_IREAD     file is readable
  10573.                    S_IWRITE    file is writeable
  10574.                    S_IEXEC     file is executable
  10575.                    S_HIDDEN    file is hidden
  10576.                    S_SYSTEM    file is marked system
  10577.                    S_ARCHIVE   file has been written to
  10578.  
  10579.  
  10580.             _S_t_a_t returns 0 on success, -1 on failure, e.g.  if
  10581.             the file could not be found.
  10582.  
  10583.        SEE ALSO
  10584.  
  10585.             ctime, creat, chmod
  10586.  
  10587.  
  10588.  
  10589.  
  10590.  
  10591.                   STRCAT, STRCMP, STRCPY, STRLEN et. al.
  10592.        SYNOPSIS
  10593.  
  10594.             #include  <string.h>
  10595.  
  10596.             char *    strcat(char * s1, char * s2);
  10597.             int strcmp(char * s1, char * s2);
  10598.             char *    strcpy(char * s1, char * s2);
  10599.             int strlen(char * s);
  10600.             char *    strncat(char * s1, char * s2, size_t n);
  10601.             int strncmp(char * s1, char * s2, size_t n);
  10602.             char *    strncpy(char * s1, char * s2, size_t n);
  10603.  
  10604.  
  10605.        DESCRIPTION
  10606.             These functions provide operations  on  null-terminated
  10607.             strings.  _S_t_r_c_a_t()  appends the string s2 to the end of
  10608.             the string s1.  The string at  s1  will  be  null  ter-
  10609.             minated.  Needless  to say the buffer at s1 must be big
  10610.             enough. _S_t_r_c_m_p() compares the two strings and returns a
  10611.             number  greater  than  0,  0  or  a  number less than 0
  10612.             according to whether s1 is greater than,  equal  to  or
  10613.             less  than s2. The comparision is via the ascii collat-
  10614.             ing order, with the first character the  most  signifi-
  10615.             cant.   _S_t_r_c_p_y()  copies s2 into the buffer at s1, null
  10616.             terminating it.  _S_t_r_l_e_n() returns the length of s1, not
  10617.             including  the  terminating null.  _S_t_r_n_c_a_t(), _s_t_r_n_c_m_p()
  10618.             and _s_t_r_n_c_p_y() will catenate, compare and copy s2 and s1
  10619.             in  the  same  manner as their similarly named counter-
  10620.             parts above, but involving at most  n  characters.  For
  10621.             _s_t_r_n_c_p_y(),  the  resulting  string may not be null ter-
  10622.             minated.
  10623.  
  10624.  
  10625.  
  10626.  
  10627.  
  10628.    Page 160                             HI-TECH C USER'S MANUAL
  10629.  
  10630.                          STRCHR, STRRCHR
  10631.    SYNOPSIS
  10632.  
  10633.         #include  <string.h>
  10634.  
  10635.         char *    strchr(char * s, int c)
  10636.         char *    strrchr(char * s, int c)
  10637.  
  10638.  
  10639.    DESCRIPTION
  10640.         These functions locate an instance of the  character  c
  10641.         in the string s. In the case of _s_t_r_c_h_r() a pointer will
  10642.         be returned to the  first  instance  of  the  character
  10643.         found  be  searching  from the beginning of the string,
  10644.         while _s_t_r_r_c_h_r() searches backwards from the end of  the
  10645.         string.  A  null  pointer  is returned if the character
  10646.         does not exist in the string.
  10647.  
  10648.    SEE ALSO
  10649.  
  10650.  
  10651.  
  10652.  
  10653.  
  10654.  
  10655.                               SYSTEM
  10656.    SYNOPSIS
  10657.  
  10658.         #include  <sys.h>
  10659.  
  10660.         int system(char * s)
  10661.  
  10662.  
  10663.    DESCRIPTION
  10664.         When executed under MS-DOS _s_y_s_t_e_m() will pass the argu-
  10665.         ment  string  to the command processor, located via the
  10666.         environment string COMSPEC,  for  execution.  The  exit
  10667.         status  of  the command processor will be returned from
  10668.         the call to system().  For example,  to  set  the  baud
  10669.         rate on the serial port on an MS-DOS machine:
  10670.  
  10671.              system("MODE COM1:96,N,8,1,P");
  10672.  
  10673.         This function will not work on CP/M-86  since  it  does
  10674.         not  have  an invokable command interpreter. Under Con-
  10675.         current CP/M the CLI system call is used.
  10676.  
  10677.    SEE ALSO
  10678.  
  10679.         spawnl, spawnv
  10680.  
  10681.  
  10682.  
  10683.  
  10684.  
  10685.  
  10686.  
  10687.  
  10688.  
  10689.  
  10690.  
  10691.  
  10692.  
  10693.  
  10694.        HI-TECH C USER'S MANUAL                             Page 161
  10695.  
  10696.                                    TAN
  10697.        SYNOPSIS
  10698.  
  10699.             #include  <math.h>
  10700.  
  10701.             double    tan(double f);
  10702.  
  10703.  
  10704.        DESCRIPTION
  10705.             This is the tangent function.
  10706.  
  10707.        SEE ALSO
  10708.  
  10709.             sin, cos, asin, acos, atan
  10710.  
  10711.  
  10712.  
  10713.  
  10714.  
  10715.                                    TIME
  10716.        SYNOPSIS
  10717.  
  10718.             #include  <time.h>
  10719.  
  10720.             time_t    time(time_t * t)
  10721.  
  10722.  
  10723.        DESCRIPTION
  10724.             This function returns the current time in seconds since
  10725.             00:00:00  on  Jan  1,  1970.  If the argument t is non-
  10726.             null, the same value is stored into the object  pointed
  10727.             to  by  t.   The accuracy of this function is naturally
  10728.             dependent on the operating system  having  the  correct
  10729.             time. This function does not work under CP/M-86 or CP/M
  10730.             2.2 but does work under Concurrent-CP/M and CP/M+.
  10731.  
  10732.        SEE ALSO
  10733.  
  10734.             ctime, gmtime, localtime, asctime
  10735.  
  10736.  
  10737.  
  10738.  
  10739.  
  10740.  
  10741.  
  10742.  
  10743.  
  10744.  
  10745.  
  10746.  
  10747.  
  10748.  
  10749.  
  10750.  
  10751.  
  10752.  
  10753.  
  10754.  
  10755.  
  10756.  
  10757.  
  10758.  
  10759.  
  10760.    Page 162                             HI-TECH C USER'S MANUAL
  10761.  
  10762.                     TOUPPER, TOLOWER, TOASCII
  10763.    SYNOPSIS
  10764.  
  10765.         #include  <ctype.h>
  10766.         char toupper(int c);
  10767.         char tolower(int c);
  10768.         char toascii(int c);
  10769.         char      c;
  10770.  
  10771.  
  10772.    DESCRIPTION
  10773.         _T_o_u_p_p_e_r() converts its lower case  alphabetic  argument
  10774.         to  upper  case, _t_o_l_o_w_e_r() performs the reverse conver-
  10775.         sion, and _t_o_a_s_c_i_i() returns a result that is guaranteed
  10776.         in the range 0-0177. _T_o_u_p_p_e_r() and _t_o_l_o_w_e_r return their
  10777.         arguments if it is not an alphabetic character.
  10778.  
  10779.    SEE ALSO
  10780.  
  10781.         islower, isupper, isascii et. al.
  10782.  
  10783.  
  10784.  
  10785.  
  10786.  
  10787.                               UNGETC
  10788.    SYNOPSIS
  10789.  
  10790.         #include  <stdio.h>
  10791.  
  10792.         int ungetc(int c, FILE * stream)
  10793.  
  10794.  
  10795.    DESCRIPTION
  10796.         _U_n_g_e_t_c() will attempt to push back the character c onto
  10797.         the  named stream, such that a subsequent _g_e_t_c() opera-
  10798.         tion will return the character. At most  one  level  of
  10799.         pushback will be allowed, and if the stream is not buf-
  10800.         fered, even this may not be possible. EOF  is  returned
  10801.         if the _u_n_g_e_t_c() could not be performed.
  10802.  
  10803.    SEE ALSO
  10804.  
  10805.         getc
  10806.  
  10807.  
  10808.  
  10809.  
  10810.  
  10811.  
  10812.  
  10813.  
  10814.  
  10815.  
  10816.  
  10817.  
  10818.  
  10819.  
  10820.  
  10821.  
  10822.  
  10823.  
  10824.  
  10825.  
  10826.        HI-TECH C USER'S MANUAL                             Page 163
  10827.  
  10828.                                   UNLINK
  10829.        SYNOPSIS
  10830.  
  10831.             int unlink(char * name)
  10832.  
  10833.  
  10834.        DESCRIPTION
  10835.             _U_n_l_i_n_k() will remove (delete) the named file,  that  is
  10836.             erase  the  file  from  its directory. See _o_p_e_n() for a
  10837.             description of the file name construction.   Zero  will
  10838.             be returned if successful, -1 if the file did not exist
  10839.             or it could not be removed.
  10840.  
  10841.        SEE ALSO
  10842.  
  10843.             open, close, rename, remove
  10844.  
  10845.  
  10846.  
  10847.  
  10848.  
  10849.                          VA_START, VA_ARG, VA_END
  10850.        SYNOPSIS
  10851.  
  10852.             #include  <stdarg.h>
  10853.  
  10854.             void      va_start(va_list ap, _p_a_r_m_N);
  10855.             _t_y_p_e      va_arg(ap, _t_y_p_e);
  10856.             void      va_end(va_list ap);
  10857.  
  10858.  
  10859.        DESCRIPTION
  10860.             These macros are provided to give access in a  portable
  10861.             way to parameters to a function represented in a proto-
  10862.             type by the  ellipsis  symbol  (...),  where  type  and
  10863.             number  of  arguments  supplied to the function are not
  10864.             known at compile time. The rightmost parameter  to  the
  10865.             function  (shown  as  _p_a_r_m_N) plays an important role in
  10866.             these macros, as it is the starting point for access to
  10867.             further  parameters.  In  a  function  taking  variable
  10868.             numbers of arguments, a variable of type va_list should
  10869.             be  declared, then the macro va_start invoked with that
  10870.             variable and the name of _p_a_r_m_N.  This  will  initialize
  10871.             the  variable  to  allow  subsequent calls of the macro
  10872.             va_arg to access successive parameters.  Each  call  to
  10873.             va_arg  requires two arguments; the variable previously
  10874.             defined and a type name which is the type that the next
  10875.             parameter  is  expected  to be. Note that any arguments
  10876.             thus accessed will have been  widened  by  the  default
  10877.             conventions  to _i_n_t, _u_n_s_i_g_n_e_d _i_n_t or _d_o_u_b_l_e.  For exam-
  10878.             ple if a character argument has been passed, it  should
  10879.             be accessed by va_arg(ap, int) since the char will have
  10880.             been widened to _i_n_t.  An example is given  below  of  a
  10881.             function  taking  one  integer parameter, followed by a
  10882.             number of other parameters. In this example  the  func-
  10883.             tion  expects  the subsequent parameters to be pointers
  10884.             to char, but note that the compiler  is  not  aware  of
  10885.             this,  and  it  is  the  programmers  responsibility to
  10886.  
  10887.  
  10888.  
  10889.  
  10890.  
  10891.  
  10892.    Page 164                             HI-TECH C USER'S MANUAL
  10893.  
  10894.         ensure that correct arguments are supplied.
  10895.  
  10896.         #include  <stdarg.h>
  10897.         prf(int n, ...)
  10898.         {
  10899.             va_list         ap;
  10900.  
  10901.             va_start(ap, n);
  10902.             while(n--)
  10903.             puts(va_arg(ap, char *));
  10904.             va_end(ap);
  10905.         }
  10906.  
  10907.  
  10908.  
  10909.  
  10910.  
  10911.                               WRITE
  10912.    SYNOPSIS
  10913.  
  10914.         #include  <unixio.h>
  10915.  
  10916.         int write(int fd, void * buf, size_t cnt)
  10917.  
  10918.  
  10919.    DESCRIPTION
  10920.         _W_r_i_t_e() will write from the buffer at  buf  up  to  cnt
  10921.         bytes  to  the file associated with the file descriptor
  10922.         fd. The  number  of  bytes  actually  written  will  be
  10923.         returned. EOF or a value less than cnt will be returned
  10924.         on error.  In any case, any return value not  equal  to
  10925.         cnt should be treated as an error (cf. _r_e_a_d() ).
  10926.  
  10927.    SEE ALSO
  10928.  
  10929.         open, close, read
  10930.  
  10931.  
  10932.  
  10933.  
  10934.  
  10935.  
  10936.  
  10937.  
  10938.  
  10939.  
  10940.  
  10941.  
  10942.  
  10943.  
  10944.  
  10945.  
  10946.  
  10947.  
  10948.  
  10949.  
  10950.  
  10951.  
  10952.  
  10953.  
  10954.  
  10955.  
  10956.  
  10957.  
  10958.        HI-TECH C USER'S MANUAL                             Page 165
  10959.  
  10960.                                   INDEX
  10961.  
  10962.  
  10963.        8086 70                         CP/M 26,106,131,155
  10964.        absolute value 116              CP/M-80 compiler 2
  10965.        acos() 103                      cputs() 107
  10966.        address                         creat() 111
  10967.            link 73                     creating a library 76
  10968.            load 73                     CREF 83
  10969.        ANSI Standard 13,17             cross compilers 3
  10970.        array                           cross reference 36,83
  10971.            dimension 16                ctime() 111
  10972.            index 16                    ctrl-Z 26,120
  10973.            size 16                     date and time 104
  10974.        ASCII 26                        debugging 10,105
  10975.        asctime() 104                   device name as file 23
  10976.        asin() 103                      device
  10977.        assembler                           as file 141
  10978.            in C programs 20            di() 113
  10979.        assert() 105                    directory 108,139
  10980.        atan() 103                          current 130
  10981.        atan2() 103                     disk changing on floppy disk
  10982.        Atari ST 3                          systems 3
  10983.        atexit() 104                    disk space 33
  10984.        atof() 105                      div() 112
  10985.        atoi() 105                      div_t 112
  10986.        atol() 105                      dup() 113
  10987.        bdos() 106                      editor 3,33
  10988.        binary output file 8            ei() 113
  10989.        bios() 106                      entering long commands 7
  10990.        braces                          Enumerated Types 16
  10991.            omission of 16              environment 130
  10992.        byte ordering 21                error message:
  10993.        C command 3,7                       Can't generate code 33
  10994.        C reference books 2                 Error closing file 33
  10995.        calloc() 107                        No room 33
  10996.        carriage return 26,120              out of memory 33
  10997.        ceil() 116                          Undefined symbol 33
  10998.        cgets() 107                         Write error 33
  10999.        change file attributes 108      error messages 23,33
  11000.        character testing 134               format of 23
  11001.        chdir() 108                         LIBR 78
  11002.        checksum 79,80                      list of 23,85
  11003.        chmod() 108                         redirection of 23
  11004.        class name 70                   execl() 114
  11005.        close() 109                     executing a sub-program 156
  11006.        clreof() 109                    executing  system   commands
  11007.        clrerr() 109                        160
  11008.        command line 7,12,77,160        execution profiling 10
  11009.        Compatibility 25                execv() 114
  11010.        compiler driver 3               exit() 114
  11011.        Compiler Structure 5            exp() 115
  11012.        console I/O 107,129,135         exponentional functions 115
  11013.        control-C handling 155          Extern Declarations 30
  11014.        converting ascii  to  binary    fabs() 116
  11015.            105                         fclose() 116
  11016.        cos() 110                       feof() 117
  11017.        cosh() 110                      ferror() 117
  11018.  
  11019.  
  11020.  
  11021.  
  11022.  
  11023.  
  11024.    Page 166                             HI-TECH C USER'S MANUAL
  11025.  
  11026.    fflush() 117                    getw() 132
  11027.    fgetc() 118                     global variables 30
  11028.    fgets() 118                     gmtime() 132
  11029.    FILE 99                         hex output file 8
  11030.    file descriptor 27,111,119      I/O redirection 127
  11031.        duplicating 113             I/O
  11032.    FILE pointer 27                     ASCII 26
  11033.    file                                Binary 26
  11034.        access time 158                 standard 25,99
  11035.        attributes 108,158          in-line assembler 20
  11036.        closing a 109,116           Initialization Syntax 16
  11037.        creating a 111              initializer 16
  11038.        deleting a 148,163          inp() 133
  11039.        flushing buffer to a 117    int86() 133
  11040.        information about a 158     int86x() 133
  11041.        modification time 158       intdos() 133
  11042.        opening a 119,123,140       intdosx() 133
  11043.        random   access   to   a    Intel hex format 79
  11044.        125,137                     interrupt 133
  11045.        reading from a 122,147      interrupt handling 155
  11046.        renaming a 149              interrupt vector
  11047.        size 158                        setting 154
  11048.        type of a 135               isalnul() 134
  11049.        writing to a 126,164        isalnum() 134
  11050.    fileno() 119                    isalpha() 134
  11051.    floating point                  isascii() 134
  11052.        library 27                  isatty() 135
  11053.        options required to  use    iscntrl() 134
  11054.        4                           isdigit() 134
  11055.    floor() 116                     isgraph() 134
  11056.    fopen() 26,119                  islower() 134
  11057.    formatted input 124,150         ispunct() 134
  11058.    formatted printing 121,142      isspace() 134
  11059.    fprintf() 121                   isupper() 134
  11060.    fputc() 121                     kbhit() 135
  11061.    fputs() 122                     Kernighan and Ritchie 2,16
  11062.    fread() 122                     large model 70,80
  11063.    free() 123                      ldexp() 124
  11064.    freopen() 123                   ldiv() 112
  11065.    frexp() 124                     LIBR 75
  11066.    fscanf() 124                    librarian 75
  11067.    fseek() 125                     libraries 7
  11068.    ftell() 126                     library manager 75
  11069.    function parameter 163          library ordering 77
  11070.    function                        library
  11071.        declaration 17                  creating 76
  11072.        large 33                        floating point 33
  11073.        parameters 17                   ordering 33
  11074.        prototype 17,163            line number symbols 10
  11075.    fwrite() 126                    linker 69
  11076.    getc() 128                      LINT 16
  11077.    getch() 129                     localtime 132
  11078.    getchar() 25,129                log() 115
  11079.    getche() 129                    log10() 115
  11080.    getcwd() 130                    logarithmic functions 115
  11081.    getenv() 130                    long 30
  11082.    gets() 131                      longjmp() 136
  11083.    getuid() 131                    lseek() 137
  11084.  
  11085.  
  11086.  
  11087.  
  11088.  
  11089.  
  11090.        HI-TECH C USER'S MANUAL                             Page 167
  11091.  
  11092.        Machine Dependencies 21         pack pragma 20
  11093.        macros                          parameter
  11094.            predefined 21                   type 17
  11095.        malloc() 137                    perror() 141
  11096.        Member Names 13,29              portable code 21
  11097.        memcmp() 138                    pow() 115
  11098.        memcpy() 138                    pragma 20,21
  11099.        memory            allocation    printf 33
  11100.            107,148,150                 printf() 142
  11101.            releasing 123               program execution 156
  11102.        memory model 31                 psect
  11103.        memory requirements 2               linking 69
  11104.        memset() 138                        local 70
  11105.        mkdir() 139                     putc() 144
  11106.        Motorola hex format 80          putch() 129
  11107.        MS-DOS 108,133,139,155          putchar() 144
  11108.        msdos() 139                     puts() 145
  11109.        msdoscx() 139                   putw() 145
  11110.        multiple definitions 30         qsort() 146
  11111.        newline 26                      rand() 147
  11112.        Newton's approximation 157      random numbers 147,158
  11113.        non-local goto 136,152          read() 147
  11114.        objtohex 72,79                  realloc() 148
  11115.        open() 140                      relocation 69
  11116.        Operating Details 7             remove() 148
  11117.        options 7                       rename() 149
  11118.            -1 10                       return 26,120
  11119.            -11 11                      rewind() 149
  11120.            -2 11                       rmdir() 139
  11121.            -6301 11                    S format hex 80
  11122.            -A 8                        sbrk() 150
  11123.            -B 9                        scanf 33
  11124.            -C 7                        scanf() 150
  11125.            -CPM 7                      segment registers 152
  11126.            -CR 7                       segread() 152
  11127.            -D 8                        self relocation 72
  11128.            -E 10                       setbuf() 153
  11129.            -F 8                        setjmp() 152
  11130.            -G 10                       setuid() 153
  11131.            -H 10                       setvbuf() 153
  11132.            -I 8                        set_vector() 154
  11133.            -LF 4,27,33                 shift
  11134.            -M 8                            signed 14
  11135.            -O 8                            unsigned 14
  11136.            -Ooutfile 8                 short 21,30
  11137.            -P 10                       signal() 155
  11138.            -R 8                        sin() 155
  11139.            -S 7                        sinh() 110
  11140.            -U 8                        size of data types 21
  11141.            -V 3,8                      sorting 146
  11142.            -W 10                       source file naming 3
  11143.            -X 8                        source level debugging 10
  11144.            -Z 10                       spawnl() 156
  11145.            linker 71                   spawnv() 156
  11146.        outp() 133                      spawnve() 156
  11147.        pack 21                         Specific Features 13
  11148.                                        sprintf() 156
  11149.                                        sqrt() 157
  11150.  
  11151.  
  11152.  
  11153.  
  11154.  
  11155.  
  11156.    Page 168                             HI-TECH C USER'S MANUAL
  11157.  
  11158.    square root function 157        Unsigned Types 14
  11159.    srand() 158                     user ID 131,153
  11160.    sscanf() 157                    V3.09 2
  11161.    Standard Libraries 25           va_arg 18,163
  11162.    Standard  Library  Functions    va_end 163
  11163.        99                          va_start 163
  11164.    stat() 158                      void 18
  11165.    stdarg.h 18,163                     Pointer to 18
  11166.    STDIO 25,27,99                  warning level 10
  11167.    storage allocator 18            warning messages
  11168.    strcat() 159                        suppressing 10
  11169.    strchr() 160                    wild card expansion 127
  11170.    strcmp() 159                    Wordstar 33
  11171.    strcpy() 159                    write() 164
  11172.    stream 27,99                    Z180 MMU 68
  11173.    string manipulation 159             Bank Base Register 68
  11174.    strlen() 159                        BBR 68
  11175.    strncat() 159                       CBAR 68
  11176.    strncmp() 159                       CBR 68
  11177.    strncpy() 159                       Common Base Register 68
  11178.    strrchr() 160                       Common/Bank Area  Regis-
  11179.    Structure Operations 15             ter 68
  11180.    structure packing 20            Z180 Registers 68
  11181.    structures                          ASCI 68
  11182.        as function argument 15         Bank Base Register 68
  11183.        assignment 15                   BBR 68
  11184.        functions returning 15          BCR0H 68
  11185.    Stylistic Considerations 29         BCR0L 68
  11186.    symbol file 10,80                   BCR1H 68
  11187.    symbols                             BCR1L 68
  11188.        cross reference 83              CBAR 68
  11189.        global 70,76                    CBR 68
  11190.    System Requirements 2               CNTLA0 68
  11191.    system() 160                        CNTLA1 68
  11192.    tan() 161                           CNTLB0 68
  11193.    tanh() 110                          CNTLB1 68
  11194.    temporary files 4                   CNTR 68
  11195.    text editor 3                       Common Base Register 68
  11196.    time and date 104                   Common/Bank Area  Regis-
  11197.    time() 161                          ter 68
  11198.    toascii() 162                       CSI/0 68
  11199.    tolower() 162                       DAR0B 68
  11200.    toupper() 162                       DAR0H 68
  11201.    trigonometric      functions        DAR0L 68
  11202.        103,110                         DCNTL 68
  11203.        hyperbolic 110                  DMA 68
  11204.    Type Checking 13                    DMA Byte Count 68
  11205.    type qualifiers 19                  DMA Desitination Address
  11206.    typecast 13                         68
  11207.    typecasting 18                      DMA Mode Register 68
  11208.    ungetc() 162                        DMA Source Address 68
  11209.    ungetch() 129                       DMA Status Register 68
  11210.    Unix                                DMODE 68
  11211.        C compiler 16                   DSTAT 68
  11212.        V7 25                           FRC 68
  11213.    unlink() 163                        Free Running Counter 68
  11214.    unsigned 23                         IAR1H 68
  11215.    unsigned char 21                    IAR1L 68
  11216.  
  11217.  
  11218.  
  11219.  
  11220.  
  11221.  
  11222.        HI-TECH C USER'S MANUAL                             Page 169
  11223.  
  11224.            ICR 68                          INC 55
  11225.            IL 68                           IND 55
  11226.            Interrupt Vector  Regis-        INDR 56
  11227.            ter 68                          INI 56
  11228.            ITC 68                          INIR 56
  11229.            MAR1B 68                        JP 56
  11230.            MAR1H 68                        JR 56
  11231.            MAR1L 68                        LD 56,57,58,59
  11232.            MMU 68                          LDD 59
  11233.            OMCR 68                         LDDR 59
  11234.            RCR 68                          LDI 59
  11235.            Refresh Control Register        LDIR 59
  11236.            68                              MLT 59
  11237.            RLDR0H 68                       NEG 59
  11238.            RLDR0L 68                       NOP 59
  11239.            RLDR1H 68                       OR 59,60
  11240.            RLDR1L 68                       OTDM 61
  11241.            SAR0B 68                        OTDMR 60
  11242.            SAR0H 68                        OTDR 60
  11243.            SAR0L 68                        OTIM 61
  11244.            STAT0 68                        OTIMR 60
  11245.            STAT1 68                        OTIR 60
  11246.            TCR 68                          OUT 60
  11247.            TDR0 68                         OUT0 60
  11248.            TDR1 68                         OUTD 60
  11249.            TIMER 0 68                      OUTI 61
  11250.            TIMER 1 68                      POP 61
  11251.            TMDR0H 68                       PUSH 61
  11252.            TMDR0L 68                       RES 61,62,63
  11253.            TMDR1H 68                       RET 63
  11254.            TMDR1L 68                       RETI 63
  11255.            TRDR 68                         RETN 63
  11256.            TSR0 68                         RL 63
  11257.            TSR1 68                         RLA 63
  11258.        Z80 Instructions 50                 RLC 63
  11259.            ADC 51                          RLCA 63
  11260.            ADD 51                          RLD 63
  11261.            AND 51                          RR 63,64
  11262.            BIT 52,53                       RRA 64
  11263.            CALL 53                         RRC 64
  11264.            CCF 53                          RRCA 64
  11265.            CP 53,54                        RRD 64
  11266.            CPD 54                          RST 64
  11267.            CPDR 54                         SBC 64
  11268.            CPI 54                          SCF 64
  11269.            CPIR 54                         SET 64,65,66
  11270.            CPL 54                          SLA 66
  11271.            DAA 54                          SLP 66
  11272.            DEC 54                          SRA 66
  11273.            DI 54                           SRL 67
  11274.            DJNZ 54                         SUB 67
  11275.            EI 54                           TST 67
  11276.            EX 55                           TSTIO 67
  11277.            EXX 55                          XOR 67
  11278.            HALT 55                     Z80 pseudo ops
  11279.            IM 55                           IRP 47
  11280.            IN 55                           IRPC 47
  11281.            IN0 55                      ZAS directives 48
  11282.  
  11283.  
  11284.  
  11285.  
  11286.  
  11287.  
  11288.    Page 170                             HI-TECH C USER'S MANUAL
  11289.  
  11290.        title 48                        operators 38
  11291.    ZAS options                         program sections 39
  11292.        -J 35                           PSECT 43
  11293.        -L 36                           psects 39,43
  11294.        -N 35                           pseudo ops 40
  11295.        -O 36                           relocatable object  code
  11296.        -U 35                           39
  11297.        -W 36                           temporary labels 37
  11298.    ZAS psect flags                     Z180 35
  11299.        ABS 43                          Zilog 35
  11300.        GLOBAL 43                   _exit() 115
  11301.        LOCAL 43                    _getargs() 127
  11302.        OVRLD 43
  11303.        PURE 43
  11304.    ZAS pseudo ops 40
  11305.        COND 42
  11306.        DB 40
  11307.        DEFB 40
  11308.        DEFF 41
  11309.        DEFL 41
  11310.        DEFM 42
  11311.        DEFS 41
  11312.        DEFW 41
  11313.        ELSE 42
  11314.        END 42
  11315.        ENDC 42
  11316.        ENDM 44
  11317.        EQU 41
  11318.        GLOBAL 43
  11319.        IF 42
  11320.        LOCAL 45
  11321.        MACRO 44
  11322.        ORG 44
  11323.        PSECT 43
  11324.        REPT 46
  11325.    ZAS
  11326.        64180 35
  11327.        arithmetic overflow 35
  11328.        binary constants 37
  11329.        character constants 38
  11330.        condition codes 48
  11331.        conditional assembly 42
  11332.        constants 37
  11333.        directives 48
  11334.        extended condition codes
  11335.        48
  11336.        external symbols 35
  11337.        floating point constants
  11338.        38
  11339.        hexadecimal constants 37
  11340.        jump optimization 35
  11341.        jumps 35
  11342.        labels 36
  11343.        listing 36
  11344.        macros 44
  11345.        mnemonics 35
  11346.        octal constants 37
  11347.        opcode constants 38
  11348.  
  11349.  
  11350.  
  11351.  
  11352.  
  11353.