DOCERR: Use of _far Keyword in Tiny Programs

Last reviewed: July 17, 1997
Article ID: Q66104
6.00 6.00a 6.00ax 7.00 | 1.00
MS-DOS                 | WINDOWS
kbprg kbdocerr

The information in this article applies to:

  • Microsoft C for MS-DOS, versions 6.0, 6.0a, and 6.0ax
  • Microsoft C/C++ for MS-DOS, version 7.0
  • Microsoft Visual C++ for Windows, version 1.0

SUMMARY

A tiny memory model program cannot have _far code. The following documentation, taken from online help in Microsoft C versions 6.0, 6.0a, 6.0ax, 7.0, and Visual C++ version 1.0, is incorrect because it is not possible to use the _far keyword with code addresses or static data addresses in a tiny program. It is also not possible to use the _huge keyword with static data addresses.

  • The tiny-model option creates a program with the .COM extension. The program contains a single segment for both code and data. Code and data combined are limited to 64K.

    Both code and data items are accessed with near addresses. You can override the defaults with the _far keyword for code and the _far or _huge keyword for data.

MORE INFORMATION

The _far keyword does override the near addresses correctly, but the linker will generate the following error message because a .COM file cannot have segment references:

   LINK : fatal error L1127: far segment references not allowed with
   /TINY

Selecting DOS COM from initial build options in PWB and not placing a /AT in the additional build options will also cause the above error.

You can use _far and _huge keywords to create pointers for use with dynamic memory or to set up pointers with absolute addresses, such as a pointer to video memory. This is because these pointers do not have segment values that depend on where the program is loaded in memory. An .EXE file contains a table of all segment references that are made by the program in its header. When the program is loaded, all segment values in the table are adjusted for the programs load location. Because .COM files do not have this header information, they cannot contain segment references.

No Microsoft graphics library routines can be used when generating .COM files because they are all compiled as far calls.


Additional reference words: 6.00 6.00a 6.00ax 7.00 1.00
KBCategory: kbprg kbdocerr
KBSubcategory: CLngIss
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.