Microsoft QuickC - Tool Kit - Microsoft Corporation PDF
Microsoft QuickC - Tool Kit - Microsoft Corporation PDF
Microsoft QuickC - Tool Kit - Microsoft Corporation PDF
QuickC
Tool Kit
MJcfOSOliF
n
Microsoft QuickC.
TOOL KIT
VERSION 2.0
Information in this document is subject to change without notice and does not represent
acommitment on the part of Microsoft Corporation. The software described in this docu-
ment is furnished under a Ucense agreement or nondisclosure agreement. The software
may be used or copied only in accordance with the terms of the agreement. It is against
the law to copy the software on any medium except as specifically allowed in the li-
cense or nondisclosure agreement. No part of this manual may be reproduced or
transmitted in any form or by any means, electronic or mechanical, including photocopy-
ing and recording, for any purpose without the express written permission of Microsoft.
Microsoft, MS, MS-DOS, QuickC, CodeView, and XENIX are registered trademarks of
Microsoft Corporation.
Introduction xix
Appendixes
Appendix A Exit Codes 201
Appendix B Working with QuickC Memory Models 205
Appendix C Hardware-Specific Utilities 221
Appendix D Error-Message Reference 225
Glossary 317
Index 323
Digitized by the Internet Archive
in 2010
http://www.archive.org/details/microsoftquickctOOmicr
Table of Contents
Introduction
Optimizing Programs 12
Checking Syntax 14
Defining Constants 15
LINK Options 24
Adding a Module 33
Deleting a Module 33
Replacing a Module 33
Description Blocks 40
Dependency Lines 40
Contents vn
Command Lines 41
Comments 42
Escape Character 43
Description-File Examples 43
The CC Macro 44
NMAKE
Invoking 45
NMAKE Options 46
Controlling Input 47
Controlling Execution 47
Controlling Output 48
Using Macros 51
Predefined Macros 53
Using Directives 59
Summary 62
via Microsoft QuickC Tool Kit
4.3.13 /GO, /G2 Options (Generate Instructions for 8086 or 80286 Processor) 84
4.3.21 /Lc,Lr (Compile for Real Mode), /Lp (Compile for Protected Mode) 93
Chapter 6 LIB hi
6.1 Invoking LIB 142
Pscudotargets 172
7.3.5
Appendixes
B.3. 3 Declaring Functions with the near and far Keywords 216
Glossary 317
Index 323
Fiqures XVI
Figure B.4 Memory Map for Large and Huge Memory Models 211
Tables XVII
Table B.l Addressing of Code and Data Declared with near and far 213
The QuickC® Tool Kit isa set of utility programs that you can use to
develop your own programs outside the QuickC integrated environment.
These tools include
into libraries
Why use the Tool Kit when you can perform many of these same opera-
tions within the QuickC environment? The main reason is flexibility. The
QuickC environment uses the same tools as the Tool Kit but provides
access to only the most commonly used options. When you use the utili-
ties from the Tool Kit, all their powerful and flexible options are avail-
able to you. You may find that it's easiest to use the integrated
environment during the early stages of program development, when
you're still tinkering with programs and you need to compile, run, and
debug programs fast. Then, when you're fine-tuning and maintaining
your code, use the tools from the Tool Kit for additional control and
flexibility.
XX Microsoft QuickC Tool Kit
Part 1 of the manual is a tutorial that illustrates the ways you'll use the QCL,
LINK, LIB, and NMAKE utilities for everyday programming work. Each chap-
ter describes the most common options of each utility.
Part 2 is a reference to the Tool Kit. Each chapter describes a tool in detail, show-
command line and describing all of the tool's options
ing the exact syntax of the
and Chapter 8 comprises a complete reference to HELPMAKE, the
their effects.
Microsoft Help-File-Creation Utility. Consult this chapter if you want to cus-
tomize your on-line help.
Appendixes of this manual list the exit codes returned by each tool, explain the
use of QuickC memory models, describe the MSHERC and FIXSHIFT utilities,
Following the appendixes is a glossary, which defines all the terms introduced in
this manual, as well as other C-specific terms you may find helpful.
NOTE Microsoft documentation uses tiie term "OS/2" to refer to tfie OS/2 systems—f^icrosoft
Operating System/2 (MS® OS/2) and IBM® OS/2. Similarly, the term "DOS" refers to both the MS-
DOS® and IBM Personal Computer DOS operating systems. The name of a specific operating sys-
tem is used when it is necessary to note features that are unique to that system.
Read the manual Cfor Yourself i( you're new to C programming and want
titled
Insert the disk titled "Learning the QuickC Environment" and type learn if
you want to learn how to use the QuickC integrated environment. The lesson
titled "Basic Skills" shows how to get on-line help for any command or option
within the environment or for any part of the C language or run-time library.
Introduction xxi
Examples Description
QCL A.C B.C C.OBJ This font is used for examples, user input,
program output, and error messages in text.
Color Graphics Adapter (CGA) The first time an acronym is used, it is often
spelled out.
::sr\
i
ill
TITTiTjr EAlf
i!ia--<.>
sleep cHeoirf'^
ages]
ARIAS
i..-^
-^^
.-,M«Ji Mmmm>^ Sm>m>^
designed to get you started with the QuickC tools. It does not cover
the tools in detail, but instead gives you a "quick start" on the op-
tions and procedures that you are most likely to need. If you are
new to QuickC, consult Part 1 to learn how to use the Tool Kit and
to become familiar with the most useful options of each tool. After
you've gained some experience with the tools, turn to Part 2, "Ref-
\ erence to QuickC Tools," for the "nuts and bolts" of each tool.
Part 1 with QCL and LINK, the fundamental tools you must
starts
use to create executable programs outside the QuickC environ-
ment. It goes on to the Library Manager (LIB), with which you can
create libraries of compiled code. The part concludes with
NMAKE, a program-maintenance utility that helps you automate
the process of rebuilding software.
i
CHAPTERS
Creating Executable
Programs
This chapter shows you how to create executable programs from QuickC
source files. The QuickC Tool Kit has two programs for this purpose:
QCL and LINK.
Although you can create executable programs within the QuickC environ-
ment, the QCL and LINK commands give you more power and flexi-
bility in this process. For example, QCL gives you greater control over
the QuickC preprocessor, allows you to generate special code for an
8087-family coprocessor or an 80286 processor, and allows you to re-
name output files.
This chapter introduces the basic concepts and the most common options
of the QCL and LINK commands. For a complete description of all the
QCL options, listed alphabetically, see Chapter 4, "QCL Command Ref-
erence," in Part 2, "Reference to QuickC Tools." For a complete explana-
tion of how LINK works, see Chapter 5, "LINK," also in Part 2.
editor and save it in a file. This file is known as a C "source file." You may enter
separate parts of the program in different source files and compile these
source
files separately.
Once you've saved your C source file(s), two steps are required to convert it to
an executable file:
1 . Compiling. During this step, the QuickC compiler converts the C source files
to object files. An object file contains binary code but is not yet in execut-
able form.
6 Microsoft QuickC Tool Kit
2. Linking. During this step, the linker takes the object files created during com-
pilation, combines them with standard libraries plus any other object files
and libraries you specify, and creates an executable file that can be run
under DOS.
A.C
c
B.C
Creating Executable Programs 7
You'll use the QCL command to perform both compiling and linking. On the
QCL command line, give the names of any C source files that you want to com-
pile, and the names of any additional object files or libraries that you want to
link. The compile/link procedure is described below and illustrated in Figure 1.1:
1. QCL compiles the source files you named, creating object files. All object
files created by QCL from source files have the extension .OBJ. They also
contain the name of the combined library needed to create the executable file.
2. QCL calls the linker and passes the object files created in the compiling step
plus any object files and libraries that you specified on the QCL com-
mand line.
3. The linker links the object files, the libraries named in the object files, and
libraries passed by QCL to create the executable file.
The items in italics are different pieces of input (described below) that you must
give on the QCL command line:
The options are QCL options, which control some aspect of the compiling or
linking process. They may appear anywhere on the command line and in
most cases affect any appear later on the command line. The most
files that
commonly used QCL options are described in the section titled "Controlling
Compiling and Linking with QCL Options." For complete information on
all QCL options, see Chapter 4, "QCL Command Reference."
The sourcefiles are the names of the C source files that you are compiHng.
Normally, these file names have .C extensions.
8 Microsoft QuickC Tool Kit
The objfiles are the names of additional object files that you want to link
with, QCL compiles the source files, then links the resulting object files with
objfiles. For example, given the command line
QCL compiles MAIN . C, creating the object file main OB J, . then passes
MAIN OBJ .AUX OBJ and . to the linker, which creates an executable file
named main.exe.
If you give a file name with any extension other than .C or .LIB, or with no
extension, QCL assumes you are giving it the name of an object file. For ex-
ample, in the command line
QCL OBJECTl 0BJECT2.0BJ
the QCL command assumes the .OBJ extension for object 1 and passes it
and 0BJECT2.0BJ to the hnker for processing.
The libraries are the names of libraries that you want to link with. These
names must have .LIB extensions.
Ordinarily, you don't need to give a library name unless your program calls
combined C
functions that are stored in libraries other than the standard
libraries (which you created during if you use
installation). For example,
libraries created by a company other than Microsoft, or if you have created a
private library of functions and your program calls functions in this library,
you must give the private-library name on the QCL command line. For ex-
ample, the command line
QCL MAIN.C GRAPHICS. LIB
tells QCL to compile MAIN . C, creating the object file main OBJ, then to .
pass MAIN OBJ . to the linker, which links main OBJ with functions in
.
The linkoptions are linker options, which control some aspect of the linking
process. Linker options are described in the section in this chapter titled
"Controlling the Linking Process."
If you're not sure that your program will fit in available memory, you can in-
dicate that certain parts of the program will become "overlays"; that is, they
will be stored on disk and read into memory — overlaid —only when needed.
To specify overlays, enclose the modules you want to overlay in parentheses
on the QCL command Une. For example,
QCL RESIDNT.C (ONCALL.C) MAIN.C
creates a program named RES IDNT EXE with an overlay module named
.
memory from disk. (See Section 5.6, "Using Overlays," for more information
about overlays and restrictions on their use.)
Creating Executable Programs 9
Extension Processing
.OBJ QCL assumes the file is an object file and passes to the it
linker.
Uppercase and lowercase letters In file names, any combination of uppercase and lowercase letters is legal. For
example, shuttle. C and Shuttle, c represent the same file.
Path names Any file name can include a path name. When a file name includes a path name,
QCL assumes the file to be in that path. You may supply either a full path name
or a partial path name. A full path name includes a drive name and one or more
directory names. A partial path name is the same as a full path name but omits
the drive name, which QCL assumes to be the current drive.
If no path name is given, QCL assumes that all source and object files given on
the command line are in the cuirent directory.
Examples
The command line
B OBJ. These object files are then Unked with the object files C OBJ, D OBJ,
. . .
and E MOD to form an executable file named A exe (since the base name of
. .
the first file on the command line is A). Note that the extension . OBJ is as-
This command line tells QCL to compile the file TEAPOT . C and to link the re-
sulting object file with \MSG\ERROR.OBJ and the library GRAPHICS .LIB.
QCL assumes the extension ,OBJ for the file \MSG\ERROR because none was
specified. It looks for the library in the \ graphics directory on drive C :
QCL options may begin with either a forward slash (/) or a dash (-). In this
manual, the slash is used.
Important Except as noted, QCL options are case sensitive, so you must use the exact combina-
tion of uppercase and lowercase letters shown in this manual.
Some QCL options require arguments. For example, you may be required to
number or a file name as part of a QCL option. For some options, you
give a
must put a space between the option and the argument; for others, you must
place the argument immediately after the option. The description of each option
gives its exact syntax.
The following sections list the most commonly used QCL options by type. See
Chapter 4, "QCL Command Reference," for a complete list of QCL options or
for more information about the effects of an option described in this chapter.
Help with QCL options If you need fast help with QCL options, enter the following command:
QCL /HELP
This command displays a list of commonly used QCL opUons with a brief de-
scription of each option. Unlike other QCL options, /HELP is not case sensitive;
you can type any combination of lowercase and uppercase letters.
To compile separate modules that you want to put in a library using the LIB
utility (described in Chapter 2 of this manual)
The example above compiles the C source files spell. C and THESRS.C,
creating the object files spell. OB J and the SRS .OBJ. No linking is per-
formed, so no executable file is created.
If you give a file-name argument following the /Gi option, the compiler writes
the change information for all the source files into that single MDT file. Do not
put spaces between the /Gi option and the file name.
Ifyou specify the /Gi option without a file name, the compiler creates an MDT
file foreach C source file that you give on the command line. Each MDT file
has the base name of the source file and the .MDT extension.
Generally, when you compile with /Gi, only the changed functions in each C
source file The entire file is recompiled only if a change affects
are recompiled.
the entire program.
See Section 4.3.15 in Part 2, "Reference to QuickC Tools," for details about in-
Example
QCL /GiASC.MDT alpha. c num.c
The example above compiles the changed portions of the files alpha c and .
num . c. It creates a single .MDT file named ASC MDT . into which it writes
change information for both source files.
12 Microsoft QuickC Tool Kit
Optimizing Programs
"Optimizing" a program is the process of making the program, or a part of the
program, as fast or as small as possible. The following QCL options can help
with this process:
Option Effect
/O, /Ot Tells the compiler to optimize the program for execution time over
code size. The compiler makes the executable file faster, but it does
not make the file size as small as possible.
/Ol Tells the compiler to optimize loops in your program. This option
makes the executable file run faster.
/Gs Turns off stack-checking routines in your program. This option re-
duces the size of the executable file, but it may cause important
stack-overflow errors to go undetected.
/Ox Tells the compiler to perform all possible optimizations. This op-
tion combines the effects of the /Ot, /Ol, and /Gs options.
/Od Tells the compiler not to optimize your program. This option
speeds compilation, although it may result in a slightly slower ex-
ecutable file.
You may combine the /O options on the command line, specifying more than
one letter following /O. For instance, /Olt optimizes loops and execution time.
If the letters conflict, QCL uses the last one in the list.
Option Effect
/Foobjfde Gives the name objfile to the object file. You may give more than
one /Fo option; each option applies to the next C source-file name
on the command line. For example,
QCL /FoOBJl SRCl .C SRC2 .C
compiles SRCl C, creating an object file named OB Jl
. . OBJ,
then compiles SRC2 C, creating an object file named
.
SRC2.0BJ.
Creating Executable Programs 13
fFeexefile Gives the name exefile to the executable file. If you give exefile
without an extension, QCL automatically appends the .EXE exten-
sion to the file name. If you give a complete path name with
exefile, QCL creates the executable file in that path. If you give a
path specification without a file name, the path specification must
end with a backslash (\) so that QCL can distinguish it from a
file name.
Object Same base names as the original C source files with extensions of
.OBJ. For example, if you compile a C source file named LEX.C,
QCL creates an object file named LEX. OB J.
Executable Same base name as the first file name on the command line plus an
extension of .EX^. For example,
nary identifiers and to display error messages if your programs use any other ex-
tended language features.
Compile with the /Za option if you plan to port your programs to environments
that don't recognize Microsoft extensions to the C language, or if you want to en-
sure that your programs are strictly compatible with the American National
Standards Institute (ANSI) definition of the C language. Microsoft extensions in-
clude the near, far, huge, cdecl, fortran, and pascal keywords, as well as
several usages of standard C constructs that are not defined in the ANSI stand-
ard. (See Section 4.3.30, "/Ze, /Za," in Part 2, for more information about these
extensions.)
14 Microsoft QuickC Too! Kit
Checking syntax
Checking Syntax
If you want to make sure that your program is free from syntax errors without
compiling and linking the program, compile it with the /Zs option. This option
tells the QCL command to display error messages if your program has syntax er-
rors. QCL doesn't create object or executable files.
lems that aren't serious enough to stop the compiling process. You can easily
identify a warning message because it begins with the word "warning" and has
"C4" as the first two characters in the error number.
The "warning leve;l" options, /w and /WO through /W3, allow you to suppress
warning messages for certain classes of problems. In general, the lower the warn-
ing level, the less strict the compiler is about flagging possible errors in your pro-
gram. You might want to use a lower warning level if you're intentionally using
the flexibility of C in some operations and you want to suppress warnings about
these operations.
Option Effect
AVI Tells the compiler to display most warning messages. (This is the
level of warnings you get by default.)
/W2 Tells the compiler to display all /Wl warnings plus warnings for
/W3 Tells the compiler to display all /W2 warnings plus warnings for
Appendix D lists all warning messages in order of error number. The description
of each message indicates the warning level that must be set in order for the mes-
sage to appear.
debugger:
Option Effect
/Zi Puts information needed for debugging into the program. Use /Zi if
you plan debug your program with the QuickC debugger or with
to
the Microsoft® CodeView® window-oriented debugger provided
with other Microsoft language products.
/Zd Puts limited symbolic information in the object file. Use /Zd if you
plan to debug your program with SYMDEB, the Microsoft Sym-
bolic Debug Utility, shipped with earlier versions of Microsoft
language products.
Defining Constants
The C preprocessor directive #define defines a name for a constant or for C pro-
gram text. Wherever the name appears in your program, the preprocessor substi-
tutes the text you've defined for that name.
16 Microsoft QuickC Tool Kit
You can use the /D option to define constants from the QQ. command line.
This option has the form
fDidentifier=string
or
fDidentifier=number
The identifier is the name you're defining; string or number is the text or
numeric value that is substituted for the name. The string must be in double quo-
tation marks if it includes spaces.
You can leave off the equal sign and the string or number. If you do, the identi-
defined and its value is set to 1. This approach is useful when you need to
fier is
define an identifier but do not care what its value is. For example, /DCREATE
defines an identifier named CREATE and sets it equal to 1.
If you've defined a number for identifier, you can "turn off the definition by
using the following form of the /D option:
fDidentifier=
When you compile with this form, the identifier is no longer defined within your
program and no value is substituted for it.
QCL allows you to define up to 15 constants using the /D option for each. You
may be able to define as many as 20, depending on the other options you
specify. (See the section in this chapter titled "Removing Predefined Identifiers"
for more information about the number of constants you are allowed to define.)
4tinc\ude filename
tells the QuickC preprocessor to insert the contents of filename in your source
program, beginning at the line where the directive appears. Include files pro-
vided with the Microsoft QuickC Compiler contain prototypes of standard C
library functions and the constants used by these functions. Iffilename is en-
closed in angle brackets (<>), the preprocessor looks for the file in the directo-
ries given by the INCLUDE environment variable. l( filename is enclosed in
("
quotation marks "), the preprocessor looks for the file first in the current
directory and then in the directories specified by the INCLUDE variable. (Enter
the SET command at the DOS prompt to see the INCLUDE variable and the
directories it specifies.)
Creating Executable Programs 17
Use the following options to override the usual search order without changing
the value of the INCLUDE variable:
Option Effect
/[directory Tells the compiler to search the given directory for include files
beforeit searches the directories given by the INCLUDE environ-
ment variable. You can give more than one /I option, each
specifying a directory. Directories are searched in the order in
which they appear on the command line.
Option Effect
/EP Writes preprocessed output to the standard output device but does
not insert #line directives.
Option Effect
If your programs will always run on machines with 80286 or 80386 processors,
or on machines with coprocessors, you can compile your programs with the fol-
lowing options to take advantage of the specific hardware configuration:
Option Effect
/G2 Uses the 80286/80386 instruction set for your program. You can-
not run the program on machines with 8088, 8086, or 80186
processors.
/FPi87 Handles math for floating-point types (float and double) by gener-
ating instructions for an 8087 or 80287 math coprocessor. This
reduces the size of your program; however, the program must be
run on a system with a coprocessor present.
The /G2 and /FPi87 options are the most commonly used options for hardware-
specific compilation, but others are available. See Sections 4.3.12 and 4.3.13 for
details.
Creating Executable Programs 19
segments the compiler allocates for its data and code. Ordinarily, you don't need
to choose the memory model explicitly if your program's code can fit into one
64K segment and your program's data can fit into one 64K segment. This
memory allocation, called the small memory model, is the default used by the
QCL command.
Ifyour program exceeds the default limit for code or data, you must use one of
the othermemory models. The following list summarizes the options for the
memory model:
Option Effect
/AS Small model: provides one 64K segment for data and one 64K seg-
ment for code. No one data item can exceed 64K. This is the most
efficient model for QuickC programs. QCL uses this option auto-
matically if you don't give a memory-model option, so you never
need to give this option explicitly.
/AM Medium model: provides one 64K segment for data and multiple
64K segments for code. No one data item can exceed 64K. This is
the most efficient model if your program exceeds the 64K default
limit for code.
/AC Compact model: provides multiple 64K segments for data and one
64K segment for code. No one data item can exceed 64K. This is
the most efficient model if your program exceeds the 64K default
limit for data.
/AL Large model: provides multiple 64K segments for data and for
code.No one data item can exceed 64K.
/AH Huge model: same as large model, except that individual data items
can be larger than 64K.
Although memory models give you additional flexibility in dealing with large
programs, you must use them with care to avoid problems in your programs.
of
See Section 4.3.1 or Appendix B if you need further information about the use
memory models.
20 Microsoft QuickC Tool Kit
Option Effect
See Sections 4.3.7, 4.3.9, and 4.3.10 for detailed information on these options
and on map files.
The /link option Another way of controlling the linking process is to use the /link option on the
QCL command line. The /link option allows you to specify LINK command op-
tions— not QCL options— without invoking the linker separately. On the QCL
command line, the /link option must follow the source and object files and all
QCL options. QCL passes directly to the linker the options that follow /link.
These options are described under "LINK Options" below and in Section 5.4,
Creating Executable Programs 21
Example
QCL /FPi87 /Fm SRCl.C SRC2 /link /INF
In the example, the /Fm and /FPi87 options apply to the QCL command and the
/INF option applies only to the linker. As a result of this command line, QCL
compiles SRCl.C to run on an 8087 or 80287 processor then passes
SRCl OBJ and SRC2 OB j to the linker. The /Fm option to QCL causes the
. .
linker to create a map file named SRCl .map. The /INF option, which applies
only to the linker and not to QCL, causes the linker to display information about
the linking process.
Option Effect
/Zl "Library" options. Tells the compiler not to put the name
of the appropriate combined library in the object file. Use
this option to compile modules that you want to put in a
library with the Lffi utiUty.
22 Microsoft QuickC Tool Kit
The QCL options shown in this chapter are those most commonly used with
QuickC programs. QCL supports a number of other options in addition to those
described so far. See Section 4.3 for descriptions of all the QCL options.
Then, in the second step, you would link the resulting object files, plus any addi-
tional object files or libraries, asshown below:
As illustrated in the second step, if you give only object files or libraries on the
QCL command line, the QCL command simply passes the object files and librar-
ies to the linker.
Instead of using the QCL command to link, you can invoke the linker directly by
entering the LINK command. The advantage to using LINK is that the linker
prompts you for any input it needs; you don't need to give all file names and op-
tions on the command line, although you may do so.
The remainder of this section explains how to use the LINK command to link ob-
ject files and libraries.
LINK
Creating Executable Programs 23
Ifyou don't give any other information on the command line, LINK prompts
you for input. The following list shows how to respond to each prompt:
Object Modules: The names of all object you want to link, sepa-
files that
Run File: The name of the executable file that you want to create.
If you press ENTER without typing a name, LINK uses the
base name of the first object file you gave plus the exten-
sion .EXE. This name is shown in brackets in the prompt.
List File: The name of the map file, which shows segments in your
program. If you press ENTER without typing a name,
LINK doesn't create a map file. If you enter a name
without an extension, LINK adds the .MAP extension
utomatically.
You can type LINK-command options as part of the response to any prompt.
See the next section, "LINK Options," for a list of commonly used options.
Input on the command line If you prefer, you can give all your input to LINK on the command line. The
LINK command line has the form shown below:
Commas must appear as shown above to separate the names of the different
files. You may type a semicolon to terminate the command line anywhere after
the list of object files. The semicolon tells LINK to use defaults for the remain-
ing files. LINK options may appear anywhere on the command line.
Input in a response file LINK allows you one other alternative for providing input. You can enter re-
sponses for all prompts in a file, then invoke LINK with the following command:
LINK @responsefile
Replace responsefile with the name of the file that contains your responses. The
responses should look the same as if you were typing them in response to
prompts. For example, type all object-file names on the first line, the executable-
file name on the second line, and the map-file name on the third line. Use a plus
sign at the end of a line to continue a response on the next line. Leave a blank
line in the file if you want LINK to use the default for a prompt. Place LINK op-
tions at the end of any response or place them on one or more separate lines.
LINK Options
LINK options allow you to control the operation of the linker. If you're using the
QCL command to link, give these options after the /link option on the command
line. If you're using the LINK command to link, these options may appear any-
where on the command line.
Not all LINK options are applicable to QuickC programs. Some options are use-
ful only for assembly-language programs. This section describes only the op-
tions that are useful for QuickC programs. See Chapter 5, "LINK," for a
complete list of options.
Case sensitivity LINK options are not case sensitive, so you can type any combination of upper-
case and lowercase letters for each option.
Abbreviations Because some LINK options have long names, LINK allows you to abbreviate
each name. The abbreviation must include enough continuous letters to distin-
guish the option from others. Letters that you may leave off are surrounded by
brackets in the following sections. In general, this manual refers to LINK op-
tions by their shortest possible abbreviations.
Creating Executable Programs 25
Numericalparameters Some LINK options take numbers as parameters. You may specify the numbers
in decimal, hexadecimal, or octal. As in C programs, hexadecimal numbers are
identified by the prefix Ox and octal numbers by the prefix 0.
Help witfj LINK options If you need quick help with LINK options, enter the following command:
LINK /help
Option Effect
Option Effect
Option Effect
Maintaining Software
Libraries witli LiB
The Microsoft Library Manager (LIB) lets you create and maintain
object-code libraries. You can use the library manager for several tasks:
are ready for linking. The structure of a library supports the mass storage of com-
mon procedures—procedures called by a variety of programs. Each library has
an index of its components. These components, called "modules," can be added,
deleted, changed, or copied. When you give the linker a library as input, the
linker efficiently scans the library and uses only the modules needed by the
program.
library, the compiler never needs to regenerate code for these routines. Librar-
ies that contain standard support routines are called "standard libraries."
To support your own work. If you have created routines that you find useful
for a variety of programs,you may want to put these routines in a hbrary.
That way, these routines do not need to be recoded or recompiled. You save
development time by using work you have already done.
The oldlibrary field gives the name of a library. Object-code libraries typically
have names that end with .LIB. You specify a library in this field whenever you
use LIB.
The options field specifies one or more LIB options. For most tasks, you won't
need use any of these options. The options are described in Chapter 6, "LIB,"
to
in Part 2, "Reference to QuickC Tools."
The commands field gives the commands that modify the contents of the library.
Commands are described below in "Modifying the Contents of a Library."
The listfile field specifies a file into which LIB puts a list of the library's con-
tents. The next section tells how to list the contents of a library.
The newlibrary field specifies a name for the modified library if the commands
you give change an existing library. See Section 6.1.1.5 for more information on
this field.
Maintaining Software Libraries witti LIB 31
You can use LIB to obtain a symbol listing for any object-code library. Listings
are useful because they give the exact names of modules and public symbols.
You may need a listing if you want to modify a library, as described in the next
section.
To list the contents of a library, you need to use only the oldlibrary field and the
listfile field. Use a semicolon (;) to terminate the command so that LIB does not
prompt you for additional input.
In the listfile field, name of the file in which you want the listing to be
give the
placed. If you enter name of a file that does not yet exist, LIB creates the file.
the
If you enter the name of a file that already exists, LIB replaces the current con-
tents of the file with the new listing.
For example, the following command line directs LIB to place a listing of the
contents of MYL IB. LIB into the file listing.txt:
LIB MYLIB, LISTING.TXT;
The listing file summarizes the contents of the entire library. Each listing file
contains two kinds of information in this order:
Modules, which are basic to the operation of LIB, are discussed in the next sec-
tion.For a more detailed description of listing files, see Section 6.1.1.4, "Cross-
Reference-Listing File," in Part 2, "Reference to QuickC Tools."
your own version of the routine. Or you may want to add a new routine to the
standard library, so that your routine is available along with the standard
routines.
LIB operations involve these two important items, besides the library file itself:
Item Description
The sections that follow refer to both of these items extensively. Just remember:
a module is stored in an object file when it is outside a library and becomes
simply a "module" when it is loaded into a library.
1 To add or replace an object module, first compile or assemble the new code.
If theprocedure you want to add is part of a program, then copy the source
code into its own file and compile or assemble it separately.
Note that in step 2 above, the command line does not use all the LIB fields. You
may, however, include a listfile if you want a file listing. You may also use the
newlibrary field to preserve old library contents. If you enter a newlibrary, LIB
places the updated library contents in newlibrary and leaves the contents of
oldlibrary unchanged. Otherwise, LIB updates the contents oi oldlibrary and
saves the old contents in the file oldlibrary. BAK.
You can use the library as input to the linker once the contents change. Any
routines you have added or replaced become part of the library and can be called
by your programs.
Maintaining Software Libraries with LIB 33
Adding a Module
To add an object file to a library, use the command
+file
in which file is the name of the object file you want to add as a module. You
may specify a complete path name for file if the object file is not in the current
directory. If the file-name extension is .OBJ, you can leave off the extension;
LIB assumes .OBJ extension by default. LIB adds the object module at the
the
end of the library. The library contains only the base name of the module
without the .OBJ extension.
For example, the following command line adds the module printout to
the library MYLIB LIB, by copying the contents of the object file
.
\SOURCE\PRINTOUT.OBJ:
LIB MYLIB +\SOURCE\PRINTOUT;
You can also add the entire contents of one library to another by specifying a
library name for file. Remember to enter a complete file name (including exten-
sion) because LIB assumes that files in the commands field have the .OBJ exten-
sion. For example, the following command line adds the complete contents of
the library SMALL. LIB to the library SUPER. LIB:
Deleting a Module
To delete an object module from a library, use the command
-module
in which module is the name of a module already stored in the library. For ex-
ample, the following command deletes the module deleteme from the library
BIGLIB.LIB:
LIB BIGLIB -DELETEME;
Replacing a Module
To replace an object module within a library, use the command
-+module
inwhich module is the name of a module that is currenUy stored in the library.
The old copy of module is deleted from the library. The current contents of
module.OB] are copied into the library. For example, to replace the QuickC
34 Microsoft QuickC Tool Kit
small-model library version of printfO with your own version, execute these
steps:
2. Make sure that the resulting object file is named printf OBJ and that .
PRINTF OBJ is located in the current directory. (If you look at a listing of
.
the library, you will see that the public symbol for the printf() function is
_printf().The name of the module, however, is printf(). If you have any
doubt about the exact name of an object module, get a listing of the library
before trying to modify the library.)
You can combine any number of operations in the commands field. Spaces be-
tween the commands are acceptable but not necessary. For example, the follow-
ing command line adds a new module, NEWFUN, replaces a current module,
OLDFUN, and deletes another current module, BYENOW:
LIB MYLIB +NEWFUN -+OLDFUN -BYENOW;
In the example above, the files NEWFUN OBJ and OLDFUN OBJ
. . serve as
input for the modules NEWFUN and OLDFUN, respectively.
in which module is the name of the module you wish to copy from the library.
The module is placed in the file module.OBJ.
For example, the following command line copies the printf() module from the
Microsoft QuickC small-model library, and places the contents of this module
into the object file printf. OB J:
LIB SLIBCE *PRINTF;
Maintaining Software Libraries witti LIB 35
You can move a module out of a library with the following command:
-* module
Moving a module is similar to copying a module, in that LIB copies the contents
of the module into a file named module.OBJ. The move command (-*),
however, causes LIB to delete the module from the library after copying it.
In the oldlibrary field, enter the name of a file that does not yet exist.
In the command field, use the add command {+file) to list entries for the new
library. (Technically, this step is not required; however, if you do not use the
add command, the library will be empty.)
For example, if the file newlib.lib does not yet exist, the following com-
mand line creates this file. The object files myproc, myfun, and print it
provide the input for the new library.
LIB NEWLIB +MYPROC +MYFUN +PRINTIT;
How to make LIB case sensitive, so that it treats Print and print as
two different module names.
How to use a response file to give input to LIB. Response files are useful for
giving unusually long command lines or for giving the same command line
repeatedly.
CHAPTER 3
Maintaining Programs
witli NHHAKE
This chapter describes what NMAKE does, defines the terms you need to
understand, and tells you how to use NMAKE to manage your QuickC
projects.
38 Microsoft QuickC Tool Kit
If you arc unfamiliar with NMAKE, this chapter will introduce its most
useful features. If you are an experienced MAKE user, you will find that
this new utility is different; in fact, you may need to change your existing
description files to make them
compatible. (See Section 7.5 for a sum-
mary of changes.) This tutorial chapter also serves as an introduction to
some of the new features.
object files needed to build the executable program. The description file also con-
tains the QCL commands that must be executed to build the program.
A sitnple description block All of these elements need not be present in every description file. For many ap-
plications, a description file consisting of a single description block is adequate.
The example below shows a description file with only one description block:
fies the "target" to be updated (program exe) and the "dependents" that
.
make up the target (program, obj , subl ob j). If any of the dependents has
.
The next section in this chapter, "Building a Simple Description File," shows
how to construct description files, such as the one above, that consist of a single
block.
Depending on the size of the project you are maintaining, your description file
may contain one or more description blocks. This section describes the com-
ponents of a description block and shows you how to build description files that
consist only of description blocks.
40 Microsoft QuickC Tool Kit
Description Blocl(s
Description blocks are the basic elements of description files. A description
block tells NMAKE how to update a target from a group of dependents. Every
description block consists of a dependency line, any number of command Unes,
and optional comments. Figure 3.1 shows the components of a description block.
j
Specifying dependents List the names of the dependent files on the same line as the target, but after the
colon. Separate the dependent names by one or more spaces. A target can have
any number of dependents. If the names of all the dependents do not fit on one
line, use a backslash (\) to end the line and continue the list on the next line. This
is NMAKE's standard method of line continuation.
Dependent names, like target names, may contain drive and path specifications.
If you do not include a drive or path specification, NMAKE looks for the de-
pendents in the current directory. For example:
The first example shows two dependents for mycprog exe. One of them is .
mycprog ob j, for which NMAKE searches the current directory. The other is
.
Searcii paf/js for dependents You can direct NMAKE to search for dependents in a sequence of other directo-
ries by adding a search path enclosed in braces. NMAKE uses the search path if
it cannot find the file in the current directory. Separate each pair of directories in
the path with a semicolon. The backslash at the end of the path is optional. Con-
sider the following:
This line lists two dependents for program.exe. The first, program, obj,
is assumed to be in the current directory. For tables ob j a search path is
. ,
specified. The search path causes NMAKE to look first in the current directory,
then in \me\cwork, and then in q:\src until it finds the file. If it cannot
find the file, all is not lost; it relies on its inference rules to build the file. (For
more information on inference rules, see "Using Inference Rules" in this chap-
ter; for a more detailed description, see Section 7.3.3.)
Command Lines
The command lines in a description block give the commands to be carried out if
a target out of date with respect to any of its dependents. Commands can be
is
the names of programs, batch files, or any DOS commands in short, any com- —
mand that can be issued on the DOS command line.
42 Microsoft QuickC Tool Kit
Rules for specifying commands Typically, NMAKE users put their commands on separate lines from the target
and its dependents, one command
per line. Each line must start with one or more
spaces or tab characters. you forget the space or tab, NMAKE assumes you
If
are specifying a dependency line (or a macro) and gives an error. You may find
it helpful to use a tab to indent the hne, making it easy to identify the commands
that apply to each target. (This manual uses that convention.) For example:
The command line in the example invokes QCL to link the two dependent files
into a single executable image.
If you prefer, however, you can put your commands on the same line as the tar-
get and dependents. In that case, a semicolon must precede each command to
separate it from the previous item on the line, whether a dependent or another
command. The following has the same effect as the previous example:
If a command is too long to fit on one line, you can split it across two or more
lines with a backslash (\), in the same way you split a long dependency list.
that
For example:
Be sure that every line that is part of a command begins with a space or tab.
Comments
You may put comments in your makefiles just as you do in your C programs.
Every comment starts with a number sign (#) and extends to the end of the cur-
rent line. NMAKE ignores all the text between the number sign and the next
new-line character. Comments may appear anywhere in an NMAKE description
fileexcept on a command line. You may place comment lines among the com-
mand lines, but the number sign that starts the comment must be the first
character on the line with no spaces or tabs preceding it. The following example
shows the use of comments:
The first comment documents the purpose of the file. The second causes
NMAKE to treat the line program as a comment. When NMAKE executes
this description, it will rebuild program.exe but will not run it.
h
Escape Character
Some characters, such as the number sign (#), have a special meaning when they
appear in NMAKE description file. If you want NMAKE to interpret these
an
characters literally, and not with their special NMAKE meanings, you must use
the caret {^) as an "escape" character.
For example, the number sign (#) denotes the start of a comment. To use it in a
file name, you must precede it with a caret to "escape" its special meaning, as
follows:
winning''# txt .
^OS'^XO !@-
NMAKE ignores a caret that precedes any other character. In addition, carets
that appear within quotation marks are not treated as escape characters.
Description-File Examples
Assume you are developing a program named handle. Your directories are or-
ganized so that all your source files and object files are stored under the current
directory and your include files are in the \ inc directory. Consider the follow-
ing makefile:
handle
The dependency line says that handle exe should be updated if any of three
.
files change. Two of these files are object files; the third is an include file. If
NMAKE determines that it must create a new version of the target, it executes
the QCL command. QCL's /Fe option specifies the name handle exe . for
the executable program. NMAKE executes the new version of handle . exe
after creating it.
If the current directory contains only the files for handle exe, and none for
.
NMAKE expands the wild cards in the dependent names when it starts to build
the target.
44 Microsoft QuickC Tool Kit
The CC Macro
The sample description files presented so far have contained only description
blocks —no macros, directives, or inference rules. For the most part, you can get
along fine without any of these features.
Before you use NMAKE with QuickC, however, you need to know about one
particular macro, CC. The predefined macro CC tells NMAKE which C com-
piler to use when it tries to create .OBJ files from .C files. As you may be aware,
NMAKE is provided with both QuickC and the Microsoft C Optimizing Com-
For that reason, CC is predefined to invoke the C Optimizing Compiler,
piler.
CL. You must redefine CC to invoke QCL, the Microsoft QuickC Compiler.
Redefining CCin a mal(efile To redefine the CC macro, add the following at the top of your description file:
CC = qcl
No spaces or tabs may precede CC; it must be the first item on the line. The
spaces around the equal sign are optional.
Continuing with the example in the previous section, the description file would
look like the following:
CC = qcl
handle.exe *.obj \inc\comm.h
:
This description has the same effect as before but ensures that will use NMAKE
the QuickC compiler to generate the .OBJ files, if necessary, from any .C files in
the current directory. The QCL command in the example invokes QuickC to link
the object files into an executable file.
tings for various utility programs. You may already have a TOOLS.INI file; if
not, you can create one with any text editor.
Items that apply to NMAKE appear in the file following the tag [nmake]. To
change the definition of the CC macro, add a line that reads CC=qcl, as follows:
[nmake]
CC=qcl
Whenever you invoke NMAKE, the utility looks for TOOLS.INI first in the
current directory and then in the directory specified by the INIT environment
variable. To see what INIT is set to, type the SET command at DOS command
level.
Maintaining Programs with NMAKE 45
Invoking NMAKE
You can invoke NMAXE in either of two ways:
By giving the NMAKE command and all options, macros, and targets on the
DOS command line
By giving the NMAKE command and the name of a response file that con-
tains all the options, macros, and targets
Optional
The macrodefinitions give text to replace macro names in the description file.
"Using Macros," later in this chapter, introduces macros and explains how and
when to use them. See Section 7.3.2 for details.
The targets field lists one or more targets for NMAKE to build. If you do not
specify a target, NMAKE builds the first one in the file. You can find more infor-
mation on targets under "Description Blocks," above, and in Section 7.3.1.
Finally, the filename field gives the name of the description file that tells
NMAKE what to do. Like the others, this field is optional. Thus, the simplest
form of the NMAKE command is just
NMAKE
The default file MAKEFILE When you invoke NMAKE with the preceding command, it looks in the current
directory for a file named MAKEFILE to use as the description file. If no such
file exists, it displays an error message.
46 Microsoft QuickC Tool Kit
NMAKE looks first for a file named MAKEFILE in the current directory, as in
the previous example. If no such file exists, NMAKE treats the first argument on
the command line that is not an option, a target, or a macro definition as the
name of a description file. In the example above, NMAKE uses the description
file history, mak from the current directory.
A third way is to use the /F option, described below in the section "Controlling
Input."
NMAKE @responsefile
For responsefile, use the name of the file that contains the options, targets, and
macros you would otherwise type on the NMAKE command line.
NI\/IAKE Options
NMAKE provides a rich set of options that control the descriptions it reads as
input, the details of its execution, and the messages it displays on output. The
sections below describe some of the most useful NMAKE options. Chapter 7
covers all the options in detail.
Controlling Input
The /F option specifies the name of the description file. This option has the fol-
lowing form:
IF filename
Ifyou specify the /F option, NMAKE uses filename as the name of the descrip-
tionfile. The space separating /F and filename is required. In place of a file
name, you can enter a dash (-) to tell NMAKE to read the description from stand-
ard input, typically your keyboard.
If you omit the /F option, NMAKE looks for a file named MAKEFILE in the cur-
rent directory. If none exists, NMAKE will take a file name from the command
line as shown in the previous section.
NOTE Unless you use the IF option, NMAKE always searches for the file MAKEFILE in the cur-
rent directory. Therefore, you should explicitly specify /F to avoid unintentionally using MAKEFILE.
This command invokes the NMAKE utility and specifies hello .mak, in the
current directory, as the description file.
Controlling Execution
The following options change the way NMAKE interprets the description file:
Option Effect
Controlling Output
As NMAKE runs, it command that it executes.
displays on standard output each
It issues a diagnostic message if it command needed to
cannot find a file or
complete a description block or if any command returns an error. You can
change the type and number of messages that NMAKE returns by using the op-
tions below:
Option Effect
Options Examples
The following command invokes NMAKE with physics mak . as the descrip-
tion file:
The /N option tells NMAKE to read, but not to execute, any of the commands
within the file physics .mak. NMAKE checks the modification dates on the
files and displays the commands it would execute if the /N option were not pre-
sent. This option is useful for finding out ahead of time what files are out of date
so you can estimate how long a build might take. It can also be used in debug-
ging description files.
After using the /N option to check what NMAKE would do, you might invoke it
The /C option suppresses the NMAKE copyright message and any warning mes-
sages. The /S option suppresses the display of commands. You will, however,
still see the copyright messages for any commands that NMAKE invokes and
the output those commands generate.
Maintaining Programs with NMAKE 49
Using NMAKE 's advanced features, you can shorten your description files
files.
Inference rules
Directives
Figure 3.2 shows a more complicated description file than those presented so far.
# Inference Rules
. c ob j
. :
Inference rule
QCL /c $**
# Macro Definitions
The characters go in front of the command name and may be separated from the
name by one or more spaces, though they need not be. At
one space or tab
least
must precede the character on the line. To use two or three special characters
with a single command, put them one after the other on the command line. The
special characters are as follows:
Character Action
Dash (-) Turns off error checking for the command it precedes so
that NMAKE continues executing if an error occurs. A
dash followed by a number suspends error checking for
error levels at the number and below.
Note that the dash (-) has the same effect as the /I option. Also, the "at" sign ((§))
is similar to the /S option.
Examples
beatles.exe John. asm paul.c george.c ringo.c
:
In the example above, the dash preceding the QCL command means that
NMAKE will attempt to execute the MASM and LINK commands even if errors
occur during compilation.
The description in this example has the same effect as that in the previous ex-
ample, except that neither the QCL nor the LINK command will be displayed
when it is executed.
Maintaining Programs with NMAKE 51
Using Macros
One way to streamline your description files is to use macros. A macro is a name
that replaces other text in the description file in the same way that a macro de-
fined in a QuickC #define directive replaces other text in a program. Wherever
the name appears in the description file, NMAKE substitutes the text associated
with it. To change the meaning of the name, you simply change the text assigned
To replace all or part of a file name so that a single NMAKE description file
can be used to update more than one program.
NMAKE provides two types of macros: predefined macros and macros you de-
fine. This section shows how to use them.
No matter where you put them, macro definitions take the following form:
macroname = string
The macroname is the name you use in the description file. A macro name may
consist of any alphanumeric characters and the underscore (_) character. The
string is the text that replaces the macro name when the description file is
processed.
Macros on the command line On the NMAKE command line, white space may not appear on either side of the
equal sign because it causes DOS to treat the macro name and its definition as
separate tokens. In addition, if string contains any embedded white space, you
must enclose it in double quotation marks, as follows:
my macro="this string"
—
52 Microsoft QuickC Tool Kit
Alternatively, you may enclose the entire macro definition macroname and
string — in double quotation marks. In that case, spaces may surround the equal
sign because DOS treats all the characters within quotation marks as a single
token. Thus, the following is also acceptable:
Macros in the description file In a description file, define each macro on a new line. The definition must start
at thebeginning of the line with no preceding white space. ignores any NMAKE
white space surrounding the equal sign. Quotation marks are unnecessary as
well; if you use them, they will become part of the string.
pname = mycprog.exe
t = this
$(macroname)
Ifyou need to use a literal dollar sign in a description file, type it twice ($$) or
use the caret (^) escape character.
The lines below show how to refer to the macros defined in the previous ex-
ample. Note that if the name of a macro is only one character long, you can omit
the parentheses.
$ (pname)
$t
Once a macro is defined, the only way to remove its definition is to use the
lUNDEF directive. See "Using Directives," later in this chapter, for more
information.
Example
A common use of macros is to specify the options for a command. For example,
the following description block uses the macro copts to represent QCL
options.
Assuming the description file is named picture mak, . the command line
might be the following:
Note that the /P option causes QuickC to create a preprocessor listing, and the /C
option retains the comments from the source files in the preprocessor listing.
Predefined Macros
Some macros are predefined by NMAKE. You have already seen one of these,
CC. Some of the other predefined macros are described below. For a complete
list, see Section 7.3.2.3.
Macros Program Names (CC, AS, MAKE) The CC macro, already in-
for
troduced, represents the C compiler command that NMAKE executes to create
object files from C source files. The AS macro is similar. It stands for the name
of the assembler that NMAKE executes when it needs to create object files from
.ASM sources. Both of these macros are predefined by NMAKE. You can
change their definitions in the description file, in the TOOLS.INI file, or on the
NMAKE command line. Their default definitions are the following:
CC = cl
AS = masm
These two macros are primarily used in inference rules. (See "Using Inference
Rules" in this chapter, or Section 7.3.3, for information on inference rules.)
The MAKE macro is defined as the command you used to invoke NMAKE. Use
this macro, rather than the NMAKE
command itself, to invoke NMAKE
recur-
sively within a description file. Recursion is typically used in building large soft-
ware projects, such as compilers, and frequently involves the use of conditional
directives. An example of the recursive use of NMAKE
appears later in this
chapter in the section titled "Conditional Directives."
Macros for Target Names ($(g>, $*) The $@ macro represents the full
name of the target and the $* macro represents the base name of the target, that
is, the full name with the extension deleted. These two macros are typically used
in inference rules but, for the sake of discussion, this section will show their use
in description files.
Assume the file is invoked with the command line that follows:
NMAKE target=trees .exe
The command hne supplies text for the macro target, which sets the full
name of the target to trees exe. At execution time, NMAKE substitutes the
.
text for the macro as explained in the previous section. However, this file goes
one step further. Instead of repeating the user-defined $ t a rge t macro as ( )
the output of the LINK command, it uses the predefined macro $@ This macro .
stands for the full name of the target and therefore has the same meaning as
$ (target Thus, the LINK command links the object files into
) .
trees exe. In the last line of the file, the macro $* stands for the base name
.
NMAKE automatically substitutes for these macros. It picks up the target name
from its position on the dependency line in the description file. You cannot as-
sign a value to a predefined macro on the command line.
NMAKE provides additional predefined macros that you can use to specify tar-
get names. See Section 7.3.2.3 for details.
Macros for Dependent Names ($**, $?) These macros signify the names
of one or more dependents. The $** macro represents the complete list of de-
pendent files for the target. The $? macro represents only the dependents that are
out of date relative to the target. These two macros are commonly used with the
special characters that modify commands to prevent from doing any NMAKE
more work than necessary.
The example below shows the description file from the previous section using
macros for the dependent names:
The first line of the example defines all the dependents for the target. On the
next line, the LINK command links all the dependents, represented by $**, into
a single executable image. Finally, the target is run as a program.
NMAKE provides additional predefined macros that you can use to specify de-
pendent names. See Section 7.3.2.3 for details.
Figure 3.3 shows how macros defined on the command line take priority over
those in the description file.
. :
Ifyou supply a description block that does not contain any commands, or if the
dependents of your target do not exist, relies on inference rules. NMAKE
Whether predefined or user defined, inference rules are based on the file-name
extensions of the target and dependent files. In short, they tell how to NMAKE
create a file with a particular extension from a file with the same base name and
a different extension.
. c . exe :
QCL $*.c
This rule defines how to make a file with the .EXE extension from a file with the
same base name and the .C extension. The first line says that the rule tells how
to go from a file with the .C extension to a file with the .EXE extension. The sec-
ond line gives the command that creates the —
.EXE file in this case, the QCL
command. The macro $* represents the base name of the target with the exten-
sion deleted.
Note that an inference rule looks very similar to a description block, with two
exceptions:
If the preceding rule were in effect, NMAKE would use it for the following de-
scription block:
zfile.exe : zfile.c
NMAKE applies the inference rule for three reasons: first, the description block
does not contain any commands; second, the file-name extensions of the target
file and its dependent match those in the rule; and third, the base name of the tar-
get and dependent are the same. The combination of the inference rule and the
description above has the same effect as the following description block:
zfile.exe zfile.c :
QCL zfile.c
From. C to .OBJ One predefined rule builds .OBJ files from .C files, as follows:
. c ob j
.
When NMAKE applies this rule, it substitutes the current values of the macros
CC and CFLAGS for $(CC) and $(CFLAGS). (The CFLAGS macro lists op-
tions for the C compiler.) It then looks for a C source file with the same name as
the target and compiles the source file without linking. This is the rule NMAKE
uses for the examples in this chapter that list .OBJ files —not C source files —as
dependents.
With the description block below, NMAKE would use this inference rule if it
needed to create or update one or more of the .OBJ files listed in the dependency
list:
If the current directory contains .C source files with the same base names as the
.OBJ files in the example, NMAKE compiles them according to the inference
rule.
From .C to .EXE Another predefined rule, shown below, builds .EXE files from .C files:
. c .exe
$(CC) $ (CFLAGS) $*.c
menu.exe : menu.c
Note that the files funcs c and draw c are not shown here. NMAKE
. ,
would not create .EXE files for them because their base names are different from
that of the .EXE file that NMAKE is trying to create.
From. ASM to. OBJ The third predefined rule builds .OBJ files from .ASM files:
.asm. ob j
$(AS) $ (AFLAGS) $* ;
This rule tells NMAKE to look for an assembly-language source file with the
same name as the target file and to invoke the Macro Assembler to create an
object file. (The AFLAGS macro lists options for the assembler command.)
NMAKE would use this inference rule under the same conditions as the first
rule. For example:
If the current directory contains .ASM files with the same base names as any of
the .OBJ files, NMAKE uses this final inference rule.
j
.fromext.toext:
command
The first line defines the types of files to which the rule applies. The extension
of the "from" file is given first followed by the extension of the "to" file. The
second and subsequent lines give the commands that NMAKE
must execute to
create a file with the "to" file extension from a file that has the same base name
and the "from" file extension. You can specify one or more commands, just as in
a description block.
Specifying a path Sometimes you may want to associate a directory with each type of file. For in-
fer, foexf or. fromexf stance, some programmers organize all their source files in one directory and
their object files in another. NMAKE allows you to precede each of the exten-
sions with a path, as follows:
The example below shows a rule that starts with source files in one directory and
creates object files in a different directory:
You may specify only one path for each extension. If you need to pull source
filesfrom several different directories and place all the object files in one
directory, you must define a separate inference rule for each source directory.
1. Inference rules defined in the description file or in files included in the de-
scription file by the ! INCLUDE directive (described below under "Using
Directives")
Maintaining Programs with NMAKE 59
Using Directives
Directives provide additional control over the execution of commands beyond
what you can do with macros and inference rules. Using directives, you can
In effect, directives let you build description files that act like DOS batch files.
Such description files are especially useful for large software projects where the
work is divided among several people. A description file can compile each
source file, build any necessary libraries, and link the entire program. If errors
occur anywhere in the process, the description file can issue diagnostic mes-
sages, possibly take corrective action, or terminate execution.
Each directive begins on a new line in the description file. A directive starts with
an exclamation point (!) as the first character on the line. NMAKE allows, but
does not require, spaces between the name of the directive and the exclamation
point.
The sections that follow describe several of the NMAKE directives. For informa-
tion on all the directives, see Section 7.3.4.
The IINCLUDE directive in this example tells NMAKE to begin reading from
the file rules, mak in the current directory and to evaluate the contents of
rules mak . as part of the current description file.
If you enclose the file name in angle brackets (<>), NMAKE searches for the
file in the directories specified by the INCLUDE environment variable.
60 Microsoft QuickC Tool Kit
ITF expression
statements
!ELSE
statements
lENDIF
If thevalue of expression is nonzero (true), NMAKE executes the statements be-
tween the IIF directive and the lELSE directive. If the value of the constant ex-
pression is zero (false), NMAKE executes the statements between the lELSE
directive and the lENDIF directive.
Expressions The expression may consist of integer constants, string constants, or program in-
vocations that return constants. Integer constants can use the C unary operators
for numerical negation (-), logical negation (!), and one's complement arith-
metic (~); or the C binary operators, including arithmetic operators, bitwise oper-
ators, and logical operators. (See Section 7.3.4 for a complete Ust.) For string
constants, only the equality (==) and inequality (!=) operators are valid. You can
use parentheses to group expressions wherever necessary. Program invocations,
when used in conditionals, must be enclosed in square brackets.
Recursion Conditional directives are commonly used to test whether a program executed
successfully. The program can be a DOS command, a program you have written,
or even NMAKE itself. In the following description block, note the use of the
macro $(MAKE) to invoke the program recursively:
lENDIF
If the library pix.lib is built successfully, NMAKE executes the LINK and
COPY commands on the two lines immediately following the IIF directive.
Maintaining Programs with NMAKE 61
The description block below shows the use of IIFDEF and IIFNDEF directives:
lENDIF
Even though the second command line sets newlib to the null string,
newlib is still considered defined because its name appears to the left of the
equal sign.
The IIFNDEF directive acts in exactly the same way as IIFDEF, except that the
statements following it are executed only ifthe macro is not defined.
Once you have defined a macro, the only way to remove its definition is to use
the lUNDEF directive. You might want to remove a macro definition before in-
cluding another file, as in the following example:
lUNDEF opts
1INCLUDE newlib. mak
The lUNDEF directive ensures that the macro opt s is not defined when the
file newlib. mak is processed.
62 Microsoft QuickC Tool Kit
tion when fatal errors occur. For example, when NMAKE comes across the
conditional
it tests the value of the macro continue. If continue holds the string
"n", NMAKE
displays the text that follows the lERROR directive then stops ex-
ecution. If continue holds any other value, NMAKE executes the LINK
command that follows the lELSE directive.
Summary
This chapter has covered a subset of NMAKE
intended to get you started but not
features described m this
to turn you into an overnight expert. In addition to the
chapter, the NMAKE utility lets you
Create description files that build more than one target, and specify
the target
to build at invocation
As you become more familiar with NMAKE, and as your software projects
grow, you will probably need to use some of these features. See Chapter 7 for
more information.
PART 2
Reference
to QuickC Tools
PART2
Reference
to QuickC Tools
Part 2 of the QuickC Tool Kit is a reference to the tools. Here you
will find complete information on all the options of the utilities.
Refer to Part 2 when you have a specific question about one of the
tools or when you've gained experience with the utilities and need
to know more about them.
The QCL, LINK, LIB, and NMAKE utilities are covered in greater
detail in Part 2 than in Part 1. In particular, these chapters describe
additional options that work with programs written in other lan-
guages (such as Pascal, FORTRAN, and assembler) or with special
hardware.
^....^^^tm^^t^^^^^
/>^
CHAPTERS
5 LINK 109
6 LIB 141
7 NMAKE 155
8 HELPMAKE 177
CHAPTER 4 67
QCL Command
Reference
This chapter describes in detail the QCL command, which is used to com-
pile and link QuickC programs. It explains the rules for giving input on
the QCL command line, describes the options to QCL in alphabetical
order, and shows how to change the stack space allocated to a program.
The chapter provides reference material for programmers who are famil-
iar with the Microsoft QuickC Compiler in general and the QCL com-
mand in particular. If you are new to QuickC, see Chapter 1, "Creating
Executable Programs," in Part 1, "QuickC Tools Tutorial" for an intro-
ductory approach.
Entry Meaning
option One or more QCL options; see Section 4.3, "QCL Op-
tions," for descriptions.
file The names of one or more source files, object files, or li-
braries. At least one name is required. QCL compiles
file
Maximum command-line length You may specify any number of options, file names, and library names, as long
as the length of the command line does not exceed 128 characters.
Specifying file names In file names, any combination of uppercase and lowercase letters is legal. Any
file name can include a full or partial path name; if so, QCL assumes the file to
be A full path name includes a drive name and one or more
in that path.
directory names. A partial path name omits the drive name, which QCL assumes
to be the current drive. If no path name is given, QCL assumes the file is in the
current directory.
QCL determines how to process each file depending on its file-name extension,
as follows:
Extension Processing
.OBJ QCL assumes the file is an object fUe and passes it to the
linker.
Any other extension or QCL assumes the file is an object file and passes it to the
no extension linker.
1 . QCL compiles each source file, creating an object file for each. In each ob-
QCL places the name of the appropriate standard combined library.
ject file,
The memory model and floating-point-math package used to compile the pro-
gram determine this library name.
,
2. QCL invokes the linker, passing the object files it has created plus any object
files or libraries command line. The linker is invoked with the
given on the
options listed in the LINK environment variable. If you use /link to specify
linker options on the QCL command line, these options apply as well. If con-
flicts occur, options that follow /link override those in the LINK environment
variable.
3. The Unker links the object files and Ubraries passed by QCL to create a
single executable file.
Before it creates the executable file, the linker resolves "external references"
in the object files. An external reference is a function call in one object file
that refers to a function defined in another object file or in a library. To re-
solve an external reference, the linker searches the following locations in the
order shown for the called function:
a. The QCL
object files passed by
b. The libraries given on the QCL command line, if any
c. The libraries named in the object files
Example
Assume that you are compiling three C source files: MAIN C, MODI C, and . ,
MAIN C calls . the function named modi ( ) in MODI .C and the function
named mod2 ( ) in M0D2 . C.
In step 1, QCL compiles the C source files and creates the object files
MAIN OBJ, MODI OBJ,
. . and M0D2 OBJ.. It places the name of the standard
library SLIBCE.LIB in each object file.
70 Microsoft QuickC Tool Kit
In step 2, QCL passes these source files to the linker. In step 3, the linker re-
solves the external references as follows:
2. MOD 1 OBJ
. : resolves the references to printf and scanf using the defini-
tions in SLIBCE.LIB. The linker knows that this is the appropriate library be-
cause it finds the library name within MODI OBJ. .
3. M0D2 OB J
. : resolves the references to myline and mycircle using
the definitions in MYGRAPH.LIB.
Important QCL options (except for the /HELP option) are case sensitive. For example, IC and Ic
are fwo different options.
Command-lme order Options can appear anywhere on the QCL command line. With a few exceptions
(/c, /Fe), each QCL option applies to the files that follow it on the command line
and does not affect files preceding it on the command line. You can also define
QCL options in the CL environment variable; these options are used every time
QCL is invoked. (See Section 4.3.36, "Giving Options with the CL Environment
Variable.")
The remainder of this section describes all the QCL options in alphabetical
order. See Chapter "Creating Executable Programs," for descriptions of the
1,
various categories of QCL options and the more commonly used options belong-
ing to each category. If an option can take one or more arguments, its format is
shown under an "Option" heading before its description.
.
QCL
C .
Example
QCL FIRST. C SECOND. C /c THIRD. OBJ
This example compilesfirst ,c, creating the object file FIRST .OBJ, and
SECOND C, creating the object file SECOND OBJ. No processing is performed
. .
This option is valid only if the /E, /P, or /EP option is also used.
Example
QCL /P /C SAMPLE.
This example produces a listing named sample I. The listing file contains the .
original source file, including comments, with all preprocessor directives ex-
panded or replaced.
/Didentifier\[={string\number}]\
Use the /D option to define constants or macros for your source file.
The identifier is the name of the constant or macro. It may be defined as a string
or as a number. The string must be enclosed in quotes if it includes spaces.
If you leave out both the equal sign and the string or number, the identifier is as-
sumed to be defined, and its value is set to 1. For example, /DSET is sufficient
to define a macro named SET with a value of 1
The /D option is especially useful with the #if directive to conditionally compile
source files.
QCL Command Reference 73
Removing definitions If you have defined a numeric constant, giving the equal sign with no number re-
moves the definition of that constant from the source file. For example, to re-
move all occurrences of RELEASE, use the following option:
/DRELEASE=
Note that the identifier argument is case sensitive. For example, the /D option
above would have no effect on a constant named release that is defined in
the source file.
Defining macros and constants with the /D option has the same effect as using a
#derine preprocessor directive at the beginning of your source file. The identi-
fier is defined until either an #undef directive in the source file removes the defi-
nition or the compiler reaches the end of the file.
Duplicate definitions If an identifier defined in a /D option is also defined within the source file, QCL
uses the definition on the command line until it encounters the redefinition of the
identifier in the source file, as illustrated in Figure 4.1.
74 Microsoft QuickC Tool Kit
RELEASE undefined and perform heap checking to find bugs. Assuming the
program name is BIG C, you would compile with the following command:
.
QCL BIG.C
After you have found all of the bugs in the program, you can define release
in a /D option so that the program will run faster, as follows:
The /E option also places a #line directive at the beginning and end of each in-
cluded file and around lines removed by preprocessor directives that specify con-
ditional compilation.
This option isuseful when you want to resubmit the preprocessed listing for
compilation. The #Iine directives renumber the hues of the preprocessed file so
that errors generated during later stages of processing refer to the original source
file rather than to the preprocessed file.
Example
QCL /E /C ADD.C > PREADD.C
The command above creates a preprocessed file with inserted #line directives
from the source file add C. The output is redirected to the file preadd C.
. .
Preprocessed output is identical to the original source file except that all pre-
processor directives are carried out, macro expansions are performed, and com-
ments are removed. The /EP option is normally used with the /C option (see
Section 4.3.3), which preserves comments in the preprocessed output.
QCL Command Reference 75
The /EP option suppresses compilation; no object file or map file is produced,
even if you specify the /Fo or /Fm option on the QCL command line.
Examples
QCL /EP /C ADD.C
The command above creates a preprocessed file from the source file add C. It .
preserves comments but does not insert #Iine directives. The output appears on
the screen.
J
4.3 /F (Set Stack Size)
Option
/F number
The /F option sets the program stack size to number bytes, where number is a
hexadecimal number in the range 0001 to FFFF, If this option is not given, a
stack size of 2K is used.
You may want to increase the stack size if your program gets stack-overflow di-
agnostic messages. Conversely, your program uses the stack very little, you
if
may want to decrease the size of your program by reducing the stack size. In
general, if you modify the stack size, you should not use the /Gs option to
suppress stack checking.
fPblboundexe^
Ifyou have installed the Microsoft C Optimizing Compiler, Version 5.1 or later,
and have created protected-mode libraries, you can use the /Fb option to bind a
program after compiling and linking. The boundexe argument specifies a name
for the bound executable program. The name must follow the option immedi-
ately with no intervening spaces.
Binding permits the same executable file to run in both OS/2 protected mode
and DOS 3.x (real mode). See the Version 5.1 Update document for the
Microsoft C Optimizing Compiler for more information.
76 Microsoft QuickC Tool Kit
/Fcexefile
By default, QCL names the executable file with the base name of the first file
(source or object) on the command line plus the extension .EXE. The /Fe option
lets you give the executable file a different name or create it in a different
directory.
Because QCL creates only one executable file, you can give the /Fe option any-
where on the command line. If more than one /Fe option appears, QCL gives the
executable file the name specified in the last /Fe option on the command line.
The /Fe option applies only in the linking stage. If you specify the /c option to
suppress linking, /Fe has no effect.
Path names and extensions The exefile argument must appear immediately after the option with no interven-
ing spaces. The exefile argument can be a file specification, a drive name, or a
path specification. If exefile is a drive name or path specification, the QCL com-
mand creates the executable file in the given location, using the default name
(base name of the first file plus .EXE). A path specification must end with a
backslash (\) so that QCL can distinguish it from an ordinary file name.
You are free to supply any name and any extension you like for exefile. If you
give a file name without an extension, QCL automatically appends the .EXE
extension.
Examples
QCL /FeC:\BIN\PROCESS *.C
The example above compiles and links all source files with the extension .C in
the current directory. The resulting executable file is named PROCESS EXE .
The example above is similar to the first example except that the executable file,
instead of being named PROCESS EXE, is given the same base name as the
.
first file compiled. The executable file is created in the directory C \BIN. :
.
Option
/Fmlmapfile^
The /Fm option produces a map file. The map file contains a list of segments in
order of their appearance within the load module.
Path names and extensions The mapfile argument must follow the /Fm option immediately with no interven-
ing spaces. The mapfile can be a file specification, a drive name, or a path speci-
fication. It can also be omitted.
Ifyou give just a path specification as the mapfile argument, the path specifica-
tionmust end with a backslash (V) so that QCL can distinguish it from an ordi-
nary file name. For example, to create a map file in the path C \ LI ST, the :
If you do not specify a name for the map file or if you supply only a drive name
or path, QCL uses the base name of the first source or object file on the com-
mand line plus the extension .MAP.
Segntent information The information in the Start and Stop columns shows the 20-bit address
(in hexadecimal) of each segment, relative to the beginning of the load module.
The load module begins at location zero. The Length column gives the length
of the segment in bytes. The Name column gives the name of the segment, and
the Class column gives information about the segment type.
Group information The starting address and name of each group appear after the list of segments. A
sample group listing is shown below:
Origin Group
01EA:0 DGROUP
In this example, DGROUP is the name of the data group. DGROUP is used for
all near data (that is, all data not expUcitly or implicitly placed in their own data
segment) in Microsoft QuickC programs.
78 Microsoft QuickC Tool Kit
Global symbols The map file shown below contains two lists of global symbols: the first list is
Global symbols in a map file usually have one or more leading underscores be-
cause the QuickC compiler adds an underscore to the beginning of variable
names. Many of the global symbols that appear in the map file are symbols used
internally by the Microsoft QuickC Compiler and the standard libraries.
Address
QCL Command Reference 79
Program entry point Following the lists of symbols, the map file gives the program entry point, as
shown in the following example:
NOTE If you use the /Fm option with the /Gi option (for incremental compilation), QCL produces
a segmented-executable map file rather than a DOS executable map file. The segment addresses
in the file are different from those in DOS map files, and the file itself has a different format.
fFoobjfile
By default, QCL gives each object file it creates the base name of the corre-
sponding source file plus the extension .OBJ. The /Fo option lets you give dif-
The objfile argument must appear immediately after the option, with no inter-
vening spaces.
Each /Fo option applies only to the next source file on the command line.
Path names and extensions You are free to supply any name and any extension you like for the objfile.
However, recommended that you use the conventional .OBJ extension be-
it is
cause the linker and the LIB library manager use .OBJ as the default extension
when processing object files.
If you do not give a complete object-file name with the /Fo option (that is, if you
do not give an object-file name with a base and an extension), QCL names the
object file according to the following rules:
You can use this option to create the object file in another directory or on
another disk. When you give only a directory specification, the directory specifi-
cation must end with a backslash (\) so that QCL can distinguish between a
directory specification and a file name.
Examples
QCL /FoB:\OBJECT\ THIS.C
In the example above, the source file THIS C . is compiled; the resulting object
file is named THIS. OB J (by default). The directory specification
B:\OBJECT\ tells QCL to create THIS. OBJ in the directory named
\OBJECT on drive B.
QCL /Fo\OBJECT\ THIS.C THAT . C /Fo\SRC\NEWTHOSE OBJ THOSE. .
In the example above, the first /Fo option tells the compiler to create the object
file THIS. OB J (the result of compiling THIS.C) in the \ OBJECT
directory. The second /Fo option compiler to create the object
tells the file
The /FPi option generates in-line instructions for an 8087 or 80287 coprocessor
and places the name of the emulator library (wLIBCE.LIB) in the object file. At
link time, you can specify an 8087/80287 library (wLIBC7.LIB) instead. If you
do not choose a floating-point option, QCL uses the /FPi option by default.
Interrupt fix-ups This option works whether or not a coprocessor is present because the Microsoft
QuickC Compiler does not generate "true" in-line 8087/80287 instructions. In-
stead, it generates software interrupts to library code. The library code, in turn.
QCL Command Reference 81
fixesup the interrupts to use either the emulator or the coprocessor depending on
whether a coprocessor is present. The fix-ups can be removed by linking the file
RMFIXUP.OBJ with the C program.
Linking this file with QuickC programs can save execution time (the time re-
quired to fix up all first time). However, a C program linked
the interrupts the
with RMFIXUP.OBJ will run only if a coprocessor is present.
Ifyou use the /FPi87 option and link with mLIBC7.LIB, an 8087 or 80287 co-
processor must be present at run time; otherwise, the program fails and the fol-
lowing error message is displayed:
Ifyou compile with /FPi87 and link with mLIBCE.LIB, you can set the
N087 environment variable to suppress the use of the coprocessor (see Section
4.3.12.5).
Compiling with the /FPi87 option results in the smallest, fastest programs
possible for handhng floating-point arithmetic.
1 . Make sure the first object file passed to the linker has the name of the desired
library. For example, if you want to use an 8087/80287 library, give the
/FPi87 option before the first source-file name on the QCL command line; or
give the name of an object file compiled with /FPi87 as the first file name on
the command line. All floating-point calls in this object file refer to the
8087/80287 library.
82 Microsoft QuickC Tool Kit
2. Give the /NOD (no default-library search) option after the /link option on the
QCL command line. Then specify the name of the library you want to use on
the QCL command line. The /NOD option overrides the library names
embedded in the object files. Because the linker searches libraries given on
the command line before it searches libraries named in object files, all
floating-point calls will refer to the libraries you specify.
Removing library names Another complication might arise if you create your own libraries: normally,
each module in the library you create will contain a standard-library name, and
the linker will u-y to search the standard libraries named in the modules when it
The safest course, especially when you are distributing libraries to others, is to
use the /Zl option when you compile the object files that make up your libraries.
The /Zl option tells the compiler not to put library names in the object files.
Later, when you link other object files with your library, the standard library
used for linking will depend only on the floating-point and memory-model op-
tions used to compile those object files.
Examples
QCL CALC.C ANOTHER SUM
source file CALC C. with the default floating-point option, /FPi. The /FPi op-
tion generates in-line instructions and selects the small-model-emulator com-
bined library (SLIBCE.LIB), which is the default.
QCL /FPi87 CALC.C ANOTHER. OBJ SUM. OBJ /link SLIBCE.LIB /NOD
In the example above, CALC C . is compiled with the /FPi87 option, which
selects the SLIBC7.LIB library. The /link option, however, overrides the default
library specification: the /NOD option suppresses the search for the default
library, and the alternate math library (SLIBCE.LIB) is specified. The resulting
executable file, CALC exe, is linked with SLIBCE.LIB.
.
Examples
QCL /AM CALC.C ANOTHER SUM /link MLIBC7.LIB /NOD
The example above compiles the program CALC C with the medium-model op-
.
Coprocessor-suppression If N087 is set to any value when the program is executed, the program will use
message the emulator even if a coprocessor is present. When this occurs, the N087 set-
ting is displayed on the standard output as a message. The message is displayed
only a coprocessor is present and its use is suppressed; if no coprocessor is pre-
if
sent,no message appears. If you want to force use of the emulator, but don't
want a message to appear, set N087 equal to one or more spaces. The variable is
still considered to be defined.
Note that the presence or absence of the N087 definition determines whether
use of the coprocessor is suppressed. The actual value of the N087 setting is
used only for the message.
The N087 variable takes effect with any program linked with an emulator
library (mLIBCE.LIB). It has no effect on programs linked with 8087/80287
libraries (mLlBC7.LIB).
Examples
SET N087=Use of coprocessor suppressed
SET N081=space
The example above sets the N087 variable to the space character. Use of the co-
processor is still suppressed, but no message is displayed.
84 Microsoft QuickC Tool Kit
These options apply to all file names that follow on the command line until
another /GO or /G2 option appears.
Note that you may also specify /Gl, which allows 80186 instructions in in-line
assembly. The code generated with the /Gl option, however, is restricted to the
8086 instruction set. This option is of limited usefulness.
Parameter-passing con ven tions Because functionsin Microsoft QuickC programs can take a variable number of
arguments, QuickC must handle function calls differently from languages such
as Pascal and FORTRAN. Pascal and FORTRAN normally push actual param-
eters to a function in left-to-right order so that the last argument in the Hst is the
last one pushed on the because QuickC functions do not al-
stack. In contrast,
ways know the number of actual parameters, they must push their arguments
from right to left, so that the first argument in the list is the last one pushed.
Stack-cleanup con ventions Another difference between QuickC programs and FORTRAN or Pascal pro-
grams is that in QuickC programs, the calling function must remove the argu-
ments from the stack. In Pascal and FORTRAN programs, the called function
must remove the arguments. If the code for removing arguments is in the called
function (as in Pascal and FORTRAN), it appears only once; if it is in the calling
function (as in QuickC), it appears every time there is a function call. Because a
typical program has more function calls than functions, the Pascal/FORTRAN
method results in slightly smaller, more efficient programs.
The pascal and forlran keywords The Microsoft QuickC Compiler can generate the Pascal/FORTRAN calling con-
vention in one of several ways. The first is through the use of the pascal and
fortran keywords. When these keywords are applied to functions, or to pointers
to functions, they indicate a corresponding Pascal or FORTRAN function (or a
function that uses the Pascal/FORTRAN calling convention). Therefore, the cor-
rect calhng convention must be used. In the following example, sort is de-
clared as a function using the alternative calling convention:
The pascal and fortran keywords can be used interchangeably. Use them when
you want to use the left-to-right calling sequence for selected functions only.
The /Gc option The second method for generating the Pascal/FORTRAN calling convention is
to use the /Gc option. you use the /Gc option, the entire module is compiled
If
using the alternative calling convention. You might use this method to make it
;
When you use /Gc to compile a module, the compiler assumes that all functions
called from that module use the Pascal/FORTRAN calling convention, even if
the functions are defined outside that module. Therefore, using /Gc would nor-
mally mean that you cannot call or define functions that take variable numbers
of parameters and that you cannot call functions such as the QuickC library func-
tions that use the QuickC calling sequence. In addition, if you compile with the
/Gc option, either you must declare the main function in the source program
with the cdecl keyword, or you must change the start-up routine so that it uses
the correct naming and calling conventions when calling main.
The cdecl keyword The cdecl keyword in Microsoft QuickC is the "inverse" of the fortran and
pascal keywords. When applied to a function or function pointer, it indicates
that the associated function is to be called using the normal QuickC calling con-
vention. This allows you to write QuickC programs that take advantage of the
more Pascal/FORTRAN calling convention while still having access to
efficient
the entire QuickC library, other QuickC objects, and even user-defined functions
that accept variable-length argument lists. The cdecl keyword takes precedence
over the /Gc option.
For convenience, the cdecl keyword has already been applied to run-time-library
function declarations in the include files distributed with the QuickC compiler.
Therefore, your QuickC programs can call the library functions freely, no matter
which calling conventionsyou compile with. Just make sure to use the appro-
priate include file for each library function the program calls.
Naming conventions Use of the pascal and fortran keywords, or the /Gc option, also affects the
naming convention for the associated item (or, in the case of /Gc, all items): the
name is converted to uppercase letters, and the leading underscore that QuickC
normally prefixes is not added. The pascal and fortran keywords can be applied
to data items and pointers, as well as to functions; when applied to data items or
pointers, these keywords force the naming convention described above for that
item or pointer.
The pascal, fortran, and cdecl keywords, like the near, far, and huge key-
words, are disabled by use of the /Za option. If this option is given, these names
are treated as ordinary identifiers, rather than keywords.
Examples
int cdecl var_print (char*, . . . )
Option
/Gi^mdtname]\
When the /Gi option is given, QCL compiles only those functions in each C
source have changed since the last time Uie source file was compiled.
file that
The process of compiling only the changed functions in a source file is known as
"incremental compilation." Because the compiler does not need to handle the en-
tire source file, incremental compilation is considerably faster than regular com-
pilation. The object files created and the code generated when you compile
incrementally, however, may be larger.
If you specify any of the optimization (JOstring) options on the same line with
/Gi, the compiler ignores the /Gi option.
Module-description table (MDT) The compiler tracks changes for incremental compilation in a file known as a
"module-description table," or MDT. A single MDT can contain change informa-
tion for multiple source files. If mdtname is given, the compiler saves change in-
formation for source files in a single
all MDT named mdtname. If you do not
specify mdtname, the compiler creates one MDT for each source file named on
the command line. Each MDT
has the base name of the source file and the
.MDT extension.
The types of changes made to a source file determine whether the compiler can
incrementally compile a source file and whether the compiler creates or updates
the corresponding MDT.
Incrementally conpile, Except as noted below, if changes are confined to function bodies, the QCL com-
update MDT mand compiles only those changed functions and the "global regions" of the
source file. Global regions are the parts of the source file between the closing
88 Microsoft QuickC Tool Kit
curly brace (}) of one function and the opening curly brace ({) of the next func-
tion (see Figure 4,2). The compiler also updates the MDT to reflect the changes
to the source file.
QCL Command Reference 89
Compile whole program, The compiler must recompile an entire source file, but does not update its MDT,
don 't update MDT in any of these cases:
Using function prototypes For fastest compilation with /Gi, use a prototype for each function in your pro-
gram. A function prototype lists the name and type of the function and the name
and type of each of its parameters. (See "Declaring a Function's Parameters," in
Chapter 2 of Cfor Yourself for more information.) The C include files that
Microsoft supplies contain prototypes for all the functions in the C run-time
library. The information in the prototypes lets the compiler check the number
and type of arguments to the function.
Ifyou use the /Gi option and your program contains functions without corre-
sponding prototypes, the compiler issues the following level 3 warning message:
Compilation errors When the /Gi option given and errors occur during compilation, the compiler
is
Incremental linking When the compiler can perform incremental compilation, it invokes a special
form of the linker performs "incremental linking." Like incremental compil-
that
ing, incremental linking links only the object files that changed from the pre-
vious link. No library searches are performed; the assumption is that the libraries
are exactly the same as in the previous link. Incremental linking is considerably
faster than regular linking. If any of the changes to the program prevent QuickC
from performing an incremental link, it automatically performs a full Unk.
NOTE If with the /Fm option (which produces a map file), the map file is a
you use the /Gi option
segmented-executable map file rather than a DOS executable map file. The segment addresses in
the file are different from those in DOS map files, and the file itself has a different format.
90 Microsoft QuickC Tool Kit
Examples
Assume three C source files named MODl.c, M0D2.C, and M0D3.C for the
following examples.
The example above incrementally compiles and links the three C source files.
Three MDTs are created or updated: MOD 1 MDT, mod 2 mdt, and . .
M0D3 .MDT.
QCL /GiMYMDT.MDT MODl.C M0D2.C M0D3.C
The example above has the same effect as the preceding example, except that
the compiler creates or updates only one MDT named MYMDT .MDT. This MDT
includes all change-control information for the three C source files.
Stackprobes A "stack probe" is a short routine called on entry to a function to verify that the
program stack has enough room to allocate local variables required by the func-
tion. The stack-probe routine is called at every function-entry point. Ordinarily,
the stack-probe routine generates a stack-overflow message if the required stack
space is not available. When stack checking is turned off, the stack-probe routine
is not called, and stack overflow can occur without being diagnosed (that is, no
When to use the /Gs option Use the /Gs option when you want to turn off stack checking for an entire mod-
ule if you know program does not exceed the available stack space. For
that the
example, stack probes may not be needed for programs that make very few func-
tion calls or that have only modest local-variable requirements. In the absence of
the /Gs option, stack checking is on. The /Gs option should be used with great
care. Although it can make programs smaller and faster, it may mean that the
program will not be able to detect certain execution errors.
When to use Use the check_stack pragma when you want to turn stack checking on or off
the checkjstack pragma only for selected routines, leaving the default (as determined by the presence or
absence of the /Gs option) for the rest. When you want to turn off stack check-
ing, put the following line before the definition of the function you don't want to
check:
Note that the preceding line disables stack checking for all routines that follow it
Compiled with
Syntax /Gs Option? Action
NOTE For versions of Microsoft Quicl^C prior to 2. 0, tiie check_stack pragma had a different for-
mat: check_stack(+) to enable stack checking and check_stack(-) to disable stack checking. Al-
though the Microsoft QuickC Compiler still accepts this format, its use is discouraged because it
Example
QCL /Gs FILE.C
This example optimizes the file FILE.C by removing stack probes with the
/Gs option. If you want stack checking for only a few functions in FILE C, .
you can use the check_stack pragma before and after the definitions of func-
tions you want to check.
Option
/GtlnumberJ
The /Gt option causes all data items whose size is greater than or equal to
When number is specified, it must follow the /Gt option immediately with no in-
tervening spaces. When /Gt is specified without a number, the default thresh-
old value is 256. When the /Gt option is omitted, the default threshold value
is 32,767.
The option is particularly useful with programs that have more than 64K of ini-
tialized static and global data in small data items.
NOTE You can use the /Gt option only if you are creating a compact-, large-, or huge-model pro-
gram because small- and medium-model programs have only one data segment.
This option displays a list of the most commonly used compiler options. QCL
processes all information on the hne containing the /help option and displays the
command list.
Unlike all the other QCL options, /HELP is not case sensitive. Any combination
of uppercase and lowercase letters is acceptable. For example, /hELp is a valid
form of this option. The option has no abbreviation.
Option
fldirectory
You can add to of directories searched for include files by using the /I
the list
(for "include") option. This option causes thecompiler to search the directory
you specify before searching the directories given by the INCLUDE environ-
ment variable. That way, you can give a particular file special handling without
changing the compiler environment you normally use.
The space between /I and directory is optional. To search more than one
directory, you can give additional /I options on the QCL command line. The
directories are searched in order of their appearance on the command line.
QCL Command Reference 93
The directories are searched only until the specified include file is found. If the
file is not found in the given directories or the standard places, the compiler
prints an error message and stops processing. When this occurs, you must restart
compilation with a corrected directory specification.
Examples
QCL /I \INCLUDE / I\MY\ INCLUDE MAIN.C
In the example above, QCL looks for the include files requested by main , c in
the following order: first in the directory \ INCLUDE, then in the directory
\MY\ INCLUDE, and finally in the directory or directories assigned to the
INCLUDE environment variable.
QCL /X /I \ALT\INCLUDE MAIN.C
In theexample above, the compiler looks for include files only in the directory
\ALT\ INCLUDE. First the /X option tells QCL to consider the Ust of standard
places empty; then the /I option specifies one directory to be searched.
You can change unsigned with the /J option, causing the char
this default to
type to be zero-extended when widened
to int type. If a char value is explicitly
declared signed, however, the /J option does not affect it, and the value is sign-
extended when widened to int type. This option is useful when working with
character data that eventually will be translated into a language other than
English.
When you specify /J, the compiler automatically defines the identifier
_CHAR_UNSIGNED, which is used with #ifndef in the LIMITS .H include file to
define the range of the default char type.
4.3.21 /Lc, Lr (Compile for Real Mode), /Lp (Compile for Protected
Mode)
If you have installed the Microsoft C Optimizing Compiler, Version 5.1 or later,
and have created protected-mode libraries, you can use the A-p option to compile
programs for the OS/2 protected-mode environment.
94 Microsoft QuickC Tool Kit
If you compile with /Lp, you must make sure the linker uses the appropriate
protected-mode library. You can use either of the following methods:
Give the /NOD option to the linker so that it does not look for the standard
combined library and specify the protected-mode library explicitly. Using the
same example, you would compile and link using the following command
line:
This command line tells the linker not to link with SLIBCE.LIB and to link
with SLIBCEP.LIB instead.
The /Lc and /Lr options are synonymous. Both options compile the program for
OS/2 real mode or for the DOS environment. As with the /Lp option, if you com-
pile with /Lc or /Lr, you must make sure the linker uses the appropriate real-
mode library; either use /NOD to tell the linker not to search for the default
library, or rename the appropriate real-mode library so that it has the default
name.
The /NT option renames a text segment in a QuickC program. The textsegment
argument can be any combination of letters and digits. The space between /NT
and textsegment is optional.
QCL Command Reference 95
ing the program instructions and a data segment containing the program data.
The program's memory model determines how many text segments and how
many data segments the program has (see Sections B.2.1-B.2.5).
Every segment in every module has a name. The linker uses this name to define
the order in which the segments of the program appear in memory when loaded
for execution. (Note that the segments in the group named DGROUP are an
exception.)
The QuickC compiler normally creates text- and data-segment names. In small-
and compact-memory models, which have a single text segment, the text seg-
ment is named _TEXT. In medium, large, and huge models, which have multiple
text segments, the code for each module is placed in a separate segment named
moduleJYEXT where module is the base name of the module. In general, you
should not use the /NT option with the small and compact memory models.
Doing so may cause fixupp-overflow errors at link time.
The /NT option overrides the default text-segment name used by the QuickC
compiler (thus overriding the default loading order). This option gives the text
segment a new name in each module being compiled.
The /O options give you control over the optimizing procedures that the com-
piler performs. The string consists of one or more of the letters "d," "1," "t," and
"x." The list below shows how each of these affects optimization:
The letters can appear in any order. More than one /O option can be given; the
compiler uses the last one on the command line if any conflict arises. Each op-
tion applies to all source files that follow on the command line.
1
The /Od option is recommended when you compile with the /Zi option (de-
scribed in Section 4.3.31) to include debugging information. This is because the
/Od option does not reorganize code, thus making it easier to debug.
frequently used loop variables in registers. The /Ox option implicitly turns on the
/Ol option.
Wherever the compiler has a choice between producing smaller (but perhaps
slower) and larger (but perhaps faster) code, the compiler generates faster code.
For example, when the /Ot option is in effect, the compiler generates intrinsic
functions to perform shift operations on long operands.
fastest possible program. Its effect is the same as using the following options on
the same command line:
/Olt /Gs
That is, the /Ox option performs loop optimizations, favors execution time over
code size, and removes stack probes.
Example
QCL /Ol FILE.C
This command tells the compiler to perform loop optimizations when it com-
piles FILE C. The compiler favors program speed over program size because
.
Example
QCL /P MAIN.C
The example above creates the preprocessed file main , i from the source file
MAIN.C.
The /Tc option tells the QCL command that the given file is a C source file. The
space between /Tc and filename is optional.
If thisoption does not appear, QCL assumes that files with the extension .C are
C source files, files with the extension .LIB are libraries, and files with any other
extension or with no extension are object files. If you use the /Tc option, QCL
treats the given file as a C source file regardless of its extension, if any.
Ifyou need to specify more than one source file with an extension other than .C,
you must specify each source file in a separate /Tc option.
Example
QCL MAIN.C /Tc TEST.PRG /Tc COLLATE. PRO PRINT. PRG
In the example above, the QCL command compiles the three source files
MAIN.C, TEST.PRG, and COLLATE PRG. Because . the file print. PRG is
given without a /Tc option, QCL treats it as an object file. Therefore, after com-
piling the three source files, QCL links the object files MAIN OBJ, .
The /U (for "undefine") option turns off the definition of one of the names that
the QuickC compiler predefines. The /u option turns off the definitions of all pre-
defined names except for the name of the memory model. These options do not
apply to user-defined names.
These names are useful in writing portable programs. For instance, they can be
used with compiler directives to conditionally compile parts of a program, de-
pending on the processor and operating system being used. The predefined iden-
tifiers and their meanings are listed in Table 4.4.
One or more spaces may separate /U and name. You may specify more than one
AJ option on the same command line.
Limits on command-line The /U and /u options are useful if you need to give more than the maximum
definitions number of definitions (15 if the /Za or /J option is used, 14 if both options are
given, or 16 otherwise) on the command line or if you have other uses for the
predefined names. For each predefined name you remove, you can subsfitute a
definition of your own on the command line. When the definitions of all six pre-
defined names are removed, you can specify up to 23 command-line definitions.
Because MS-DOS limits the number of characters you can type on a command
line, however, the number of definitions you can specify in practice is probably
fewer than 23.
Example
QCL /UMSDOS /UM_I86 WORK.C
This example removes the definitions of two predefined names. Note that the fU
option must be given twice to do this.
You can suppress certain classes of warning messages produced by the compiler
by using the /w, /WO, AVI AV2, or /W3 option. Compiler warning messages are
,
Warnings indicate potential problems (rather than actual errors) with statements
that may not be compiled as you intend.
The AV options affect only source files given on the command line; they do not
apply to object files.
/WO,/w The /WO option turns off all warning messages. This option is useful when you
compile programs that deliberately include questionable statements. The /WO op-
tion applies to the remainder of the command line or until the next occurrence of
a /W option on the command line. The /w option has the same effect as the /WO
option.
C
/Wi The AVI option (the default) causes the compiler to display most warning
messages.
/W2 The /W2 option causes the compiler to display an intermediate level of warning
messages. Level-2 warnings may or may not indicate serious problems. They in-
clude warnings such as the following:
/W3 The AV3 option displays the highest level of warning messages, including warn-
ings about the use of non- ANSI features and extended keywords and about func-
tion calls that precede their function prototypes in the program.
Note that the descriptions of the warning messages in Appendix D indicate the
warning level that must be set (that is, the number for the appropriate AV option)
for the message to appear.
Example
QCL /W3 CRUNCH. C PRINT.
This example enables all possible warning messages when the source files
CRUNCH. C and PRINT. C are compiled.
You can prevent the QuickC compiler from searching the standard places for in-
clude files by using the /X (for "exclude") option. When QCL sees the /X op-
tion,does not search the current directory or any directories specified
it in the
INCLUDE environment variable.
This option is often used with the /I option to define the location of include files
that have the same names as include files found in other directories but that con-
tain different definitions. See Section 4.3.19 for an example of /X used with /I.
int *p;
((long *)p)++;
The preceding example could be rewritten to conform with the ANSI C stand-
ard as shown below:
(}
Use of trailing commas (,) rather than an ellipsis (,...) in function declarations
to indicate variable-length argument lists, as in the following example:
int printf(char * , )
Use of bit fields with base types other than unsigned int or signed int
The use of single-line comments, which are introduced with two slash
characters, as in the following example:
Use the /Za option if you plan to port your program to other environments. The
/Za option tells the compiler to treat extended keywords as simple identifiers and
disable the other extensions listed above.
When you specify /Za, the compiler automatically defines the identifier
NO_EXT_KEYS. In the include files provided with the Microsoft QuickC Com-
used with #ifndef to control use of the
piler run-time library, this identifier is
cdecl keyword on library function prototypes. For an example of this conditional
compilation, see the file STDIO.H.
102 Microsoft QuickC Tool Kit
The yZd option produces an object file containing hne-number records corre-
sponding to the line numbers of the source file. Use /Zd if you plan to debug
with the SYMDEB debugger. This option is also useful in cases where you want
to reduce the size of an executable file that you will be debugging with the
CodeView debugger, and you do not need to use the expression evaluator during
debugging.
Example
QCL /c /Zi TEST.C
This command produces an object file named TEST. OB J that contains line
numbers corresponding to the lines in TEST . C.
The /ZI option tells the compiler not to place the default-library name in the ob-
jectfile. As a result, the object file is slightly smaller.
The /ZI option is useful when you are using the LIB utility (described in Chap-
ters 2 and 6) a library. You can use /ZI to compile the object files you
to build
plan to put in your library, thereby omitting the default-library names from your
object modules. Although the /ZI option saves only a small amount of space for
a single object file, the total amount of space saved is significant in a library con-
taining many object modules.
Example
QCL ONE.C /ZI TWO.C
An object file named ONE OBJ . that contains the name of the C library
SLIBCE.LIB
/ZpK 11214}]]
When storage is allocated for structures, structure members are ordinarily stored
as follows:
Structures are word aligned; structures of odd size are padded to an even
number of bytes.
Use the /Zp option when you want to specify the same packing for all structures
in amodule. When you give the /Zpn option, where n is 1 2, or 4, each structure ,
member after the first is stored on /i-byte boundaries depending on the option
you choose. If you use the /Zp option without an argument, structure members
are packed on two-byte boundaries.
On some processors, the /Zp option may result in slower program execution be-
cause of the time required to unpack structure members when they are accessed.
For example, on an 8086 processor this option can reduce efficiency if members
with int or long type are packed in such a way that they begin on odd-byte
boundaries.
Table 4.5 shows the interaction of the /Zp option with the pack pragma.
Syntax
QCL Command Reference 105
Example
QCL /Zr prog.c
follow the option on the command line. This option provides a quick way to find
and correct syntax errors before you try to compile and link a source file.
When you give the /Zs option, the compiler does not generate code or produce
object object listings, or executable files. The compiler, however, does dis-
files,
Example
QCL /Zs TEST*.C
This command causes the compiler to perform a syntax check on all source files
in the currentworking directory that begin with TEST and end with the .C ex-
tension. The compiler displays messages for any errors found.
This variable is useful if you usually give a large number of files and options
when you compile. Ordinarily, the command line is limited to 128 characters.
The files and options that you define with the CL environment variable,
however, do not count toward this limit. Therefore, you can define the files and
options you use most often with the CL variable and then give only the files and
options you need for specific purposes on the command line.
106 Microsoft QuickC Tool Kit
SET CL=/FPi87
QCL Command Reference 107
In the example above, the CL environment variable tells the QCL command
to compile andlink the source files FILEI.C and FILE2 .C. The QCL
command
QCL FILEI.C FILE2.C FILE3.0BJ
would then have the same effect as the previous command line.
SET CL=/Za
QCL FILEI.C /Ze FILE2.C
The example above illustrates how to turn off the effects of a QCL option de-
fined in the environment. In this example, the CL environment variable is set to
the yZa option, which tells the compiler not to recognize Microsoft extensions to
the C language. This option causes Microsoft-specific keywords to be treated as
ordinary identifiers rather than reserved words. The QCL command specifies the
inverse option, /Ze, which tells the compiler to treat language extensions as re-
served words. Since the effect is the same as compiling with the command line
Programs compiled and linked under the Microsoft QuickC Compiler run with a
fixed stack size (the default size is 2048 bytes). The stack resides above static
data, and the heap uses whatever space is left above the stack. For some pro-
grams, however, a fixed-stack model may not be ideal; a model where the stack
and heap compete for space is more appropriate.
Linking with the mVARSTCK.OBJ object files gives you such a model: when
the heap runs out of memory, it tries to use available stack space until it runs into
the top of the stack. When the allocated space in the heap once
is freed, it is
again made available to the stack. Note that the stack cannot grow beyond the
last-allocated heap item in the stack or, if there are no heap items in the stack,
beyond the size it was given at link time. Furthermore, while the heap can em-
ploy unused stack space, the reverse is not true: the stack cannot employ unused
heap space.
108 Microsoft QuickC Tool Kit
You can change the model used heap space by linking your program
to allocate
with one of the mVARSTCK.OBJ object (where m is the first letter of the
files
library you choose). These files are the small-, medium-, compact-, and large-
model versions of a routine that allows the memory-allocation functions
(malice, calloc, _expand, fmalloc, nmalloc, and realloc) to allocate items in
unused stack space if they run out of other memory. (If you use the huge
memory model, link with the large-model object file LVARSTCK.OBJ.)
When you link your program with one of the mVARSTCK.OBJ files, do not
suppress stack checking with the #check_stack pragma, or with the /Gs or /Ox
option. Stack overflow can occur more easily in programs that link with the
variable-stack object files, possibly causing errors that would be difficult to
detect.
Example
QCL TEST.C SVARSTCK
Thiscommand line compiles TEST.C and then links the resulting object
module with SVARSTCK.OBJ, the variable-stack object file for small-model
programs.
.
CHAPTER 5
LINK
5.1 Overview
The Microsoft Overlay Linker (LINK) combines object files into a single
8086/8088, 80286, or 80386 machines. The format of input to the linker is the
Microsoft Relocatable Object-Module Format (OMF), which is based on the
Intel® 8086 OMF.
The output file from LINK (that is, the executable file) is not bound to specific
memory addresses. Thus, the operating system can load and execute this file at
any convenient address. LINK can produce executable files containing up to one
megabyte of code and data.
2. By responding to prompts.
Regardless of how you invoke LINK, you may press CTRL+C at any time to ter-
minate a LINK operation and exit to DOS.
You can use any combination of uppercase and lowercase letters for the file
names you specify on the LINK command line or give in response to the LINK
command prompts.
If you specify file names without extensions, LINK uses the following default
file-name extensions:
File Type
LINK 111
You may also specify one or more libraries in the objfiles field. To enter a
library in this field, make sure that you include the .LIB extension; otherwise,
LINK assumes the .OBJ extension. Libraries entered in this field are called "load
libraries" as opposed to "regular libraries." LINK automatically links in every
object module in a load library; it does not search for unresolved external refer-
ences first. The effect of entering a load library is exactly the same as if you had
entered the names of all the library's object modules in the objfiles field. This
feature is useful if you are developing software using many modules and wish to
avoid typing the name of each module on the LINK command line.
The mapfile field allows you to specify the name of the map file if you are creat-
ing one. To include public symbols and their addresses in the map file, specify
the /MAP option on the LINK command line.
Ifyou specify a map-file name without an extension, LINK automatically adds
an extension of .MAP. LINK creates the map file in the current working
directory unless you specify a path name for the map file.
5.2.1.5 Libraries
The libraries field allows you to specify the name of one or more libraries that
you want linked with the object file(s). When LINK finds the name of a library
in this field, it treats the library as a "regular library" and links in only those ob-
ject modules needed to resolve external references.
C
Each time you compile a source file for a high-level language, the compiler
places the name of one or more libraries in the object file that it creates; the
linker automatically searches for a library with this name (see Section 5.2.4).
Because of this, you do not need to give library names on the LINK command
line unless you want to search libraries other than the default libraries or search
for libraries in different locations.
When you link your program with a library, the linker pulls into your executable
fileany library modules that your program references. If the library modules
have external references to other library modules, your program is linked with
those other library modules as well.
You can also select default responses by using a semicolon (;). The semicolon
tells LINKto use the defaults for all remaining fields. Anything after the semi-
colon is ignored. If you do not give all file names on the command line or if you
do not end the command line with a semicolon, the Unker prompts you for the
files you omitted. See Section 5.2.2 for a description of these prompts.
The list below summarizes the linker's defaults for each field:
Field Default
exefile Creates afile with the base name of the first object file
mapfile Does not create a map file unless you include the mapfile
The field may be empty, as in the following com-
field.
mand line:
Ifyou include the field but not a file name, LINK creates
a map file with the base name of the executable file and
the .MAP extension. Thus the example creates a map file
named ourfile. map.
libraries Searches only the default libraries specified in the object
files.
;
LINK 113
Ifyou do not specify a drive or directory for a file, the linker assumes that the
on the current drive and directory. If you want the linker to create files in a
file is
location other than the current drive and directory, you must specify the new
drive and directory for each such file on the command line.
Examples
LINK SPELL+TEXT+DICT+THES, ,SPELLIST, XLIB.LIB
The command Une above causes LINK to load and link the object modules
SPELL. OBJ, TEXT. OBJ, DICT.OBJ, and THE s OBJ, and to search for .
LINK also produces a map file, SPELLIST map. Note that no semicolon is re-
.
LINK SPELL, ,
The LINK command line shown above produces a map file named spell MAP .
LINK spell, ;
LINK SPELL;
These two command lines do not produce a map file because commas do not ap-
pear as placeholders for the mapfile specification.
The command above causes LINK to link the three files MAIN OBJ, .
5.22 Prompts
If you want the linker to prompt you for input, start LINK by entering
LINK
at the DOS prompt. LINK also displays prompts if you type an incomplete com-
mand line that does not end with a semicolon or if a response file (see Section
5.2.3) is missing any required responses.
:
LINK prompts you for the input it needs by displaying the following lines, one
at a time. The items in square brackets are the defaults LINK applies if you press
ENTER in responseto the prompt. (You must supply at least one object-file name
for the "Object Modules" prompt.) LINK waits for you to respond to each
prompt before it displays the next one.
Note that the default for the Run File prompt is the base name of the first ob-
ject file with the .EXE extension.
The responses you giveto the LINK command prompts correspond to the fields
on the LINK command line as follows:
"Object Modules"
LINK 115
Defaults for prompts The following list shows the defaults for the other linker prompts:
Prompt Default
"Run File" The name of the first object file submitted for the "Ob-
ject Modules" prompt with the .EXE extension replacing
the .OBJ extension
"List File" The special file name NUL.MAP, which tells LINK not
to create a map file
"Libraries" The default libraries encoded in the object files (see Sec-
tion 5.2.4)
LINK treats the input from the response file just as if you had entered it in re-
sponse to prompts or on a command line. It treats any new-line character in the
response file as if you had pressed enter in response to a prompt or included a
comma in a command line. (This mechanism is illustrated in Figure 5.1.) For
compatibility with OS/2 versions of the linker, it is recommended that all linker
response files end with a semicolon after the last line.
LINK @RESPONSE
Libraries:
To use the linker with a response file, create the response file, then type the fol-
lowing command:
LINK @responsefile
Here responsefile specifies the name or path name of the response file for the
linker. You can also enter the name of a response file, preceded by an "at" sign
((a)), after any LINK command prompt or at any position in the LINK command
line; in this case, the response file completes the remaining input.
Options and You can use options and command characters in the response file in the same
command characters way as you would use them in responses you type at the keyboard. For example,
if you type a semicolon on the line of the response file corresponding to the
"Run File" prompt, LINK uses the default responses for the executable file and
for the remaining prompts.
Prompts When you enter the LINK command with a response file, each LINK prompt is
displayed on your screen with the corresponding response from your response
file. If the response file does not include a line with a file name, semicolon, or
carriage return for each prompt, LINK displays the appropriate prompt and waits
for you to enter a response. When you type an acceptable response, LINK
continues.
Example
Assume that the following response file is named spell LNK:.
SPELL+TEXT+DICT+THES
/PAUSE /MAP
SPELLIST
XLIB.LIB;
You can type the following command to run LINK and tell it to use the re-
sponses in SPELL LNK: .
LINK dSPELL.LNK
The response file tells LINK to load the four object files spell, text,
DiCT,and THES. LINK produces an executable file named spell.exe and
a map file named SPELLIST .map. The /PAUSE option tells LINK to pause
before it produces the executable file so that you can swap disks, if necessary.
The /MAP option tells LINK to include public symbols and addresses in the map
file. LINK also links any needed routines from the hbrary file XL IB LIB. The .
semicolon is included after the library name for compatibility with the OS/2 ver-
sion of the linker.
LINK 117
By an object module. The QuickC compiler writes the name of a default com-
bined library in each object module it creates.
NOTE The material in this section does not apply to libraries that LINK finds in the objfiles field,
either on the command line or in response to the "Object l^odules" prompt. Those libraries are
treated simply as a series of object files, and LINK does not conduct extensive searches in such
cases.
Library name If the library name includes a path specification, LINK searches only that
with path specification directory for the library. Libraries specified by object modules (that is, default
libraries) normally do not include a path specification.
Library natne If the library name does not include a path specification, LINK searches the fol-
without path specification lowing locations, in the order shown, to find the library file:
2. Any path specifications or drive names that you give on the command line or
type in response to the "Libraries" prompt in the order in which they appear
Because object files created by the Microsoft QuickC Compiler contain the
names of all the standard libraries you need, you are not required to specify a
library on the LINK command line or in response to the LINK "Libraries"
prompt unless you want to do one of the following:
For example, if you have developed your own customized Hbraries, you might
want to include one or more of them as additional libraries at linking time.
1
LINK automatically supplies the .LIB extension if you omit it from a library-file
name. If you want to link a library file that has a different extension, be sure to
specify the extension.
You assigned a "custom" name to a standard library when you set up your
libraries.
You want to link with a library that supports a different math package than
the math package you gave on the compiler command line (or the default).
If you specify a new library name on the LINK command line, the linker
searches the new library to resolve external references before it searches the
library specified in the object file.
Ifyou want the linker to ignore the library whose name is included in the object
file,you must use the /NOD option. This option tells LINK to ignore the default-
library information that is encoded in the object files created by high-level-
language compilers. Use this option with caution; for more information, see
Section 5.4.14, "Ignoring Default Libraries."
Example
LINK
LINK 119
This example links four object modules to create an executable file named
SPELL.EXE. LINK searches NEWLIBV3.LIB before searching the default
libraries to resolve references. To locate NEWLIBVS.LIB and the default
libraries, the linker searches the current working directory, then the
C:\TESTLIB\ directory, and finally the locations given by the LIB environ-
ment variable.
to serve as memory. This temporary file is handled in one of the following ways,
depending on the DOS version:
For the purpose of creating a temporary file, the linker uses the directory
specified by the TMP environment variable. If the TMP variable is set to
C \ TEMPO IR, for example, then LIISTK puts the temporary file in
:
C:\TEMPDIR.
If there is no TMP environment variable or if the directory specified by TIVIP
does not exist, then LINK puts the temporary file in the current directory.
If the linker is running on DOS Version 3.0 or later, it uses a DOS system
call to create a temporary file with a unique name in the temporary-file
directory.
When the linker creates a temporary disk file, you see the message
a name generated by DOS, and letter is the drive containing the temporary file.
Ifyou are running on a removable-disk system, the "Do not change diskette"
message appears. After this message appears, do not remove the disk from the
120 Microsoft QuickC Tool Kit
specified drive until the link session ends. If you remove the disk, the operation
of LINK is unpredictable, and you may see the following message:
If this happens, rerun the link session. The temporary file created by LINK is a
working file only. LINK deletes it at the end of the link session.
NOTE Do not give any of your own files tlie name WW. Tf^P. Tfie linl^er displays an error mes-
sage if it encounters an existing file witii this name.
When you use the LINK command line to invoke LINK, you may put options at
the end of the line or after individual fields on the line. Options, however, must
immediately precede the comma that separates each field from the next.
If you respond to the individual prompts for the LINK command, you may
specify linker options at the end of any response. When you use more than one
option, you can either group the options end of a single response or dis-
at the
tribute the options among several responses. Every option must begin with the
slash character (/) or a dash (-), even if other options precede it on the same line.
Abbreviations Because linker options are named according to their functions, some of their
names are quite long. You
can abbreviate the options to save space and effort.
Be sure that your abbreviation is unique so that the linker can determine which
option you want. The minimum legal abbreviation for each option is indicated in
the syntax description of the option.
Abbreviations must begin with the first letter of the name and must be continu-
ous through the last letter typed. No gaps or transpositions are allowed. Options
may be entered in uppercase or lowercase letters.
Numeric arguments Some linker options take numeric arguments. A numeric argument can be any of
the following:
LINK 121
LINK environment variable You can use the LINK environment variable to cause certain options to be used
each time you link. The linker checks the environment variable for options if the
variable exists.
The linker expects to find options listed in the variable exactly as you would
type them on the command does not accept any other arguments; for in-
line. It
stance, including file names in the environment variable causes the error mes-
sage unrecognized option name.
Each time you you can specify other options in addition to those in the
link,
LINK environment variable. If you enter the same option both on the command
line and in the environment variable, the linker ignores the redundant option. If
the options conflict, however, the command-Une option overrides the effect of
the environment variable option. For example, the command-line option
/ S E 5 1 2 cancels the effect of the environment- variable option / s E 2 5 6
: :
NOTE The only way to prevent an option in the environment variable from being used is to reset
Example
>SET LINK=/NOI /SE:256 /CO
>LINKTEST;
>LINK /NOD /CO PROG;
In the example above, the file TEST OBJ is linked with the options /NOI,
.
A
5 1 Running in Batch Mode (/BA)
Option
/BAITCHI
By default, the linkerprompts you for a new path name whenever it cannot find
a library that it It also prompts you if it cannot fmd an
has been directed to use.
object file that it expects to find on a removable disk. If you use the /B A option,
however, the linker does not prompt you for any libraries or object files that it
cannot find. Instead, the linker generates an error or warning message, if appro-
priate. In addition, when you use /B A, the linker does not display its copyright
banner, nor does it echo commands from response files. This option does not
122 Microsoft QuickC Tool Kit
prevent the linker from prompting for command-line arguments. You can pre-
vent such prompting only by using a semicolon on the command line or in a re-
sponse file.
Using this option may result in unresolved external references. It is intended pri-
marily for use with batch or NMAKE files that link many executable files with a
single command and to prevent linker operation from halting.
NOTE In earlier versions of LINK, the /BA TCH option was abbreviated to /B.
/BIINARYI
The /BI option is used to generate a .COM file instead of a .EXE file as the out-
put from the linker. The result you had linked a .EXE file, then
is the same as if
used the EXE2BIN command to convert it to a .COM file. (See The MS-DOS
Programmer' s Reference Manual for more information on .COM files and the
EXE2BIN command.)
When you use the /BI option, the linker by default produces an output file with
the .COM extension instead of .EXE. If you specify a file name with a different
extension, the linker applies the extension you specify. Note that the "Run File"
prompt shows the .EXE extension if you have not yet given the /BI option.
After you give the option, the linker issues a warning message that the extension
of the output file is .COM,
Files with the .COM extension may not perform load-time relocations and there-
fore may not include far-segment references. The linker issues an error if it de-
tects such references.
Object files linked with the /CO option must first be compiled with the /Zi op-
tion, which is described in Section 4.3,31.
You can run this executable file outside the CodeView debugger; the extra data
in the file are ignored. To keep file size to a minimum, however, use the special-
format-executable file only for debugging; then you can link a separate version
without the /CO option after the program is debugged.
The /CP option sets the maximum number of 16-byte paragraphs needed by the
program when it is loaded into memory. The operating system uses this value
when allocating space for the program before loading it. The option is useful
when you want to execute another program from within your program and you
need to reserve space for that other program.
LINK normally requests the operating system to set the maximum number of
paragraphs to 65,535. Since this represents more memory than could be availa-
ble under DOS, the operating system always denies the request and allocates the
largest contiguous block of memory it can find. If the /CP option is used, the
operating system allocates no more space than the option specifies. This means
any additional space in memory is free for other programs.
The number can be any integer value in the range 1 - 65,535. If number is less
than the minimum number of paragraphs needed by the program, LINK ignores
your request and sets the maximum value equal to whatever the minimum value
happens to be. The minimum number of paragraphs needed by a program is
never less than the number of paragraphs of code and data in the program. To
free more memory for programs compiled in the medium- and large-memory
models, link with /CP: 1; this leaves no space for the near heap.
/DOISSEG]]
The /DO option forces a special ordering on segments. This option is automati-
cally enabled by a special object-module record in Microsoft QuickC hbraries. If
you are linking to one of these libraries, then you do not need to specify this
option.
124 Microsoft QuickC Tool Kit
This optionis also enabled by assembly modules that use the Microsoft Macro
Assembler directive .DOSSEG.
When the A)0 option is in effect the linker initiaUzes two special variables as
follows:
The variables _edata and _end have special meanings C and for the Microsoft
FORTRAN compilers, so it is your own program
not wise to give these names to
variables. Assembly modules can reference these variables but should not
change them.
Option
/DS [[ALLOCATE]!
By default, LINK loads all data starting at the low end of the data segment. At
run time, the DS (data segment) register is set to the lowest possible address to
allow the entire data segment to be used.
Use the /DS option to tell LINK to load all data starting at the high end of the
data segment instead of at the low end. In this case, the DS register is set at run
time to the lowest data-segment address that contains program data.
The /DS option is typically used with the /HI option (see Section 5.4.10) to take
advantage of unused memory within the data segment.
Option
/EIXEPACKl
Executable files linked with this option may be smaller, and thus load faster,
than files linked without this option. Programs with many load-time relocations
(about 500 or more) and long streams of repeated characters are usually shorter
if packed. The /E option, however, does not always save a significant amount of
disk space and sometimes may increase file size. LINK notifies you if the
packed file is larger than the unpacked file.
Note you cannot use the QuickC debugger, the Symbolic Debug Utility
that
(SYMDEB), or the CodeView® window-oriented debugger to debug packed
files. The /EXEPACK option strips symbolic information needed by the debug-
gers from the input file and issues a warning message to notify you.
Option
/FIARCALLTRANSLATIONl
The /F option directs the linker to optimize far calls to procedures that lie in the
same segment as the caller. Using the /F option may result in slightly faster code
and smaller executable-file should be used with the /PAC option (see Sec-
size. It
When /F has been specified the linker optimizes code by removing the following
instruction:
push cs
call NEAR label
nop
Upon execution, the called procedure still returns with a far-return instruction.
Because both the code segment and the near address are on the stack, however,
the far return is executed correctly. The nop (no-op) instruction appears so that
exactly five bytes replace the five-byte far-call instruction; the linker may in
some cases place nop at the beginning of the sequence.
The /F option has no effect on programs that make only near calls. Of the high-
level Microsoft languages, only small- and compact-model C programs use near
calls.
NOTE There is a small risk involved w/f/i the If option: the linker may mistakenly translate a byte
in a code segment that happens to have the far-call opcode (9A hexadecimal). If a program linked
with /F inexplicably fails, then you may want to try linking with this option off Object modules pro-
duced by f^lcrosoft high-level languages, however, should be safe from this problem because rela-
In general, assembly-language programs are also relatively safe for use with the If option, as long
as they do not involve advanced system-level code, such as might be found in operating systems or
interrupt handlers.
The /HELP option causes LINK to display a list of its options on the screen.
This gives you a convenient reminder of the options.
When you use this option, LINK ignores any other input you give and does not
create an executable file.
LINK 127
A 10
5 Controlling Executable-File Loading (/HI)
Option
/HIIGHl
The /Hi option allows you to control where the executable file is placed in
memory. The executable file can be placed either as low or as high in memory as
possible. The /HI option tells LINK to place the executable file as high as
possible in memory. Without the /HI option, LINK places the executable file as
low as possible.
Option
/INFIORMATION]]
The /INF option tells the linker to display information about the Unking process,
including the phase of linking and the names of the object files being linked.
This option is useful if you want to determine the locations of the object files
Exampie
The following is a sample of the linker output when the /INF option is specified
on the LINK command line:
**** PASS ONE ****
HSTGM.OBJ(hstgm.c)
**** LIBRARY SEARCH ****
\qc\lib\SLIBCE.LIB{CRTO)
\qc\lib\SLIBCE.LIB (CRTODAT)
\qc\lib\SLIBCE.LIB (CRTOMSG)
\qc\lib\SLIBCE.LIB(CRTOFP)
\qc\lib\SLIBCE.LIB(CHKSTK)
\qc\lib\SLIBCE.LIB (CHKSUM)
128 Microsoft QuickC Tool Kit
Segments 31
Groups 1
Bytes in symbol table 32784
You can include the line numbers and associated addresses of your source pro-
gram in the map file by using the /LI option. This option is primarily useful if
you will be debugging with the SYMDEB debugger included with earlier re-
leases of Microsoft language products.
Ordinarily themap file does not contain line numbers. To produce a map file
with Une numbers, you must give LINK an object file (or files) with line-number
information. The /Zd option of the QCL command (see Section 4.3.31) directs
the compiler to include line numbers in the object file. If you give LINK an ob-
ject file without line-number information, the /LI option has no effect.
The /LI option forces LINK to create a map file even if you did not explicitly tell
the linker to create a map file. By default, the file is given the same base name as
the executable file plus the extension .MAP. You can override the default name
by specifying a new map file on the LINK command line or in response to the
"List File" prompt.
Option
/MIAPI
You can list all public (global) symbols defined in the object file(s) by using the
/M option. When you invoke LINK with the /M option, the map file contains a
listof all the symbols sorted by name and a list of all the symbols sorted by
address. If you do not use this option, the map file contains only a list of
segments.
LINK 129
When you use this option, the default for the mapfile field or "List File" prompt
response no longer NUL. Instead, the default is a name that combines the base
is
name of the executable file with a .MAP extension. You may still specify NUL
in the mapfile field (which indicates that no map file is to be generated); if you
do, the /M option has no effect.
NOTE In earlier versions of LINK, number specified themaximum number of public symbols
that LINK could sort; the current version of LINK sorts the maximum number of symbols that can be
sorted in available memory.
Option
/N0D[[EFAULTLIBRARYSEARCH]1 I'.filenamel
The /NOD option tells LINK not to search any library specified in the object file
to resolve external references. If you s^ocxiy filename, then LINK searches all
libraries specified in the object file except ioi filename.
Option
/NOEIXTDICTIONARY]
The /NOE option prevents the linker from searching the extended dictionary,
which is an internal list of symbol locations that the Unker maintains. Normally,
the linker consults this list tospeed up library searches. The effect of the /NOE
option is to slow down the linker. You often need this option when a library sym-
bol is redefined. Use /NOE if the linker issues the following error message:
Option
/NOFIARCALLTRANSLATION]
This option is normally not necessary because far-call optimization (translation)
is turned off by default. However, if an environment variable such as LINK
130 Microsoft QuickC Tool Kit
(or CL) turns on far-call translation automatically, you can use /NOF to turn far-
call translation off again.
Option
/NOGP^OUPASSOCIATION]
The /NOG option causes the linker to ignore group associations when assigning
addresses to data and code items. It is provided primarily for compatibility with
previous versions of the linker (Versions 2.02 and earlier) and early versions of
Microsoft language compilers.
/NOIIGNORECASEI
By default, LINK treats uppercase letters and lowercase letters as equivalent.
Thus ABC, abc, and Abe are considered the same name. When you use the
/NOI option, the linker distinguishes between uppercase letters and lowercase let-
ters, and considers ABC, abc, and Abc to be three separate names. Because
names in some high-level languages are not case sensitive, this option can have
minimal importance. In Microsoft QuickC, however, case is significant. If you
plan to link your files from other high-level languages with Microsoft QuickC
routines, you may need to use this option.
Option
/OrVERLAYINTERRUPTI mumper
By default,the interrupt number used for passing control to overlays is 63 (3F
hexadecimal). The /O option allows you to select a different interrupt number.
The number can be a decimal number from to 255, an octal number from octal
to octal 0377, or a hexadecimal number from hexadecimal to hexadecimal
FF. Numbers that conflict with DOS interrupts can be used; however, their use is
not advised.
In general,you should not use /O with programs. The exception to this guideline
would be a program that uses overlays and spawns another program that also
uses overlays. In this case, each program should use a separate overlay-interrupt
number, meaning that at least one of the programs should be compiled with /O.
/PACIKCODE]] I'.number^
The /PAC option affects code segments only in medium- and large-model pro-
grams. intended to be used with the /F option. It is not necessary to under-
It is
stand the details of the /PAC option in order to use it. You only need to know
that this option, used in conjunction with /F, produces slightly faster and more
compact code. The packing of code segments provides more opportunities for
far-call optimization, which is enabled with /F. The /PAC option is off by de-
fault and can always be turned off with the /NOP option.
The /PAC option directs the linker to group neighboring code segments. Seg-
ments in the same group are assigned the same segment address; offset addresses
are adjusted upward accordingly. In other words, all items have the correct physi-
cal address whether the /PAC option is used or not. However, /PAC changes seg-
ment and offset addresses so that all items in a group share the same segment
address.
The number field specifies the maximum size of groups formed by /PAC. The
linker stops adding segments to a group as soon as cannot add another segment
it
without exceeding number. At that point, the Unker starts forming a new group.
The default for number is 65,530.
132 Microsoft QuickC Tool Kit
You can safely use /PAC with programs developed with the Microsoft QuickC
Compiler. The /PAC option, however, should not be used with assembly pro-
grams that make assumptions about the relative order of code segments. For ex-
ample, the following assembly code attempts to calculate the distance between
CSEGl and CSEG2. This code would produce incorrect results when used with
/PAC because /PAC causes the two segments to share the same segment address.
Therefore, the procedure would always return 0.
CSEGl ENDS
codsize
LINK 133
NOTE Do not remove the disk that will receive the listing file or the disk used for the tempo-
rary file.
disk during processing, as described in Section 5.3, and display the follow-
file
ing message:
If the file is created on the disk you plan to swap, press CTRL+c to terminate the
LINK session. Rearrange your files so that the temporary file and the executable
file can be written to the same disk, then try linking again.
For each segment, the linker must allocate some space to keep track of segment
information. By using a relatively low segment Umit as a default (128), the
linker is able to link faster and allocate less storage space.
When you set the segment limit higher than 128, the Unker allocates additional
space for segment information. This option allows you to raise the segment limit
for programs with a large number of segments. For programs with fewer than
128 segments, you can keep the storage requirements of the linker at the lowest
level possible by setting number to reflect die actual number of segments in the
program. If the number of segments allocated is too high for the amount of
memory available to the linker, LINK issues the following error message:
If this occurs, relink the object files, specifying a lower segment limit.
Option
/STIACKJ: number
The /ST option allows you to specify the size of the stack for your program. The
number is any positive value (decimal, octal, or hexadecimal) up to 65,535
.
(decimal). It represents the size, in bytes, of the stack. If you do not use this op-
tion, the stack size is 2K.
Ifyour program returns a stack-overflow message, you may need to increase the
your program uses the stack very little, you may
size of the stack. In contrast, if
save some space by decreasing the stack size.
7. Performs fixups
Steps 5, 6, and 7 are performed concurrently: in other words, LINK moves back
and forth between these steps before it progresses to step 8.
The "executable image" contains the code and data that constitute the executable
file. The "relocation information" is a list of references, relative to the start of
the program. The references change when the executable image is loaded into
memory and an actual address for the entry point is assigned.
The following sections explain the process LINK uses to concatenate segments
and resolve references to items in memory.
When LINK encounters a segment, it checks the alignment type before copying
the segment to the executable file. If the alignment is WORD, PARA, or PAGE,
LINK checks the executable image byte copied ends on the ap-
to see if the last
propriate boundary. If not, LINK pads the image with null bytes.
already copied to the executable file (as described in the previous section). The
starting address consists of an offset and a "canonical frame number." The
canonical frame number specifies the address of the first paragraph in memory
that contains one or more bytes of the segment. (A paragraph is 16 bytes of
memory; therefore, to compute a physical location in memory, multiply the
frame number by 16 and add the offset.) The offset is the number of bytes from
the start of the paragraph to the first byte in the segment. For BYTE and WORD
alignments, the offset may be nonzero. The offset is always PARA and
zero for
PAGE alignments. (An offset of zero means that the physical location is an exact
multiple of 16.)
You can find the frame number for each segment in the map file created by
LINK. The first four digits of the segment's start address give the frame number
The /DOSSEG option may change the way in which segments are ordered. (See
Section 5.4.5.)
Ifa segment has combine type PUBLIC, LINK automatically combines it with
any other segments that have the same name and belong to the same class. When
LINK combines segments, it ensures that the segments are contiguous and that
136 Microsoft QuickC Tool Kit
alladdresses in the segments can be accessed using an offset from the same
frame address. The result is the same as if the segment were defined as a whole
in the source file.
LINK preserves each individual segment's alignment type. This means that even
though the segments belong to a single, large segment, the code and data in the
segments do not lose their original alignment. If the combined segments exceed
64K, LINK displays an error message.
If a segment has combine type STACK, LINK carries out the same combine
operation as for PUBLIC segments. The only exception is that STACK segments
cause LINK to copy an initial stack-pointer value to the executable file. This
stack-pointer value is the offset to the end of the first stack segment (or com-
bined stack segment) encountered.
A segment has combine type PRIVATE only if no explicit combine type is de-
fined for it in the source file. LINK does not combine private segments.
5.5.5 Groups
Groups allow segments to be addressed relative to the same frame address.
When LINK encounters a group, it adjusts all memory references to items in the
group so that they are relative to the same frame address.
Groups do not affect the order in which the segments are loaded. Unless you use
class names and enter object files in the right order, there is no guarantee that the
segments will be contiguous. In fact, LINK may place segments that do not
belong to the group in the same 64K of memory. LINK does not explicitly check
whether all the segments in a group fit within 64K of memory; however, LINK
is likely to encounter a fixup-overflow error if they do not.
5.5.6 Fixups
Once the linker knows the starting address of each segment in the program and
has established all segment combinations and groups, LINK can "fix up" any un-
resolved references to labels and variables. To fix up unresolved references,
LINK computes the appropriate offset and segment address and replaces the tem-
porary values generated by the assembler with the new values.
LINK 137
LINK carries out fixups for the types of references shown in Table 5.1.
The size of the value to be computed depends on the type of reference. If LINK
discovers an error in the anticipated size of a reference, it displays a fixup-
overflow message. This can happen, for example, if a program attempts to use a
16-bit offset to reach an instruction which is more than 64K away. It can also
occur if all segments in a group do not fit within a single 64K block of memory.
138 Microsoft QuickC Tool Kit
You specify overlays by enclosing them in parentheses in the list of object files
that you submit to the linker. Each module in parentheses represents one over-
lay. For example, you could give the following object-file list in the objfiles field
of the LINK command line:
In this example, the modules (b+c), (e+f), and (i) are overlays. The re-
maining modules, and any drawn from the run-time libraries, constitute the resi-
dent part (or root) of your program. Overlays are loaded into the same region of
memory, so only one can be resident at a time. Duplicate names in different over-
lays are not supported, so each module can appear only once in a program.
The linker replaces calls from the root to an overlay, and calls from an overlay to
another overlay, with an interrupt (followed by the module identifier and offset).
By default, the interrupt number is 63 (3F hexadecimal). You can use the
/OVERLAYINTERRUPT option of the LINK command to change the interrupt
number.
For example, assume that an executable program called payroll EXE uses .
overlays and does not exist in either the current directory or the directories
specified by PATH. If you run PAYROLL EXE (by entering a complete path .
specification), the overlay manager displays the following message when it at-
tempts to load overlay files:
You can then enter the drive or directory, or both, where PAYROLL EXE is . lo-
If you later remove the disk in drive B and the overlay manager needs to access
the overlay again, it does not find payroll EXE . and displays the following
message:
After reading the overlay file from the disk, the overlay manager displays the fol-
lowing message:
LIB
The Microsoft Library Manager (LIB) helps you create and maintain
object-code hbraries. An "object-code library" is a collection of sepa-
rately compiled or assembled object files combined into a single file.
Object-code libraries provide a convenient source of commonly used
routines. A program that calls library routines is linked with the library to
produce the executable file. Only the necessary routines, not all library
routines, are linked into the executable file.
Library files are usually identified by their .LIB extension, although other
extensions are allowed. In addition to accepfing DOS object files and
library files,LIB can read the contents of 286 XENIX® archives and
Intel-style libraries and combine their contents with DOS libraries.
You can use the LIB utility for the following tasks:
2. Respond to prompts.
The three sections below present the three methods of invoking LIB. Section
6.1.1 describes the input fields in detail and is relevant to all three methods.
To terminate the library session at any time and return to DOS, press ctrl+c.
The individual components of the command line are discussed in the sections
that follow.
Type a semicolon (;) after any field except the oldlibrary field to tell LIB to use
the default responses for the remaining fields. The semicolon should be the last
character on the command line.
Typing a semicolon after the oldlibrary field causes LIB to perform a con-
sistency check on the library —
no other action is performed. LIB displays any
consistency errors it finds and returns to the operating-system level.
Examples
LIB GRAPHIC;
The example above causes LIB to perform a consistency check of the library file
GRAPHIC. LIB.
LIB GRAPHIC , SYMBOLS. LST;
This example tells LIB to perform a consistency check of the library file
LIB 143
The example above uses the add-command symbol (+) to instruct LIB to add the
file STAR to the library GRAPHIC. LIB. The semicolon at the end of the com-
mand line causes LIB to use the default responses for the remaining fields. As a
result, no listing file is createdand the original library file is renamed
GRAPHIC . BAK. The modified library is GRAPHIC . LIB
LIB GRAPHIC -*JUNK *STAR, , SHOW
moved from the library in the process. The module STAR is copied from the
library to an object file called STAR OB j; the module remains in the library.
.
There is no default for the oldlibrary field. This field is required and LIB issues
an error message if you do not give a file name.
Consistency check If you type a library name and follow it immediately with a semicolon (;), LIB
only performs a consistency check on the given library. A consistency check
tells you whether all the modules in the library are in usable form. No changes
are made to the library. It usually is not necessary to perform consistency checks
because LIB automatically checks object files for consistency before adding
them to the library. LIB prints a message if it finds an invalid object module; no
message appears if all modules are intact.
Option
/IIGNORECASEI
The /I option tells LIB to ignore case when comparing symbols, which is the de-
fault. Use this option when you are combining a library that is case sensitive
(was created with the /NOI option) with others that are not case sensitive. The re-
sulting library will not be case sensitive. The /NOI option is described later in
this section.
Option
/NOEIXTDICTIONARYl
The /NOE option tells LIB not to generate an extended dictionary. The extended
dictionary is an extra part of the library that helps the linker process libraries
faster.
Use the /NOE option if you get either the error message insufficient
memory or no more virtual memory, or if the extended dictionary causes
problems with the linker. For more information on how the linker uses the ex-
tended dictionary, see Section 5.4.15.
Option
/NOIIGNORECASEI
The /NOI option tells LIB not to ignore case when comparing symbols; that is,
/NOI makes LIB case sensitive. By default, LIB ignores case. Using this option
allows symbols that are the same except for case, such as Spline and
SPLINE, to be put in the same library.
Option
/PAIGESIZE^: number
The /PA option specifies the library-page size of a new library or changes the
library-page size of an existing library. The number specifies the new page size.
Itmust be an integer value representing a power of 2 between the values 16
and 32,768.
A library's page size affects the alignment of modules stored in the library. Mod-
ules in the library are always aligned to start at a position that is a multiple of the
LIB 145
page from the beginning of the file. The default page size for a
size (in bytes)
new an existing library, the default is its current page size.
library is 16 bytes; for
Because of the indexing technique used by the LIB utility, a library with a large
page size can hold more modules than a library with a smaller page size. For
each module in the library, however, an average of number/2 bytes of storage
space is wasted. In most cases, a small page size is advantageous; you should
use a small page size unless you need to put a very large num.ber of modules in a
library.
Another consequence of the indexing technique is that the page size determines
the maximum possible size of the library file. Specifically, this Umit is number *
65,536. For example, / P A 1 6 means : that the library file must be smaller than
1 megabyte (16 * 65,536 bytes).
6.1.1.3 Commands
The commands field command symbols for manipulat-
allows you to specify the
command symbol followed immediately by a
ing modules. In this field, type a
module name or an object-file name. The command symbols are the following:
Symbol Action
Note that LIB does not process commands in left-to-right order; it uses its own
precedence rules for processing, as described in Section 6.2. You can specify
more than one operation in the commands field, in any order. LIB makes no
changes to oldlibrary if you leave this field blank.
side your current directory, supply a path specification. Note that the LIB utility
does not assume any defaults for this field on the command line. If you do not
specify a name for the file, the file is not created.
. :
Each symbol name is followed by the name of the module in which it is de-
fined. The example output below shows that the public symbol ADD is con-
tained in the module junk and the public symbols CALC, MAKE, and
ROLL are contained in the module dice:
ADD junk
CALC dice
MAKE dice
ROLL dice
If you leave this field blank, the original library is renamed with a .B AK exten-
sion and the modified library receives the original name.
6.1.2 Prompts
If you want to respond to individual prompts to give input start the LIB
to LIB,
utility at the DOS command level by typing LIB. The library manager prompts
you for the input it needs by displaying the following four messages, one at
a time:
Library name:
Operations
List file:
Output library:
LIB 147
LIB waits for you to respond to each prompt before printing the next prompt. If
you notice that you have entered an incorrect response to a previous prompt,
press CTRL+C to exit LIB and begin again.
The responses to the LIB command prompts correspond to fields on the LIB
command line (Section 6.1.1), as follows:
If the library you name does not exist, LIB displays the
following prompt:
"Output library' The newlibrary field. This prompt appears only if you
specify at least one operation at the "Operations" prompt.
Extending lines Ifyou have many operations to perform during a library session, use the amper-
sand symbol (&) to extend the operations line. Type the ampersand symbol after
the name of an object module or object file; do not put the ampersand between a
command symbol and a name.
The ampersand causes LIB to display the "Operations" prompt again, allowing
you to specify more operations.
Default responses Press ENTER to choose the default response for the current prompt. Type a semi-
colon (;) and press enter after any response except "Library name" to select de-
fault responses for all remaining prompts.
Prompt Default
The responsefile is the name of a response file. Specify a path name if the re-
sponse file is not in the current directory.
You can also enter @responsefile at any position on a command line or after any
of the prompts. The input from the response file is treated exactly as if it had
been entered on a command line or after the prompts. A new-line character in
the response file is treated the same as pressing the enter key in response to a
prompt.
A response file uses one text line for each prompt. Responses must appear in the
same order as the command prompts appear. Use command symbols in the re-
sponse file the same way you would use responses typed on the keyboard. You
can type an ampersand (&) at the end of the response to the "Operations"
prompt, for instance, and continue typing operations on the next line. This mech-
anism is illustrated in Figure 6.1.
LIB 149
When you run LIB with a response file, the prompts are displayed with the re-
sponses from the response file. If the response file does not contain responses for
all the prompts, LIB uses the default responses.
Example
GRAPHIC
+C IRCLE+WAVE-WAVE * FLASH
GRAPHIC. LST
contains the above Unes and you invoke LIB with the command shown below:
LIB deletes the module wave from the library GRAPHIC, lib, copies the
module FLASH into an object file named FLASH .OBJ, and appends the ob-
ject files CIRCLE. OB J and WAVE. OB J as the last two modules in the
library. LIB also creates a cross-reference-listing file named graphic lst. .
modules from a library, replacing a module in the library file, copying a module
to a separate object file, and moving a module out of a library and into an ob-
ject file.
For each library session, LIB reads and interprets commands in the order Usted
below. It determines whether a new library is being created or an existing library
is being examined or modified.
As the LIB utility carries out these commands, it reads the object modules in the
library, checks them for validity, and gathers the information necessary to build
a library index and a listing file. When you link a library with other object files,
the linker uses the library index to search the library.
LIB never makes changes to the original library; it copies the library and makes
changes to the copy. Therefore, if you press CTRL+C to terminate the session, you
do not lose your original library. Therefore, when you run LIB, make sure your
disk has enough space for both the original library file and the copy.
name of the new library file is the same as the name of an existing library
If the
LIB assumes that you want to change the existing file. If the name of the
file,
new library file is the same as the name of a file that is not a library, LIB issues
an error message.
When you give the name of a file that does not currently exist, LIB displays the
following prompt:
Type y to create the file, or n to terminate the library session. This message
does not appear if the name is followed immediately by a command, a comma,
or a semicolon.
You can specify a page size for the library by specifying the /PAGESIZE option
when you create the library (see Section 6.1.1.2). The default page size is 16
bytes.
Once you have given the name of the new library file, you can insert object mod-
ules into the library by using the add-command symbol (-»-).
LIB 151
LIB uses the base name of the object file as the name of the object module in the
library. For example, if the object file B \ CURSOR OBJ is added to a library
: .
Combining libraries You can also use the plus sign to combine two libraries. When you give a library
name following the plus sign, a copy of the contents of that library is added to
the library file being modified. You must include the .LIB extension when you
give a library-file name. Otherwise, LIB uses the default .OBJ extension when it
looks for the file. If both libraries contain a module with the same name, LIB ig-
nores the second module of that name. For information on replacing modules,
see Section 6.2.4.
LIB adds the modules of the library to the end of the library being changed. Note
that theadded library still exists as an independent library because LIB copies
the modules without deleting them.
In addition to allowingDOS libraries as input, LIB also accepts 286 XENIX ar-
chives and Intel-format libraries. Therefore, you can use LIB to convert libraries
from either of these formats to the DOS format.
Examples
LIB mainlib +flash;
This command adds the file flash.obj to the library mainlib. lib.
LIB math +trig.lib;
The command above adds the contents of the library trig, lib to the library
math. lib. The library trig, lib is unchanged after this command is
executed.
After the minus sign, give the name of the module to be deleted. Module names
do not have path names or extensions.
152 Microsoft QuickC Tool Kit
Example
LIB mainlib -flash;
The command shown above deletes the module flash from the library
mainlib . lib.
To replace a module, LIB first deletes the existing module, then appends an ob-
ject file that has the same name as the module. The object file is assumed to
have the .OBJ extension and to reside in the current directory; if not, give the
object-file name with an explicit extension or path.
Example
LIB mainlib -+flash;
Example
LIB mainlib *flash;
Thiscommand copies the module flash from the mainlib. lib library to
a called flash.obj in the current directory. Upon completion of this
file
Example
LIB mainlib -*flash;
Thiscommand moves the module flash from the mainlib, lib library to
a called f lash ob j in the current directory. Upon completion of this
file .
CHAPTER 7
NMAKE
The options field specifies options that modify the action of NMAKE. (Options
are not required.) They are described in Section 7.2.
The optional macrodefinitions field lists macro definitions for NMAKE to use.
Macros provide a convenient method for replacing a string of text in the descrip-
tion file. Macro definitions that contain spaces must be enclosed by quotation
marks. Macros are discussed in Section 7.3.2.
The optional target... field specifies the name of one or more targets to build. If
you do not list any targets, NMAKE builds the first target in the description file.
The optional ///ename field gives the name of the description file from which
NMAKE reads target- and dependent-file specifications and commands. A better
way of designating the description file is to use the /F option (described in Sec-
tion 7.2). By default, NMAKE looks for a file named MAKEFILE in the current
directory. If MAKEFILE does not exist, NMAKE uses the filename field: it inter-
prets the first su-ing on the command line that is not an option or macro defini-
name of the description file, provided its file-name extension isn't
tion as the
.SUFFIXES list. (See Section 7.3.5 for more information on the
listed in the
.SUFFIXES Ust.)
NOTE Unless you use the If option, NMAKE always searches for a file named MAKEFILE in the
current directory.
Example
NMAKE /S "program = flash" sort.exe search.exe
This example invokes NMAKE with the /S option, a macro assigning flash
toprogram, and two targets, sort.exe and search.exe. By default,
NMAKE uses the file named MAKEFILE as the description file.
NMAKE @responsefile
Here commandfile is the name of a file containing the same information that
would be specified on the command line: options, macro definitions, and targets.
The response file is not the same as the description file.
NMAKE 157
A response file is useful for invoking NMAKE with a long string of command-
line arguments, such as macro definitions, that might exceed the DOS limit of
128 characters. NMAKE treats line breaks that occur between arguments as
spaces. Macro definitions can span multiple lines by ending each line except the
lastwith a backslash (\). Macro definitions that contain spaces must be enclosed
by quotation marks, just as if they were entered directly on the command line.
Example
/S "program \
= flash" sort.exe search.exe
Assume a file named update contains the text above. The command below in-
vokes NMAKE with the description file MAKEFILE, the /S option, the macro
program = flash, and the targets sort exe and
definition .
search exe. Note that the backslash ending the Une allows the macro defini-
.
NMAKE @update
Option Action
Examples
NMAKE /f quick /c fl f2
The example above causes NMAKE to execute the commands in the description
file quick to update the targets fl and f 2. The /c option prevents NMAKE
from displaying nonfatal error messages and warnings.
NMAKE /D /N fl fl.mak
the description file. The /D option displays the modification date of each file and
the /N option displays the commands without executing them.
NMAKE reads a description file to determine what to do. The description file
may contain any number of description blocks, along with macros, inference
rules, and directives. These can be in any order.
When NMAKE runs, it builds the first target in the description file by default.
You can override this default by specifying on the command line the names of
j
NMAKE 159
the targets to build. The sections that follow describe the elements of a descrip-
tion file.
The target... field The target field specifies the name of one or more files to update. If you specify
more than one file, separate the file names by a space. The first target name must
start in the first column of the line; it may not be preceded by any tabs or spaces.
Note that the target need not be a file; it may be a pseudotarget, as described in
Section 7.3.5.
The dependent., field The dependent field lists one or more files on which the target depends. If you
specify more than one file, separate the file names by a space. You can specify
directories for NMAKE to search for the dependent files by using the following
form:
NMAKE searches the current directory first, then directory!, directory?, and so
on. If dependent cannot be found in any of these directories, NMAKE looks for
an inference rule to create the dependent in the current directory. See Section
7.3.3 for more information on inference rules.
In the following example, NMAKE first searches the current directory for
pass .obj, then the \src\alpha directory, and finally the d:\proj
directory:
The command field The command is used to update the target. This can be any command that can be
issued on the DOS command line. A semicolon must precede the command if it
is given on the same line as the target and dependent files. Commands may be
placed on separate lines following the dependency line, but each line must start
with at least one space or tab character. Blank lines may be intermixed with
commands. A long command may span several lines if each line ends with a
backslash (\). If no commands are specified, NMAKE looks for an inference rule
to build the target.
The comment field NMAKE considers any text between a number sign (#) and a new-line character
to be a comment and ignores it. You may place a comment on a line by itself or
at the end of any line except a command line. In the command section of the de-
scription file, comments must start in the first column.
Wild-card characters You can use the DOS wild-card characters (* and ?) when specifying target- and
dependent-file names. NMAKE expands wild cards in target names when it
reads the description file. It expands wild cards in the dependent names when it
builds the target. For example, the following description block compiles all
source files with the .C extension:
astro.exe :
QCL
Escape character You can use a caret (^) to escape any DOS or OS/2 file-name character in a de-
scription file, so that the character takes on its literalmeaning and does not have
any special significance to NMAKE. The following characters must be preceded
by an escape character for NMAKE to interpret them literally.
#()$^\{} 1@-
For example, NMAKE interprets the specification
big'^t c .
Using the caret, you can include a literal new-line character in a description
This capability
file. is primarily useful in macro definitions, as in the following
example:
XYZ = abc'^
def
NMAKE interprets this example as if you had assigned to the XYZ macro the C-
style string abc\ndef Note . that this effect differs from the use of the
backslash (\) to continue a line. A new-line character that follows a backslash is
replaced with a space.
: : :
NMAKE 161
NMAKE ignores a caret that is not followed by any of the characters mentioned
above, as in the following:
mno ^ : def
In this case, NMAKE ignores the caret and treats the line as
mno : def
Carets that appear within quotation marks are not treated as escape characters.
Character Action
Dash (-) Turns off error checking for the command. If the dash is
followed by a number, NMAKE halts only if the error
level retumed by the command is greater than the num-
ber. In the following example, if the program flash
retumed an error code NMAKE would not halt, but
would continue to execute commands:
light 1st light txt
. : .
@ECHO sorting
The output of the ECHO command, however, appears as
usual.
These two description blocks both update the library named target lib. If .
any of the assembly-language files have changed more recently than the library
file, NMAKE executes the commands in the first block to assemble the source
files and update the library. Similarly, if any of the C-language files have
changed, NMAKE executes the second group of commands, which compile the
C files and then update the library.
Ifyou use a single colon in the above example, NMAKE issues an error mes-
sage. It is legal, however, to use single colons if commands are listed in only one
target: jump.bas
target up .c:
commands
is equivalent to
target: jump.bas up .
commands
7.3.2 Macros
Macros provide a convenient way to replace a string in the description file with
another string. The text is automatically replaced each time NMAKE
is invoked.
This feature makes it easy to change text used throughout the description file
To create a standard description file for several projects. The macro repre-
sents the file names used in commands. These file names are then defined
when you run NMAKE. When you switch to a different project, changing the
macro changes the file NMAKE uses throughout the description file.
names
The macroname may be any combination of alphanumeric characters and the un-
derscore O
character. The string may be any valid string.
You can define macros on the NMAKE command line or in the description file.
Because of the way DOS parses command lines, the rules for the two methods
are shghtly different.
Defining macros In NMAKE description files, define each macro on a separate line. The first
in description files macro name must be the first character on the line. NMAKE ig-
character of the
nores spaces following macroname or preceding string. The string may be a null
stringand may contain embedded spaces. Do not enclose string in quotation
marks; NMAKE will consider them part of the string.
Defining macros On the command line, no spaces may surround the equal sign. Spaces cause
on the NMAKE command line DOS to treat macroname and string as separate tokens. Strings that contain
embedded spaces must be enclosed in double quotation marks. Alternatively,
you can enclose the entire macro definition macroname and string in quota- —
tion marks. The string may be a null string.
After you have defined a macro, use the following to include it in a dependency
line or command:
${macroname)
The parentheses are not required if macroname is only one character long. The
macroname is converted to uppercase letters. If you want to use a dollar sign ($)
in the file but do not want to invoke a macro, enter two dollar signs ($$), or use
the caret (^) as an escape character preceding the dollar sign.
Example
Assume the following text is in a file named MAKEFILE:
program = flash
c = LINK
options =
When you invoke NMAKE, it interprets the description block as the following:
flash.exe : flash. obj
LINK flash. obj;
$(macroname:stringl = string!)
following stringl or preceding stringl are ignored. If stringl is a null string, all
Example
SRCS = prog.c subl.c sub2.c
prog.exe $( SRCS :. c= obj
: .
LINK $**;
DUP : ${SRCS)
ICOPY $** c:\backup
Note that the special macro $** stands for the names of all
the dependent files
(see Section 7,3.2.3). If the description file above invoked with a command
is
line that specifies both targets, NMAKE will execute the following commands:
The macro substitution does not alter the definition of the macro SRCS, but
simply replaces the listed characters. When NMAKE builds the target
prog exe, . it picks up the definition for the special macro $** (that is, the list
of dependents) from the dependency line, which specifies the macro substitution
in SRCS, The same is true for the second target, DUP, In this case, however, no
macro substitution is requested, so SRCS retains its original value, and $** rep-
resents the names of the C source files.
NMAKE 165
Macro Value
CC = qcl
You might want to place the above definition in your
TOOLS.INI file to avoid having to redefine it for each de-
scription file.
macro.
h h
Characters that modify You can append characters to any of the first six macros in the above list to mod-
spec/a/ macros meaning. Appending a D sjxjcifies the directory part of the file name only,
ify its
an F specifies the file name, a B specifies just the base name, and an R specifies
the complete file name without the extension. If you add one of these characters,
you must enclose the macro name in parentheses. (The special macros $$@ and
$** are the only exceptions to the rule that macro names more than one
character long must be enclosed in parentheses.)
For example, assume that $@ has the value C \ SOURCE \prog\ SORT OB J. : .
The list below shows the effect the special characters have when combined
with $(5):
Macro Value
$(@D) C:\SOURCE\PROG
$(@F) SORT. OBJ
$(@B) SORT
$(@R) C:\SOURCE\PROG\SORT
Examples
trig. lib : sin.obj cos.obj arctan.obj
!LIB trig. lib -+$?;
In the example above, the macro $? represents the names of all dependents that
are more recent than the target. The exclamation point causes NMAKE to ex-
ecute the LIB command once for each dependent in the list. As a result of this de-
scription, the LIB command is executed up to three times, each time replacing a
module with a newer version.
COPY globals.h $@
$ (DIR) \types .h types. :
COPY types. h $@
$ (DIR) \macros h macros. . :
COPY macros. h $@
This example shows the use of NMAKE to update a group of include files. In
the description file above, each of the files globals h, types h, and
. .
with the file of the same name from the current directory.
.
NMAKE 167
The following description file, which uses the special macro $$@, is equivalent:
!COPY $? $@
In this example, the special macro $$(@F) signifies the file name (without the
directory) of the current target.
When NMAKE executes the description, it evaluates the three targets, one at a
time, with respect to their dependents. Thus, NMAKE first checks whether
c:\include\globals.h is out of date compared with globals.h in
the current directory. If so, it executes the command to copy the dependent file
globals h . to the target. NMAKE repeats the procedure for the other two tar-
gets. Note that in the command line, the macro $? refers to the dependent for this
target. The macro $@ means the full name of the target.
looks for an inference rule that specifies how to create the target from the de-
pendent files, given the two file extensions. Similarly, if a dependent file does
not exist, NMAKE looks for an inference rule that specifies how to create the de-
pendent from another file with the same base name.
.
The use of inference rules eliminates the need to put the same commands in
several description blocks. For example, you can use inference rules to specify a
single QCL command that changes any C source file (which has an extension of
.C) to an object file (which has an extension of .OBJ).
.fromext.toext:
command
\[command^
.C.OB J:
QCL -c $<;
The special macro $< represents the name of a dependent that is out of date rela-
tive to the target.
Path specifications You can specify a single path for each of the extensions, using the following
form:
commands
NMAKE takes the files with i\ie,fromext extension it finds in the directory
specified hy frompath and uses commands to create files with the toext extension
in the directory specified by topath.
NOTE NMAKE applies an inference rule only if the base name of the file it is trying to create
matches the base name of a file that already exists.
NMAKE 169
In effect, this means that inference rules are useful only when there is a one-to-one correspon-
dence between the files with the "from" extension and the files with the to" extension. You cannot,
for example, define an inference rule that inserts a number of modules into a library.
Predefined inference rvles NMAKE uses three predefined inference rules, summarized in Table 7.1. Note
macro CC, which invokes the Microsoft C Optimizing
that these rules use the
Compiler by default. If you plan to rely on inference rules to build your targets,
you should redefine CC to invoke the QuickC compiler, as shown in
Section 7.3.2.3.
Example
.OBJ. EXE:
LINK $<;
In the sample description file above, the first line defines an inference rule that
executes the LINK command on the second line to create an executable file
whenever a change is made in the corresponding object file. The file name in the
inference rule is specified with the special macro $< so that the rule applies to
any .OBJ file that has an out-of-date executable file.
When NMAKE does not find any commands in the first description block, it
checks for a rule that may apply and finds the rule defined on the first two lines
of the description file. NMAKE
applies the rule, replacing the $< macro with
EXAMPLEl OBJ when . it executes the command, so that the LINK command
becomes
NMAKE does not search for an inference rule when examining the second de-
scription block because a command is explicitly given.
1 70 Microsoft QuickC Tool Kit
7.3.4 Directives
Using directives, you can construct description files that are similar to batch
files. NMAKE provides directives that specify conditional execution of com-
mands, display error messages, include the contents of other files, and turn on or
off some of NMAKE's options.
Each directive begins with an exclamation point (!) in the first column of the de-
scription file. Spaces can be placed between the exclamation point and the direc-
tive keyword. The list below describes the directives:
Directive Description
value.
value to be defined.
IIFNDEF macroname Executes the statements between the IIFNDEF
keyword and the next ELSE or lENDIF direc-
I
The constantexpression used with the !IF directive may consist of integer con-
program invocations. Integer constants can use the C
stants, string constants, or
unary operators for numerical negation (-), one's complement (~), and logical
negation (!). They may also use any of the C binary operators listed below:
Operator Description
+ Addition
— Subtraction
* MuUiplication
/ Division
% Modulus
& Bitwise AND
!
Bitwise OR
AA Bitwise XOR
&& Logical AND
II
Logical OR
« Left shift
» Right shift
== Equality
Inequality
You can use parentheses to group expressions. Values are assumed to be deci-
mal values unless specified with a leading (octal) or leading Ox (hexadecimal).
Use the equality (==) operator to compare two strings for equality or the inequal-
ity (!=) operator to compare for inequality. Strings are enclosed by quotes. Pro-
gram invocations must be in square brackets ([ ]).
172 Microsoft QuickC Tool Kit
Example
!INCLUDE <infrules.txt>
•CMDSWITCHES +D
winner. exerwinner.obj
IIFDEF debug
! IF "$ (debug) "=="y"
LINK /CO winner. obj;
! ELSE
LINK winner. obj;
ENDIF
ELSE
ERROR Macro named debug is not defined.
ENDIF
The IINCLUDE directive causes the file INFRULES TXT to be read and eval-.
uated as were a part of the description file. The !CMDS WITCHES directive
if it
turns on the /D option, which displays the dates of the files as they are checked.
If winner.exe is out of date with respect to winner .obj, the !IFDEF
directive checks to see if the macro debug is defined. If it is defined, the !IF
directive checks to see if it is set to y. If it is, then the linker is invoked with the
/CO option; otherwise it is invoked without. If the debug macro is not de-
fined, the lERROR directive prints the message and NMAKE stops executing.
7.3.5 Pseudotargets
A "pseudotarget" is a target that is not a file but instead is a name that serves as
a "handle" for building a group of files or executing a group of commands. In
the following example, UPDATE is a pseudotarget:
UPDATE: *.*
loopy $** a:\product
The NMAKE utility includes four predefined pseudotargets that provide special
rules within a description file. The list below describes these pseudotargets:
Pseudotarget Action
.SILENT: Does not display lines as they are executed. Same effect
as invoking NMAKE with the /S option.
.IGNORE: Ignores exit codes returned by programs called from the
description file. Same effect as invoking NMAKE with
the /I option.
NMAKE 173
.SUFFIXES ://5r Lists file suffixes for NMAKE to try if it needs to build a
target file for which no dependents are specified.
NMAKE searches the current directory for a file with the
same name as the target file and a suffix from the list. If
NMAKE finds such a file, and if an inference rule ap-
plies to the file, then NMAKE treats the file as a
dependent of the target. The order of the suffixes in the
hst defines the order in which NMAKE searches for the
files. The list is predefined as follows:
.SUFFIXES:
.PRECIOUS: target. Tells NMAKE not to delete target if the commands that
build it are quit or interrupted. Using this pseudotarget
overrides the NMAKE default. By default, NMAKE de-
letes the target if it cannot be sure the target was built
successfully. For example:
7A Response-File Generation
At times, you may need to issue a command in the description file that has a list
of arguments that exceeds the DOS Umit of 128 characters. Just as sup- NMAKE
ports the use of response files, it can also generate response files for use with
other programs.
target : dependents
command @« Ifilename^
response-file-text
j
All of the text between the two sets of angle brackets («) is placed in a re-
sponse file. The second pair of angle brackets must be at the beginning of the
line, with no preceding white-space characters. Note that the at sign (@) is not
part of the NMAKE
syntax but is the typical response-file character for utilities
such as LINK and LIB.
To name the response file, specify a filename immediately after the first pair of
angle brackets, with no intervening spaces. If you do not specify a file name,
NMAKE gives the response file a unique name in the directory specified by the
TMP environment variable if the variable is defined; if the TMP variable is not
defined, NMAKE creates the response file in the current directory.
Example
math. lib add.obj sub.obj mul.obj div.obj
:
LIB @«
math lib .
listing
«
The above example creates a response file and uses it to invoke the Microsoft
Library Manager (LIB), The response file specifies which library to use, the com-
mands to execute, and the listing file to produce. The response file contains the
following:
math lib .
listing
NMAKE 175
MAKE assumed that all targets in the description file would be built. Because
NMAKE builds the first target in the file unless you specify otherwise, you may
need to change your old description files to work with the new utility.
Description files written for use with MAKE typically Ust a series of subordinate
targets followed by a higher-level target that depends on the subordinates. As
MAKE executed, it would build the targets sequentially, creating the highest-
level target at the end.
The easiest way to convert these description files is to create a new description
block at the top of the file. Give this block a pseudotarget named ALL and set its
dependents to all of the other targets in the file. When executes the de- NMAKE
scription, it will assume you want to build the target ALL and consequently will
build all targets in the file.
Example
one.obj: one.c
two ob j . : two .
X ob. j : X c .
y ob j
. : y c .
z . ob j : z . c
Assume the above is an old MAKE description file named MAKEFILE. Note
that it builds two top-level targets, progl exe and xyz exe To use this
. . .
file with the new NMAKE, insert the following as the first line in the file:
With the addition of this line, ALL becomes the first target in the file. Since
NMAKE, by default, builds the first target, you can invoke NMAKE with
NMAKE
infer the creation of .OBJ files from .C or .ASM sources as NMAKE does.
HELPMAKE
HELPMAKE translates help text files into a help data base accessible
from within the following:
Microsoft Editor
QuickC
Microsoft® QuickBASIC
To use HELPMAKE, you specify the name of a help text file formatted
in one of several simple styles and the amount by which to compress the
file. HELPMAKE can also decompress a help data base to its original
text format.
information about the subject, then lists another subject and some information
about it, then another, and so on. In HELPMAKE terminology, the subjects are
called "contexts" and the information is called "topic text." Whenever someone
asks for help on the open function, the Advisor looks for the context "open" and
displays its topic text. (The name of every function in the C run-time library is a
context throughout the QuickC Advisor.)
Often, especially with library routines, the same information applies to more
than one subject. For example, the string-to-number functions strtod, strtol, and
stroul share the same help text. The help file lists all three function names as
contexts for one block of topic text. The converse, however, is not true. You can-
not specify different blocks of topic text, in different places in the help file, to de-
scribe a single subject.
Cross-references To make it easier for users to navigate through a help data base, you can put
cross-references in your help text. Cross-references bring up information on re-
lated topics, including header files and code examples. The help for the open
function, for example, references the access function and the ASCII header file
FCNTL.H. Cross-references can point to other contexts in the same help data
base, to contexts in other help data bases, or to ASCII files outside the data base.
u Implicit cross-references
Implicit cross-references The word "open" is an "implicit cross-reference" throughout QuickC help be-
cause it is the name of a function. If a user selects the word "open" anywhere in
QuickC help, the help system displays information on the open function. Cross-
references like this are called "implicit cross-references" because they are impli-
cit in the help fileand require no special coding. Anywhere a context appears,
the help system makes an implicit cross-reference to its topic text.
HELPMAKE 179
Hyperlinks Explicit cross-references, also called "hyperlinks," are tied to a word or phrase at
a specific location in the help file. You set up explicit cross-references when you
write the help text. For example, to cause one instance of the word "formatting"
to bring up help on the printf function, you would create an expUcit cross-
reference from the word "formatting" to the context "printf." Anywhere else in
the file, "formatting" would have no special significance, but at that one posi-
tion, it would reference the help for printf.
Formatting flags Help text can also include formatting flags to control the appearance of the text
on the screen. Using these flags, you can make certain words appear in boldface,
others underlined, and so forth, depending on the graphics capabilities of the
user's computer. In QC.HLP, the help data base Microsoft supplies for QuickC,
cross-references appear underlined when displayed on a monochrome monitor.
On a color monitor, they appear highlighted instead. Other applications may rep-
resent cross-references differently; for example, in italics or in color.
QuickHelp format
QuickHelp QuickHelp format is the default and is the format in which HELPMAKE writes
files it decodes from existing help data bases. Use any text editor to create a
QuickHelp-format help text file. QuickHelp format also lends itself to a rela-
tively easy automated translation from other document formats.
RTF Rich Text Format (RTF) is a Microsoft word-processing format that many other
word processors also support. You can create RTF help text with any word pro-
cessor capable of generating RTF output. You may also use any utility program
that takes word-processor output and produces an RTF file.
Use RTF when you want to transfer help files from one application to another
while retaining formatting information. You can format RTF files directly with
180 Microsoft QuickC Tool Kit
theword processing program and need not edit them to insert any special com-
mands or lags. Like QuickHelp files, RTF files can contain formatting attributes
and cross-references.
Minimally formatted ASCII Minimally formatted ASCII files simply define contexts and their topic text.
These files cannot contain cross-references or screen-formatting commands.
Unformatted ASCII Unformatted ASCII files are exactly what their name implies: regular ASCII
files with no special formatting commands, context definitions, or special infor-
mation whatsoever. An unformatted ASCII file does not become part of the help
data base. Instead, only its name is used as the object of a cross-reference. The
standard C header (include) files are unformatted ASCII files used for cross-
references by the help system for the C run-time library. Unformatted ASCII
files are also useful for program examples.
Decoding reverses the process: it converts a help data base into a text file. The
utility can decode any Microsoft help data base file to a QuickHelp formatted
text file for editing. It can also encode an RTF (Rich Text Format), QuickHelp,
or minimally formatted ASCII text file into help-data-base format.
Either the /E (encode) or the /D (decode) option must be supplied. When encod-
ing (/E) to create a help data base, you must use the /O option to specify the file
name of the data base.
The sourcefile field is required. It specifies the input file for HELPMAKE. If
you use the /D (decode) option, sourcefile may be one or more help-data-base
files (such as QC.HLP). HELPMAKE decodes the data-base files into a single
text file. If you use the /E (encode) option, sourcefile may be one or more help
text files (such as QC.SRC). Separate file names with a space. Standard wild-
card characters may also be used.
HELPMAKE 181
Example
HELPMAKE /V /E /Omy.hlp my.txt > my. log
This example invokes HELPMAKE with the A'^, /E, and /O options (see Section
8.3.1). HELPMAKE reads input from the text file my txt and writes the com- .
pressed help data base in the file my hip. The /E option causes maximum com-
.
pression. Note that the DOS redirection symbol (>) sends a log of HELPMAKE
activity to the file my log. You may
. find it helpful to redirect the log file be-
cause, in its more verbose modes (given by A^), HELPMAKE may generate a
lengthy log.
This example invokes HELPMAKE to decode the help data base my hip into .
the text file my s re, given with the /O option. Once again, the fV option re-
,
sults in verbose output, and the output is directed to the log file my log. Sec- ,
Most options apply only to encoding; others apply only to decoding; and a few
apply to both. Section 8.3.1 describes all the options that apply to encoding, and
Section 8.3.2 describes all the options that apply to decoding.
Option Action
/C Indicates that the context strings for this help file are case
sensitive. At run time, all searches for help topics are
case sensitive if the help data base was built with the /C
option in effect.
182 Microsoft QuickC Tooi Kit
Value Technique
No compression
1 Run-length compression
2 Keyword compression
4 Extended-keyword compression
8 Huffman compression
Add values combine compression techniques. For ex-
to
ample, use /E3 to get run-length and keyword
compression. This is useful in the testing stages of help-
data-base creation where you need to create the data base
quickly and are not too concerned with size.
Option
HELPMAKE 183
Option Action
/DJ^letter^ Decodes the input file into its component parts. If a desti-
nation not specified with the /O option, the help
file is
Letter Effect
Option Effect
The first method decompress an existing help data base, modify the result-
is to
ing help text and recompress the help text file to form a new data base. Note
file,
that, if you decompress the Microsoft help-data-base file QC.HLP, the resulting
text file occupies about 800K on disk.
The second and simpler method is to append a new help data base onto an ex-
isting help data base. This method involves the following steps:
3. Make a back-up copy of the existing data-base file (for safety's sake).
HELPMAKE 185
4. Append the new help-data-base file onto the existing help data base. The ex-
ample below concatenates the new data base sample, hip onto the end of
the QC.HLP data base:
COPY qc.hlp /b + sample. hip /b
5. Test the data base. The sample, hip data base contains the context
sample. you type the word "sample" in the QuickC environment and re-
If
quest help on it, the help window will display the text associated with the
context sample.
text. The HELPMAKE utility and the display routines built into Microsoft lan-
guage environments, however, make certain assumptions about the format of
help text. This section provides some guidelines for creating help text files that
are compatible with those assumptions.
In all three help text formats, the help text source file is a sequence of topics,
each preceded by one or more unique context definitions.
Contexts in QuickHelp In QuickHelp format, each topic begins with one or more context definitions that
define the context strings that map to the topic text. Subsequent hnes up to the
next context definition constitute the topic text, as shown below:
.context strtod
.context strtol
.context stroul
.context strtok
Contexts in RTF In RTF, each context definition must be in a paragraph of its own, beginning
with the help delimiter (»). Subsequent paragraphs up to the next context defi-
nition constitute the topic text, as shown below:
{rtfO
>>strtod \par
>>strtol \par
>>stroul \par
>>strtok \par
>>strtod
>>strtol
>>stroul
>> strtok
Microsoft languages. If you decompress any of the help data base files that
Microsoft supplies, you will see these contexts in the text output.
The contexts listed below are required and are present in all Microsoft help files.
If you modify or replace the standard files, be sure to retain these definitions.
HELPMAKE 187
Context Description
h.notfound The help text that is displayed when the help system can-
not find information on the requested context. The text
could be an index of contexts, a topical list, or general in-
formation on using help.
h.pgl The help text that is logically first in the file. This is used
by some applications in response to a "go to the begin-
ning" request made within the help window.
h.pg$ The help text that is logically last in the file. This is used
by some applications in response to a "go to the end" re-
quest made within the help window.
Note each of the contexts above begins with h. Microsoft help systems con-
that
sider context strings beginning with x., where x is a specified character prefix, as
"internal" or "constructed" help contexts. Except for the contexts listed above,
these apply to menu items, error numbers, and so forth; in general, you do not
need to insert these in your help files. The following character prefixes denote in-
ternal help contexts:
Character Description
The keystroke that activates the hyperlink depends on the application. Consult
the documentation for each product to find the specific keystroke needed.
When the user activates the hyperlink, the help system displays the topic named
by the invisible text.
Examples
\bSee also:\p \uExample\p\vopen ex\v .
the letters of Example brings up the help topic whose context is open. ex.
On the user's screen, this line appears as follows:
See also: Example
When a hyperlink needs to cross-reference more than one word, you must use an
anchor, as in the example above. Anchored hyperlinks must fit on a single line.
In this case, the hyperlink consists of the phrase formatting table, which
references the context print f .table. The\v flag makes the name
print f table . invisible; it does not appear on the screen when the help is
displayed.
HELPMAKE 189
When you use a local context, HELPMAKE does not generate a context string
thatcan be used from elsewhere in the help file. Instead, it embeds a cross-
reference that has meaning only within the current context. An example of this
usage is shown below:
.context normal
This is a normal topic, accessible by the context string
"normal .
.context @local
This topic can be reached only if the user browses
sequentially through the file or uses the cross-reference
in the previous topic.
may appear at the beginning of any line of help text. This special character is in-
terpreted by the application. If the application does not support this character, it
is ignored.
Within the data bases and applications provided with Microsoft languages, a
colon is used as the control character, and the following colon commands are
supported:
Command Action
Example
.context open
:113
\blnclude:\p <fcntl.h>, <io.h>, <sys\\types ,h>,
<sys\stat h> .
This example shows the data-base entry from the C run-time library for the open
routine. The 11 3 command on the second Une of the file defines the default
:
An entire help system (such as the one supphed with Microsoft C, QuickC, or
QuickBASIC) may use any combination of files formatted with different format
types. With C, for example, the README.DOC information file is encoded as
minimally formatted ASCII; and the help files for the C language and run-time
library are encoded in the QuickHelp format. The data base also cross-references
the header (include) files, which are unformatted ASCII files stored outside the
data base.
The list below summarizes the three formats and their characteristics:
Type Characteristics
Minimally formatted Uses a help delimiter (») to define help contexts; does
ASCn not support highlighting, color, or cross-references. This
format may be compressed, but compression is not
required.
One or more .context commands precedes each topic in a QuickHelp file. Each
.context command defines a context string for the topic text. You may define
more than one context for a single topic, as long as you do not place any topic
text between them.
Typical context commands are shown below. The first defines a context for the
#include C preprocessor directive. The second set illustrates multiple contexts
192 Microsoft QuickC Tool Kit
forone block of topic text. In this case, the same topic text explains all of the
string-to-number conversion routines in C.
.context #include
.context strtod
.context strtol
.context strtoul
On monochrome monitors, text labeled with the bold, italic, and underlining at-
tributes appears in boldface, italics, or underlined, respectively. On color moni-
by the application into suitable colors,
tors, these attributes are translated
depending on the user's default color selections.
The\b,\i,\u, and\v options are toggles, turning on and off their respective at-
tributes. You may use several of these on the same text. Use the \p attribute to
turn off all attributes. Use the \v attribute to hide cross-references and hyperlinks
in the text.
HELPMAKE 193
HELPMAKE truncates the lines in QuickHelp files to the width specified with
the AV option. (See Section 8.3.1 for a description of this option.) The format-
ting flags do not count toward the character-width limit. Lines that begin with an
application-specific control character are truncated to 255 characters regardless
of the width specification. See Section 8.5.4.2 for details on application-specific
control characters.
Examples
\bReturns:\p a handle if successful, or -1 if not.
errno: EACCES, EEXIST, EMFILE, ENOENT
In this example, the \b flag initiates boldface text for the word Returns: and
the \p flag that follows the word reverts to plain text for the remainder of the line.
In this example, the\b and\p flags surrounding See also : work in the same
way as those surrounding Returns previous example. The \u flag that
: in the
precedes Example causes that word to be underlined on monitors that support
underlining and highlighted on monitors that do not. The^p flag that follows
Example turns off underlining for the text that follows. The\v flag causes the
text open ex to be invisible and defines a cross-reference, as described in the
.
following section.
If the hyperlink consists of a single word, you can use invisible text to flag it in
the source file. The\v formatting flag creates invisible text, as follows:
hyperlink\\context\y
Specify the first \v flag immediately following the word you want to use as
the hyperlink. Following the flag, insert the context that the hyperlink cross-
references. The second \v flag marks the end of the context, that is, the end of
) ;
If the hyperlink consists of a phrase, rather than a single word, you must use an-
chored text to create explicit cross-references. Use the\a and\v flags to create
anchored text as follows:
"^yperlink-wordsXycontexAv
The ^a marks an "anchor" for the cross-reference. The text that follows the
flag
\a flag is The hyperlink must fit entirely on one line. The first \v
the hyperlink.
flag marks both the end of the hyperlink and the beginning of the invisible text
that contains the cross-reference context. The second \v flag marks the end of the
invisible text.
Examples
See also: abs, cabs, fabs
The example above shows the encoding for an explicit cross-reference to an ex-
ample program and a function template from the help data base for the C run-
time library. The hyperhnks are Example and Template, which reference
the contexts open ex and open tm. The example also contains an implicit
. .
The example above shows the encoding for an explicit cross-reference to an en-
tirefamily of functions. This cross-reference uses anchored text to associate a
phrase, rather than just a word, with a context. In this example, the hyperlink is
the anchored phrase is . . . f unct ions, and it cross-references the context
is_f unct ions. In addition, the example contains an implicit cross-reference
to the atoi routine.
.context open
:113
\blnclude:\p <fcntl.h>, <io.h>, <sys\\types h>, .
<sys\\stat h> .
HELPMAKE 195
\uTemplate\p\vopen tp\v, .
QuickC-specific character used in the help display. The number that follows 1
specifies the size of the initial window for the help text. In this case, the initial
window displays 13 lines.
open . tp, respectively. Note the use of double backslashes in the include file
names.
Example
>>open
The preceding example, coded in minimally formatted ASCII, shows the same
text as the previous example. The first line of the example defines open as a
context string; therefore the topic text that follows will be displayed when the
user requests help on that topic. No formatting flags or cross-references are in-
cluded because minimally formatted ASCII does not support them. Note,
however, the double backslashes in the file names sys \ \ types and
sysWstat h. The double backslashes ensure that HELPMAKE interprets the
.
The minimally formatted ASCII help file must begin with the help delimiter
(»), so that HELPMAKE can verify that the file is indeed an ASCII help file.
HELPMAKE 197
Using the word-processing program, you can break the topic text into para-
graphs. When HELPMAKE compresses the file, it formats the text to the width
given with the fW option, ignoring the paragraph formats.
As with the other text formats, each entry in the data base source consists of one
or more context
strings, followed by topic text. The help delimiter (») at the
beginning of any paragraph denotes the beginning of a new help entry. The text
that follows on the same line is defined as a context for the topic. If the next para-
graph also begins with the help delimiter, it also defines a context string for the
same topic text. You may define any number of contexts for a block of topic
text. The topic text comprises all subsequent paragraphs up to the next paragraph
that begins with the help delimiter.
Example
{rtfO
>> open \par
{\b Include:} <fcntl.h>, <io.h>, <sys\\types .h>,
<sys\\stat .h>
{\b Prototype:} int open (char *path, int flag[, int mode] )
The code above isan example of a help data base that contains a single entry
using subset RTF text. Note that RTF uses curly braces ({ }) for nesting. Thus,
the entire file is enclosed in curly braces, as is each specially-formatted
text item.
Appendixes
A ExitCodes 201
Exit Codes
Most of the utilities return an exit code (sometimes called an "errorlevel" code)
that can be used by DOS batch files or other programs such as NMAKE. If the
program finishes without errors, it returns exit code 0. The code returned is non-
zero if the program encounters an error. This appendix discusses several uses for
exit codes and lists the exit codes that can be returned by each utility.
For example, assume the NMAKE description file TEST contains the follow-
ing lines:
If the source code in TEST.C contains a program error (but not if it contains a
warning error), you would see the following message the first time you use
NMAKE with the NMAKE description file TEST:
This error message indicates that the command QCL /c test C . in the
NMAKE description file returned exit code 2.
You can also test exit codes in NMAKE description files with the !IF directive.
QCL /c %1.C
IF NOT ERRORLEVEL 1 LINK %1;
IF NOT ERRORLEVEL 1 %I
202 Microsoft QuickC Tool Kit
You can execute this sample batch file with the following command:
COMPILE TEST
DOS then executes the first line of the batch file, substituting TEST for the par-
ameter % 1, as in the following command Une:
QCL /c TEST.C
It returns exit codeif the compilation is successful or a higher code if the com-
piler encounters an error. In the second line, DOS tests to see if the code re-
turned by the previous line is 1 or higher. If it is not (that is, if the code is 0),
DOS executes the following command:
LINK TEST;
LINK also returns a code, which is tested by the third line. If this code is 0, the
TEST program is executed.
The compiler returns the following exit codes:
Code Meaning
No error
Nonzero number Program or system-level error
Code Meaning
««
No error.
2 Program error. Commands or files given as input to the linker pro-
duced the error.
Exit Codes 203
Code Meaning
No error.
Code Meaning
No error
2 Program error
4 System error —out of memory
Appendix B 205
You can gain greater control over how your program uses memory by specifying
thememory model for the program. You do not need to specify a memory model
except in the following cases:
Your program has more than 64K of code or more than 64K of static data.
Your program contains individual arrays that need to be larger than 64K.
1 If you are compiling with the QCL command, you can specify one of the
other standard memory models (medium, compact, large, or huge) using one
of the /A options.
2. You can create a mixed-model program using the near, far, and huge
keywords.
Segments DOS loads the code and data allocated by your program into "segments" in
physical memory. Each segment is up to 64K long. Because separate segments
are always allocated for theprogram code and data, the minimum number of seg-
ments allocated for a program is two. These two segments, required for every
program, arc called the default segments. The small memory model uses only
the two default segments. The other memory models discussed in this chapter
allow more than one code segment per program, or more than one data segment
per program, or both.
Near addresses In the 8086 family of microprocessors, all memory addresses consist of two
parts:
The architecture of the 8086 microprocessor is such that code can be accessed
within the default code or data segment by using just the 16-bit offset value. This
is possible because the segment addresses for the default segments are always
known. This 16-bit offset value is called a "near address"; it can be accessed
with a "near pointer." Because only 16-bit arithmetic is required to access any
near item, near references to code or data are smaller and more efficient.
Far addresses When data or code lie outside the default segments, the address must use both
the segment and offset values. Such addresses are called "far addresses"; they
can be accessed by using "far pointers" in a C program. Accessing far data or
code items is more expensive in terms of program speed and size, but using them
enables your programs to address all memory, rather than just the standard 64K
code and data segments.
Huge addresses There is a third type of address in Microsoft QuickC: the "huge" address. A
huge address is similar to a far address in that both consist of a segment value
and an offset value; but the two differ in the way address arithmetic is performed
on pointers. Because items (both code and data) referenced by far pointers are
still assumed to he completely within the segment in which they start, pointer
arithmetic is done only on the offset portion of the address. This gain in pointer
arithmetic efficiency is achieved, however, by limiting the size of any single
item to 64K. With data items, huge pointers overcome this size limitation:
pointer arithmetic is performed on all 32 bits of the data item's address, thus al-
lowing data items referenced by huge pointers to span more than one segment,
provided they conform to the rules outlined in Section B.2.5, "Creating Huge-
Model Programs."
The rest of this chapter deals with the various methods you can use to control
whether your program makes near or far calls to access code or data.
When you use the standard memory models, the compiler handles library sup-
port for you.The library corresponding to the memory model you specify is used
automatically. Each memory model, except the huge model, has its own hbrary.
The huge model uses the same library as the large model.
The advantage of using standard models for your programs is simplicity. In the
standard models, memory management is specified by compiler options; since
the standard models do not require the use of extended keywords, they are the
best way code that can be ported to other systems (particularly systems
to write
that do not use segmented architectures).
.
The disadvantage of using standard memory models exclusively is that they may
not produce the most efficient code. For example, if you have an otherwise
small-model program containing a large array that pushes the total data size for
your program over the 64K limit for small model, it may be to your advantage to
declare the one array with the far keyword, while keeping the rest of the pro-
gram small model, as opposed to using the standard compact memory model for
the entire program. For maximum flexibility and control over how your program
uses memory, you can combine the standard-memory-model method with the
near, far, and huge keywords, described in Section B.3.
The /A options for QCL are used to specify one of the five standard memory
models (small, medium, compact, large, or huge) at compile time. These
memory-model options are discussed in the next five sections.
NOTE In the following sections, which describe the different memory-model addressing conven-
tions, it is important to keep in mind two common features of all five models:
2. No single data item can exceed 64K, unless it appears in a huge-model program or it has been
declared with the huge keyword.
Small-model programs are typically QuickC programs that are short or have a
limited purpose. Because code and data for these programs are each limited to
64K, the total size of a small-model program can never exceed 128K. Most pro-
grams fit easily into this model.
Because programs compiled within the QuickC environment use the small
memory model by default, you should give the /AS option in cases where you
use the QCL command to compile a module for use within the QuickC
environment.
By default, both code and data items in small-model programs are accessed with
near addresses. You can override the defaults by using the far or huge keyword
for data or by using the far keyword for code.
The compiler in the QuickC environment and the QCL command create small-
model programs automatically if you do not specify a memory model. The /AS
option is provided for completeness; you never need to give it explicitly.
208 Microsoft QuickC Tool Kit
Figure B.l illustrates how memory is set up for the small memory model.
Working with QuickC Memory Modeis 209
) ;
main (
fund (NULL) ;
func2 (NULL)
}
This example passes a 16-bit pointer to both fund and func2 if compiled
using the medium model, and a 32-bit pointer to both fund and func2 if
compiled using the compact model. To override this behavior, add prototypes to
the beginning of the program to indicate the types, or use an explicit cast on the
argument to fund (compact model) or func2 (medium model).
Figure B.3 illustrates how memory is set up for the compact memory model.
High memory
Low memory
Large-model programs are typically very large C programs that use a large
amount of data storage during normal processing.
By default, both code and data items in large-model programs are accessed with
far addresses. You can override the defaults by using the near or huge keyword
for data or by using the near keyword for code.
Figure B.4 illustrates how memory is set up for the large and huge memory
models.
High memory
Low memory
Figure B.4 Memory Map for Large and Huge Memory Models
212 Microsoft QuickC Tool Kit
1. No array element can be larger than 64K. For instance, this might occur
when an array has elements that are structures or arrays.
2. For any array larger than 128K, all elements must have a size in bytes equal
to a power of 2 (that is, 2 bytes, 4 bytes, 8 bytes, 16 bytes, and so on). If the
array is 128K or smaller, however, its elements may be any size, up to and in-
cluding 64K.
Pointer subtraction In huge-model programs, care must be taken when using the sizeof ojxjrator or
when subtracting pointers. The C language defines the value returned by the
sizeof operator to be an unsigned int value, but the size in bytes of a huge array
is an unsigned long value. To solve this discrepancy, the Microsoft QuickC
Compiler produces the correct size of a huge array when a type cast like the fol-
lowing is used:
Similarly, the C language defines the result of subtracting two pointers as an int
value. When subtracting two huge pointers, however, the result may be a long
int value. The Microsoft QuickC Compiler gives the correct result when a type
cast like the following is used:
Table B.l Addressing of Code and Data Declared with near and far
Pointer
Keyword Data Function Arithmetic
NOTE The near, far, and huge keywords are not a standard part of the C language; they are
meaningful only for systems that use a segmented architecture similar to that of the 8086 micro-
processors. Keep this in mind if you want your code to be ported to other systems.
In the Microsoft QuickC Compiler, the words near, far, and huge are C key-
words by default. To treat these keywords as ordinary identifiers, you must do
one of the following:
For programs compiled within the QuickC environment, compile with the
Language Extensions option turned off.
For programs compiled with the QCL command, give the fZa. option at com-
pile time.
;
These options are useful if you are compiling programs with compilers in which
—
near, far, and huge are not keywords for instance, if you are porting a pro-
gram in which one of these words is used as a label.
Ifyou use the near, far, or huge keyword, it is strongly recommended that you
use function prototypes with argument-type lists to ensure that all pointer argu-
ments are passed to functions correctly (see Section B.3.4).
The keyword always modifies the object or pointer immediately to its right.
In complex declarators, think of the far keyword and the item immediately to
its right as being a single unit. For example, in the declarator
pointer to char.
If the item immediately to the right of the keyword is an identifier, the key-
word determines whether the item will be allocated in the default data seg-
ment (near) or a separate data segment (far or huge). For example,
char near a;
u If the item immediately to the right of the keyword is a pointer, the keyword
determines whether the pointer will hold a near address (16 bits), a far
address (32 bits) or a huge address (also 32 bits). For example,
Examples
The examples in this section show data declarations using the near, far, and
huge keywords.
The first declaration in the example above allocates the array a in the default
data segment. By contrast, the array b in the second declaration may be allo-
cated in any far data segment. Since these declarations appear in a small-model
program, array a probably represents frequently used data that were deliber-
ately placed in the default segment for fast access. Array b probably represents
seldom used data that might make the default data segment exceed 64K and
force the programmer memory model if the array were not de-
to use a larger
clared with the far keyword. The second declaration uses a large array because it
In theexample above, access speed would probably not be critical for array a.
Even though it may or may not be allocated within the default data segment, it is
The pointer pa is declared as a near pointer to an item of type char in the ex-
ample above. The pointer is near by default since the example appears in a small-
model program. By contrast, pb is allocated as a far pointer to an item of type
char; pb could be used to point to, and step through, an array of characters
stored in a segment other than the default data segment. For example, pa might
216 Microsoft QuickC Tool Kit
Examples
void char far fun (void) /* small model */
void char far fun (void)
In the example above, fun is declared as a function returning type char. The
far keyword in the declaration nneans that fun must be called with a 32-bit call.
In the large-model example above, fun is declared as a near function that re-
Such a function might be seen in a large-model
turns a far pointer to type char.
program as a helper routine that is used frequently, but only by the routines in its
own module. Because all routines in a given module share the same code seg-
ment, the function could always be accessed with a near call. However, you
could not pass a pointer to fun as an argument to another function outside the
module in which fun was declared.
or if it is not far by default, then calling that function through pfun would
cause the program to fail.
The final example above declares pfun as a far pointer to a function that re-
turns a far pointer to type double, and then assigns the address of fun to
pfun. This might be used in a compact-model program for a function that is not
used frequently and thus does not need to be in the default code segment. Both
the function and the pointer to the function must be declared with the far
keyword.
218 Microsoft QuickC Tool Kit
The default pointer size for that type, as defined by the memory model used
during compilation.
Ifa function prototype with argument types is given, the compiler performs type
checking and enforces the conversion of actual arguments to the declared type of
the corresponding formal argument. However, if no declaration is present or the
argument-type hst is empty, the compiler will convert pointer arguments auto-
matically to either the default type or the type of the argument, whichever is
largest. To avoid mismatched arguments, you should always use a prototype
with the argument types.
Examples
/* This program produces unexpected results in compact-,
** large-, or huge-model programs.
*/
main ( )
QCL) ormedium-model program (with the /AM option on the QCL command
line), the size of pointer argument x is 16 bits, the size of pointer argument y
is 32 bits, and the value printed for a is 1. However, if the preceding example is
compiled with the /AC, /AL, or /AH option, both x and y are automatically
converted to far pointers when they are passed to test_fun. Because ptrl,
the first parameter of test_f un, is defined as a near-pointer argument, it takes
only 16 bits of the 32 bits passed to it. The next parameter, pt r 2 takes the re-
,
maining 16 bits passed to ptrl, plus 16 bits of the 32 bits passed to it. Finally,
the third parameter, a takes the leftover 16 bits from pt r 2 instead of the
, ,
value of z in the main function. This shifting process does not generate an
error message, because both the function call and the function definition are
legal, but in this case the program does not work as intended because the value
assigned to a is not the value intended.
To pass ptrl as a near pointer, you should include a forward declaration that
specifically declares this argument for test_fun as a near pointer, as shown
below:
main ( )
Note that it would not be sufficient to reverse the definition order for
test_f un and main in the first example to avoid pointer coercions; the
Hardware-Specific Utilities
This appendix describes three utihty programs provided with Microsoft QuickC.
These utilities support special hardware that some QuickC users may have. The
utilities are the following:
The FIXSHIFT utility fixes a bug associated with some COMPAQ® and
compatible keyboards.
To correct the problem, copy FIXSHIFT.COM to the directory that contains the
QuickC program files, and type the following command:
f ixshift
Any combination of uppercase and lowercase letters is acceptable for this com-
mand. When FIXSHIFT executes, it first prompts you to press the down key to
ascertain whether the BIOS has the bug. If not, FIXSHIFT displays a message
telling you so, then exits. You need not run FIXSHIFT again. If your machine's
BIOS has the bug, FIXSHIFT displays additional prompts that guide you
through the appropriate actions.
MSHERC
To load the driver when you start the machine, put the MSHERC command in
your AUTOEXEC.BAT file.
Ifyou have both a Hercules monochrome card and a color video card, you
should invoke MSHERC.COM with the /H (/HALF) option, as follows:
MSHERC /H
The /R option causes the driver to use one instead of two graphics pages. This
prevents the two video cards from trying to use the same area of memory. You
need not use the /H option if you have only a Hercules card.
If you are developing a commercial application that uses graphics, you should
include MSHERC.COM with your product; you are free to include this file
without an explicit licensing agreement.
NOTE MSHERC.COM is identical to 0BHERC.COM, the Hercules driver shipped with Microsoft
OuickBASIC, Version 4.0, and the Microsoft BASIC Compiler, Version 6.0.
Error-Message Reference
This appendix lists error messages you may encounter as you develop a program
and gives a brief description of actions you can take to correct the errors. The fol-
lowing list tells where to find error messages for the various components of the
Microsoft QuickC Compiler:
Component Section
Note that the compiler, command-line, and run-time error messages are hsied al-
phabetically by category in this appendix.
See "Compiler Limits" in the "Compiler Errors" section for information about
compiler Umits; see "Run-Time Limits" in the "Run-Time Errors" section for in-
formation about run-time limits.
226 Microsoft QuickC Tool Kit
1. Fatal-error messages
2. Compilation-error messages
3. Warning messages
The messages for each category are listed below in numerical order, with a brief
explanation of each error. To look up an error message, first determine the mes-
sage category, then find the error number. Each message that is generated within
the QuickC environment appears in the error window; QuickC moves the cursor
to the line that caused the error. Each message that is generated by compiling
with the QCL command gives the file name and line number where the error
occurs.
Fatal-Error Messages
Fatal-error messages indicate a severe problem, one that prevents the compiler
from processing your program any further. These messages have the following
format:
Compilation-Error Messages
Compilation-error messages identify actual program errors. These messages ap-
pear in the following format:
The compiler does not produce an object file for a source file that has compila-
tion errors in the program. When the compiler encounters such errors, it attempts
to recover from the continues to process the source file and
error. If possible, it
produce error messages. If errors are too numerous or too severe, the compiler
stops processing.
Warning Messages
Warning messages are informational only; they do not prevent compilation or
linking. These messages appear in the following format:
You can use the AV option to control the level of warnings that the compiler
generates.
Please report this condition to Microsoft Corporation, using the Product As-
sistance Request form at the back of this manual.
Please report this condition using the Product Assistance Request form at the
back of this manual. Please include the file name and line number where the
error occurred in this report; note that the file name refers to an internal compiler
file, not your source file.
The compiler ran out of dynamic memory space. This usually means that your
program has too many symbols and/or complex expressions.
To correct the problem, divide the file into several smaller source files, or break
expressions into smaller subexpressions.
Errors in the program were too numerous or too severe to allow recovery, and
the compiler must terminate.
Check to see if the macro is recursively defined or if the expanded text is too
large.
The given file either did not exist, could not be opened, or was not found.
Make sure your environment settings are valid and that you have given the cor-
rect path name for the file. If this error appears without an error message, the
compiler has run out of file handles. In that case, increase the value of the
FILES= variable in your CONFIG.SYS file and reboot.
The given did not exist, could not be opened, or was not found. Make
file either
sure your environment settings are valid and that you have given the correct path
name for the file. If these are correct, the problem may be that the compiler has
run out of far heap space. See the description of error CI 060 for alternative solu-
tions. If this error appears without an error message, the compiler has run out of
file handles. In that case, increase the value of the FILES= variable in your
CONFIG.SYS file and reboot.
Error-Message Reference 229
You must specify an identifier with the #ifdef and #ifndef direcuves.
The #elif directive is legal only when it appears within an #if, #ifdef, or #ifndef
construct.
The #else directive is legal only when it appears within an #if, #ifdef, or #ifndef
construct.
The characters following the number sign (#) do not form a valid preprocessor
directive.
An #if, #ifdef, or #ifndef directive was not terminated with an #endif directive.
One of the following statements about the file name or path name given by
filename is true:
The file with the given name cannot be opened for lack of space.
To solve this problem, break the expression into simpler subexpressions and
recompile.
One of the conditions listed under error message CI 032 prevents the given file
The compiler could not create intermediate files used in the compilation process
because no more file handles were available.
The option appeared too many times. The string contains the occurrence of the
option that caused the error.
Error-Message Reference 231
The compiler limit on nesting of initializers was exceeded. The limit ranges
from 10 to 15 levels, depending on the combination of types being initiahzcd.
To correct this problem, simplify the data type being initialized to reduce the
levels of nesting, or assign initial values in separate statements after the
declaration.
The file being compiled contained too many symbols. Try to separate it into two
files that can be compiled independently.
The compiler ran out of storage for items that it stores in the "near" (default data
segment) heap.
The compiler ran out of storage for items that it stores in the far heap.
Usually this error occurs in programs compiled within the QuickC environment
because the symbol table contains too many symbols. To fix this error, try com-
piling with the Debug option turned off, or try including fewer include files. If
these solutions do not work, try compiling the program using the QCL com-
mand. Finally, it may help to free additional memory on your system by remov-
ing TSRs (processes that terminate and stay resident).
232 Microsoft QuickC Tool Kit
Nested blocks in the program exceeded the nesting limit allowed by the compiler.
To correct this problem, rewrite the program so that fewer blocks are nested
within other blocks.
You compiled with the /P, /E, or /EP option to produce a preprocessor output
file, but not enough room was available to hold the file.
Your program was too complex and caused the compiler stack to overflow.
Simplify your program by making it more modular and recompile.
The compiler read an identifier that is longer than the internal buffer used for
identifier names. Shorten the name and recompile.
The compiler cannot open the given file. A number of conditions may cause this
error, including (but not limited to) the following: the directory does not exist;
the file is needed for output but is marked read only; needed for input
the file is
but does not exist; the FILES= line in CONFIG.SYS does not allow enough files.
An error occurred while the compiler tried to write to the file. One possible
cause of this error is insufficient disk space.
The preprocessor found the #if, #ifdef, or #ifndef directive, but did not find a
corresponding #end if directive in the same source file.
The space allocated for the local variables of a function exceeded the given limit.
Error-Message Reference 233
Please report this condition to the Microsoft Corporation, using the Product As-
sistance Request form at the back of this manual.
The given identifier was used more than once in the formal-parameter list of a
macro definition,
The given character was used incorrectly in the formal-parameter list of a macro
definition.
The closing angle bracket (>) was missing from an #include directive.
Non- white-space characters appeared before the number sign (#) of a preproces-
sor directive on the same line.
The character or characters after the escape character (\) did not form a valid
escape sequence.
The given character followed a number sign (#), but it was not the first letter of a
preprocessor directive.
Error-Message Reference 235
The given character was not a legal digit for the base used,
The given character was used as the exponent of a floating-point constant but
was not a valid number.
C2023 divide by
C2024 mod by
The second operand in a remainder operation (%) evaluated to 0, giving unde-
fined results.
The given identifier had akeady been used for an enumeration, structure, or
union tag.
The given identifier has akeady been used for an enumeration constant, either
within the same enumeration type or within another enumeration type with the
same visibility.
Structure and union members must be declared within the structure or union.
enum a {
January,
february,
int march; /* structure declaration:
** illegal
V
};
The given structure or union member was declared with the near, far, or huge
keyword.
The given bit field was declared as a pointer (*), which is not allowed.
The number of bits specified in the bit-field declaration exceeded the number of
bits in the given base type.
The expression before the member-selection operator (->) was not a pointer to a
structure or union type, or the expression before the member-selection operator
(.) did not evaluate to a structure or union. In this message, member is a member
designator in one of the following forms:
—>identifier
. identifier
Both the signed and the unsigned keywords were used in a single declaration, as
in the following example:
A break statement is legal only within a do, for, while, or switch statement.
C2044 illegal continue
The label appeared before more than one statement in the same function.
An expression was illegal because of a previous error. (The previous error may
not have produced an error message.)
The identifier was not declared as a function, but an attempt was made to use it
as a function.
Error-Message Reference 239
An attempt was made to call a function through an expression that did not eval-
uate to a function pointer.
A function declaration appears within a block, but the function is not declared
extern. This causes an error if the /Za option is in effect, that is, when language
extensions are not enabled. The following example would cause this error:
main ()
The braces ({}) around the given array initializer were missing.
240 Microsoft QuickC Tool Kit
The braces ({ }) around the given structure or union initializer were missing.
The identifier was declared as structure or union type name, which has not been
defined.
The identifier was declared in a function definition but not in the formal parame-
ter Ust.
C2087 *
identifier* : missing subscript
The definition of an array with multiple subscripts was missing a subscript value
for a dimension other than the first dimension, as in the following example:
int func(a)
char a [10] [] /* Illegal */
{
Error-Message Reference 241
int func(a)
char a [ ] [ 5] ; /* Legal */
{
The given identifier referred to a structure or union type that was not defined.
Arrays of functions are not allowed; however, arrays of pointers to functions are
allowed.
The program tried to use the address of an automatic variable in the initializer of
a static item, as in the following example:
func
{
int i;
static int *ip=&i;
The function did not contain a statement labeled with the given identifier.
Formal parameters and arguments to functions cannot have type void; they can,
however, have type void * (pointer to void).
242 Microsoft QuickC Tool Kit
You cannot compare two structures or unions. (You can, however, compare in-
dividual members of structures and unions.)
The address -of operator (&) did not have an lvalue as its operand.
An attempt was made to subtract pointers that did not point to the same type.
The right operand in a subtraction operation (-) was a pointer, but the left oper-
and was not,
The left operand of the given operator was a pointer; the right operand must be
an integral value.
The left or right operand of the given operator was illegal for that operator.
C2117 *
operator^ : illegal for struct/union
Structure and union type values are not allowed with the given operator.
Two typedef types were used to declare an item and both typedef types had in-
direction. For example, the declaration of p in the following example is illegal:
The storage space required for the parameters to a function exceeded the limit
of32K.
C2130 #line expected a string containing the file name, found ^string*
More than one of the keywords near, far, or huge were applied to an item, as in
the following example:
An attempt was made to declare an unsized array as a local variable, as in the fol-
lowing example:
int array2 [ ]
/* Illegal */
The size of a structure or union exceeded the compiler limit (2^^ bytes).
;
long char a;
This message also appears if more than one enum, struct, or union type is used
in the same declaration,
An enumeration constant had a value outside the range of values allowed for
type int.
The compiler detected a token consisting of two periods ( .. ) and assumed that
an ellipsis (...) was intended.
The compiler expected token! to appear before tokeriZ. This message may ap-
pear if a required closing brace (}), right parenthesis 0). or semicolon (;) is
missing.
The compiler expected the given token to appear before the given type name.
This message may appear if a required closing brace (}), right parenthesis ()), or
semicolon (;) is missing.
246 Microsoft QuickC Tooi Kit
The compiler expected the given token to appear before an identifier. This mes-
sage may appear if a semicolon (;) does not appear after the last declaration of a
block.
The compiler expected the given token to appear before the given identifier.
The given named bit field had a zero width. Only unnamed bit fields are allowed
to have zero width.
C2150 identifier, bit-field must have type int, signed int, or unsigned int
The ANSI C standard requires bit fields to have types of int, signed int, or
unsigned int. This message appears only if you compiled your program with the
/Za option.
An attempt was made to assign a pointer to a function declared with one calling
convention (cdecl, fortran, or pascal) to a pointer to a function declared with a
different calling convention.
The hexadecimal constants Ox and OX are illegal. At least one hexadecimal digit
must follow the "x" or "X."
Certain pragmas must be specified at a global level, outside a function body, and
one of these pragmas occurred within a function.
Error-Message Reference 247
More than one storage class was given in a declaration, as in the following
example:
The token following a stringizing operator (#) was not a formal parameter name,
as in the following example:
The fortran, pascal, or cdecl keyword was used illegally to modify a pointer to
data, as in the following example:
An attempt was made to assign a value to an item declared with const storage
class.
The given unary operator was used with an illegal operand type, as in the follow-
ing example:
fp++;
d = ~dl
248 Microsoft QuickC Tool Kit
C2174 function : actual has type 'void' : parameter number^ parameter list number
The given function is not defined in the source file, or built into the QuickC pro-
gramming environment, or present in the Quick library (if any) that was loaded.
This error occurs only for single-module programs created in the QuickC en-
vironment. To solve this program, either define the function in the source file,
load a Quick library containing the function, or (if the function is a standard C
library function) create a program list for the program.
You cannot declare data items with the huge attribute in the QuickC environ-
ment Declare a huge pointer to the data item instead.
Information was lost because a constant value was too large to be replaced in the
type to which it was assigned.
The given option must be used when compiling the check_pointer pragma with
the QuickC compiler.
The given variable was declared with the void keyword. The void keyword can
be used only in function declarations.
The given interrupt function was implicitly or explicitly declared as near. You
must declare the function without the near attribute; furthermore, if you compile
the program with the small (default) or compact memory model, you must expli-
citly declare the function with the far attribute.
The given function was declared with the FORTRAN/Pascal calling conven-
tions, eitherbecause the fortran or pascal attribute was used in the declaration
or because the /Gc option was used at compile time. Functions declared with a
variable number of arguments or with the interrupt attribute must use the C cal-
ling conventions. To correct this error, either remove the pascal or fortran at-
tribute from the function declaration (if you compile without the /Gc option), or
declare the function with the cdecl attribute (if you compile with the /Gc option).
The #error directive was used to terminate compilation and display a message.
functyp foo
{
The given token caused a syntax error caused an error within the given context.
The register used within an indirect memory operand must be a base register in
this context.
The register used within an indirect memory operand must be an index register
in this context.
The register used within an indirect memory operand must be either a base or
index register in this context.
Short forward references must refer only to a label. An additional offset cannot
be used.
The identifier used with the SIZE or LENGTH operator, or as a specifier with the
member-selection operator (.), was not defined.
The first argument of the PTR operator was not a legal type specification.
The given identifier used with this context is not a member of a visible structure
or union; or the identifier is not a member of the structure or union specified
with the member-selection operator (.)
The given label was defined more than once within the current function. Change
the spelling of the label and its references.
The alignment size used with the ALIGN directive was either missing or outside
the valid range.
The second argument to the division (/) operator used within the given context
is zero.
252 Microsoft QuickC Tool Kit
The second argument to the MOD operator used within the given context is zero.
C2420 'identifier' : illegal symbol 'context'
The given token is used to form an improper expression within the given context.
The given token is used to form a nonconstant expression within the given
context.
The given token may not be used as an operator within the given context. For
example, array dimension tokens ([ ]) may not be nested.
message to appear.
Error-Message Reference 253
Please report this condition to Microsoft Corporation, using the Product As-
sistance Request form at the back of this manual.
The number of actual arguments specified with the given identifier was greater
than the number of formal parameters given in the macro definition of the
identifier. (1)
The number of actual arguments specified with the given identifier was less
than the number of formal parameters given in the macro definition of the
identifier. (1)
The closing parenthesis was missing from an #if defined phrase. (1)
The name of the identifier whose definition was to be removed was not given
with the #undef directive. (1)
Bit fields must be declared as unsigned integral types. The compiler converted
the given bit field accordingly. (1)
Bit fields must be declared as unsigned integral types. A conversion has been
supplied. (1)
The given function had not yet been declared or defined, so the return type was
unknown.
The number of arguments specified in a function call was less than the number
of parameters specified in the argument-type list or function definition. (1)
The pointer type of the given parameter was different from the pointer type
specified in the argument-type list or function definition. (1)
Error-Message Reference 255
The type of the given parameter in a function call did not agree with the type
given in the argument-type list or function definition. (1)
The function was declared to take arguments, but the function definition did not
declare formal parameters. (1)
The function was declared to take no arguments (the argument-type list con-
sisted of the word void), but formal parameters were declared in the function
definition, or arguments were given in a call to the function. (1)
The type of the given parameter did not agree withthe corresponding type in the
argument-type Ust or with the corresponding formal parameter. (1)
The argument-type list given in a function declaration did not agree with the
types of the formal parametcs given in the function definition. (1)
A function was declared more than once with different argument-type lists in the
declarations. (1)
A function was declared more than once with different argument-type lists. (1)
C4032 unnamed struct/union as parameter
The type of the structure or union being passed as an argument was not named,
so the declaration of the formal parameter cannot use the name and must declare
the type. (1)
The sizeof operator was applied to an operand that yielded a size of zero. (1)
int *f (a,b, c)
The given formal parameter was declared with a storage class other than auto or
register. (1)
The near, far, or huge keyword has no effect in the declaration of the given
identifier and is ignored. (1)
The given formal parameter was redefined in the function body, making the
The specified storage class cannot be used in this context (for example, function
parameters cannot be given extern class). The default storage class for that con-
text was used in place of the illegal class. (1)
Error-Message Reference 257
The compiler ignored the huge keyword on the specified identifier. Only arrays
may be declared huge. (1)
Too many initializers were present for the given array. The excess initializers are
ignored. (1)
An attempt was made to apply the address-of operator (&) to a function or array
identifier. (1)
char **p;
char *q;
p = q;
An array was declared twice with different sizes. The larger size is used. (1)
The indirection operator (*) was used in an expression to access values of differ-
ent types. (1)
Two data items in an expression had different types, causing the type of one
item to be converted. During the conversion, a data item was truncated. (2)
The program was compiled with the default data segment (DS) not equal to the
stack segment (SS), and the program tried to point to a frame variable with a
near pointer. (1)
The base types of the actual and formal arguments of a function were different.
The actual argument is converted to the type of the formal parameter. (1)
The pointer sizes of the actual and formal arguments of a function were differ-
ent. The actual argument is converted to the type of the formal parameter. (1)
#endif NO_EXT_KEYS
This is accepted in some versions of the Microsoft C Compiler, but not in Ver-
sion 2.0 of the Microsoft QuickC Compiler. (1)
The compiler has converted a 16-bit near pointer to a long integer, which in-
volves first extending the high-order word with the current data-segment value,
not 0.(1)
The given function was called before the compiler found the corresponding func-
tion prototype. (3)
Note that although C4071 is a level 3 warning, the compiler issues it any time
you compile with the /Gi option but omit function prototypes.
Error-Message Reference 259
The given nonstandard language extension was used when the Language Exten-
sions option in the Compile dialog box was turned off, or when the /Ze option
was in effect. (If the /Za option is in effect, this condition generates an error.) (3)
C4075 size of switch expression or case constant too large - converted to int
A value appearing in a switch or case statement was larger than an int type. The
compiler converts the illegal value to an int type. (1)
The signed or unsigned type modifier was used with a nonintegral type. (1)
unsigned double x;
In the old form of the check_stack pragma, the argument to the pragma must be
empty, +, or-. (I)
An opening left parenthesis was missing from the argument Ust for a pragma. (1)
The token following the keyword pragma was not an identifier. (1)
#pragma (on)
260 Microsoft QuickC Tool Kit
An invalid argument was given for the new form of the checkstack pragma, (1)
C4086 expected [1 1
2 | 4]
The given function was declared as taking no parameters, but a call to the func-
tion specified actual parameters, as in the following example (1):
int f 1 (void)
fl (10)
The nth argument in the given function call has a different level of indirection,
as in the following example (1):
main (
The argument in the given function call did not have the same type as the argu-
ment in the function prototype, as in the following example (1):
main (
Int i;
( *sample (10, 20) ) (i) ; /* pointer mismatch parameter 1,
parameter list 2. */
A pointer to an item declared as const was passed to a function where the corre-
sponding formal parameter was a pointer to a non-const item. This means the
item could be modified by the function undetected. (1)
str (p)
int ;
struct {
};
evaluated to 0, making the following code inactive, and a new-line character ap-
peared between a single or double quotation mark and the matching single or
double quotation mark in that inactive code. (3)
More than one argument appeared for a pragma that takes only one argument. (1)
262 Microsoft QuickC Tool Kit
A function declared with a void return type also returned a value, as in the fol-
lowing example (1):
void func ()
return (10)
}
The given formal parameter was never referenced in the body of the function for
which it was declared. (3)
The given modifier was used to declare something other than a function or func-
tion pointer. (1)
You assigned a function pointer to a function pointer, but the parameter lists of
the functions do not agree, as in the following example (1):
sample = example;
}
The directive does not take any operands; however, an operand was specified. (1)
The label referenced was ambiguous. This warning occurs when a label is de-
fined twice in C source code with the same spelling but different capitalization
and then referenced in in-line assembler. (1)
The instruction does not have a form with the specified size. (1)
The identifier is a local symbol that resolves to a displacement register and there-
fore may be used on an operand with another symbol. (1)
main ()
fund 0;
int fund ()
If you compile this program with the /Gi option, then change the definition of
fund long fund, the compiler issues this waring message
to to let you
know that calls to f unc 1 may be of the wrong type.
You should be sure that the function calls reference the correct type; if not, re-
Table D.l summarizes the limits imposed by the QuickC compiler. If your pro-
gram exceeds one of these limits, an error message will inform you of the
problem.
The compiler does not set explicit limits on the length of a string or on the num-
ber and complexity of declarations, definitions, and statements in an individual
function or in a program. If the compiler encounters a function or program that is
Please report this condition to Microsoft Corporation, using the Product As-
sistance Request form at the back of this manual.
Too many symbolic constants were defined by using the /D option on the com-
mand line.
The normal limit on command-line definitions is 15; you can use the /U or /u op-
tion to increase the limit to 20.
Two different memory models were specified; the model specified later on the
command line was used.
Too many letters were given with the specified option (for example, with the /O
option).
268 Microsoft QuickC Tool Kit
You specified more than one floating-point (/FP) option on the command line.
You tried to pass more than 128 separate options and object files to the linker.
You gave a file name with an extension of .ASM on the command line.
Because the compiler cannot invoke the Microsoft Macro Assembler (MASM)
automatically,it cannot assemble such files.
This error may have occurred because another read-only file had the same name
as the response file.
The compiler does not allow the source file to be overwritten by one of the com-
piler output files.
The /Gc option and the /Za option were specified on the same command line.
The /Gc option requires the extended keyword cdecl to be enabled if library
functions are to be accessible.
The /HELP option was given, but the file containing the help messages
(QCL.HLP) was not in the current directory or in any of the directories specified
by the PATH environment variable.
Error-Message Reference 269
The compiler could not find the given file in the current working directory or in
any of the other directories named in the PATH variable.
No more file handles were available to redirect the output of the /P option to
a file.
Try editing your CONFIG.SYS file and increasing the value num on the line
f iles=nMm (i( num is less than 20).
Please report this condition to Microsoft Corporation, using the Product As-
sistance Request form at the back of this manual.
One of the options given on the command line was not recognized and is ignored.
Both the /GO option and the /G2 option were given; /G2 takes precedence.
The QCL command could not find the specified executable file in the
search path.
The /C option must be used in conjunction with one of the preprocessor output
flags,/E,/EP,or/P.
270 Microsoft QuickC Tool Kit
The /Gt option was used in a memory model that has near data pointers. It can
be used only in compact, large, and huge models.
When /Fc is specified along with either /Fl or /Fa, the combined listing (/Fc) is
created.
An invahd value was given in a context where a particular numeric value was
expected.
Error-Message Reference 271
Using C's default 8087/80287 control- word settings, the following exceptions
are masked and do not occur:
The following errors do not occur with code generated by the Microsoft QuickC
Compiler or provided in the standard C library:
Square root
Stack underflow
Unemulated
272 Microsoft QuickC Tool Kit
M6101 invalid
M6102 denormal
A very small floating-point number was generated and may no longer be valid
due to loss of significance. Denormals are normally masked, causing them to be
trapped and operated on. This error terminates the program with exit code 130.
M6103 divide by
An attempt was made to divide by 0. This error terminates the program with exit
code 131.
M6104 overflow
M6105 underflow
M6106 inexact
M6107 unemulated
The operand in a square-root operation was negative. This error terminates the
program with exit code 136. (Note: the sqrt function in the C run-time library
checks the argument before performing the operation and returns an error value
if the operand is negative; see the on-line help for details on sqrt.)
Your program has run out of stack space. This can occur when a program uses a
large amount of local data or is heavily recursive. The program was terminated
with an exit code of 255.
To correct the problem, recompile using the /F option of the QCL command, or
relink using the linker /STACK option to allocate a large stack.
274 Microsoft QuickC Tool Kit
The contents of the NULL segment have changed in the course of program ex-
ecution. The NULL segment is a special location in low memory that is not nor-
mally used. If the NULL segment change during a program's
contents of the
execution, it means program has written to this area, usually by an inad-
that the
vertent assignment through a null pointer. Note that your program can contain
null pointers without generating this message; the message appears only when
you access a memory location through the null pointer.
This error does not cause your program to terminate; the error message is printed
following the normal termination of the program. This error yields a nonzero
exit code.
Your program needs the floating-point library, but the library was not loaded.
The error causes the program to be terminated with an exit code of 255. This oc-
curs in two situations:
The program was compiled or linked with an option (such as /FPi87) that re-
quired an 8087 or 80287 coprocessor, but the program was run on a machine
that did not have a coprocessor installed. To fix this problem, either recom-
pile the program with the /FPi option or install a coprocessor.
A format string for one of the routines in the printf or scanf families con-
tains a floating-point format specification and there are no floating-point
values or variables in the program. The QuickC compiler attempts to min-
imize the size of a program by loading floating-point support only when nec-
essary. Floating-point format specifications within format strings are not
detected, so the necessary floating-point routines are not loaded. To correct
use a floating-point argument to correspond to the floating-point
this error,
format specification. This causes floating-point support to be loaded.
Errors R6005 through R6007 occur when a child process spawned by one of the
exec Ubrary routines fails and DOS could not return control to the parent
process. This error indicates that not enough memory remained to load the pro-
gram being spawned.
The file to be executed by one of the exec functions was not in the correct for-
mat for an executable file.
During a call to one of the exec functions, DOS determined that the child
process was being given a bad environment block.
Errors R6(X)8 and R6(X)9 both occur at start-up if there is enough memory to
load the program, but not enough room for the argv vector, the envp vector, or
both. To avoid this problem, rewrite the _setargv or _setenvp routine.
This error occurs only if pointer checking is in effect (that is, if the program was
compiled with the Pointer Check option in the Compile dialog box, the /Zr op-
tion on the QCL command line, or the pointer_check pragma in effect).
You pressed ctrl+break to stop the execution of a program within the QuickC
environment.
276 Microsoft QuickC Tool Kit
When you create a program from a program list in the QuickC environment,
QuickC automatically creates object files and passes them to the linker. If you
compile with the Debug option turned on, the object files that QuickC passes to
the linker contain interrupts that are required within the QuickC environment.
However, you cannot run a program created from such object files outside of the
QuickC programming environment.
^32
Files Maximum file size 2 -1 bytes (4 gigabytes)
Maximum number of
open files (streams)
* Five streams are opened automatically (stdin, stdout, stderr, stdaux, and stdprn), leaving 15 files
available for the program to open.
Error-Message Reference 277
Fatal errors cause the linker to stop execution. Fatal error messages have the fol-
lowing format:
Nonfatal errors indicate problems in the executable file. LINK produces the ex-
ecutable file. Nonfatal error messages have the following format:
Nonfatal errors generated by the incremental linker are numbered from LI 250
toL1299.
Warnings indicate possible problems in the executable file. LINK produces the
executable file. Warnings have the following format
Warning numbers less than L4200 apply to LINK. Those numbers greater than
L4200 apply to the incremental linker.
In all three kinds of messages, location is the input file associated with the error,
or LINK if there is no input file. If the input an .OBJ or .LIB file, and a
file is
module name is associated with the error, the module name is enclosed in
parentheses, as shown in the following examples:
SLIBC.LIB(_file)
MAIN. OBJ (main. c)
TEXT. OBJ
The following error messages may appear when you link object files:
An incorrect value appeared for one of the linker options. For example, a
character string was given for an option that requires a numeric value.
The value supplied with the /PACKCODE option exceeds the limit of 65,536
bytes.
The value given as a parameter to the /STACKSIZE option exceeds the maxi-
mum allowed.
L1007 option : interrupt number exceeds 255
A number greater than 255 was given as a value for the /OVERLAYINTER-
RUPT option.
L1008 option : segment limit set too high
The /SEGMENTS option specified a limit greater than 3072 on the number of
segments allowed.
The number specified in the /CPARMAXALLOC option was not in the range
1-65,535.
More than 32,768 long calls, long jumps, or other long pointers appeared in the
program.
Try replacing long references with short references where possible, then recreate
the object module.
An object module specified more than the limit of 1023 external symbols.
L1047 too many group, segment, and class names in one module
Reduce the number of groups, segments, or classes, and recreate the object file.
280 Microsoft QuickC Tool Kit
Reduce the number of group definitions or split the module. (Group definitions
are explained in the Microsoft MS-DOS Programmer' s Reference and in other
reference books on DOS.)
The program had more symbolic information (such as public, external, segment,
group, class, and file names) than could fit in available memory.
Try freeing memory by linking from the DOS command level instead of from an
NMAKE file or an editor. Otherwise, combine modules or segments and try to
eliminate as many public symbols as possible.
Error-Message Reference 281
The linker did not have enough memory to allocate tables describing the number
of segments requested. (The default is 128 or the value specified with the
/SEGMENTS option.)
Try linking again by using the /SEGMENTS option to select a smaller number
of segments (for example, use 64 if the default was used previously), or free
some memory by eliminating resident programs or shells.
A LEDATA record (in an object module) contained more than 1024 bytes of
data. This is a translator error. (LEDATA is a DOS term, which is explained in
the Microsoft MS-DOS Programmer' s Reference and in other DOS reference
books.)
If you were linking from within an editor or NMAKE, try linking directly.
The linker was given too many object files with debug information, and the
linker ran out of space to store the debug information.
The program had more than 64K of communal variables. This error occurs only
with programs produced by the Microsoft FORTRAN Compiler or other com-
pilers that support communal variables.
The number of physical segments exceeds the limit of 254 imposed when link-
ing incrementally.
Reduce the number of segments or group more of them, and use the
/PACKCODE option.
L1074 name group larger than 64K bytes
:
Reduce the size of the group, or remove any unneeded segments from the group
(refer to the map file for a listing of segments).
The disk on which the .EXE file was being written was full.
The linker cannot find the special stub file that is required for incremental link-
ing under QuickC. The given file must be on the current path or in the current
directory. For QuickC, the special stub file is named ILE^IKSTB.OVL, and it is
shipped as part of the QuickC package.
Note the circumstances of the problem and contact Microsoft Corporation using
the Microsoft Product Assistance Request form at the back of one of your
manuals.
The disk (where the listing file was being written) is full.
LINK could not find the specified response file. This usually indicates a typing
error.
284 Microsoft QuickC Tool Kit
Replace the disk containing the library and run the linker again.
One of the object files specified in the linker input was not found.
The linker was unable to open the file with write permission.
The linker ran out of disk space for the specified output file.
The special stub file ILINKSTB.OVL, which is required for incremental linking
with QuickC, has somehow become corrupted and is not a valid DOS execut-
able file.
A data record in an object module specified data extending beyond the end of a
segment. This is a translator error.
The specified file was not a valid library file. This error causes LINK to abort.
L1105 invalid object due to aborted incremental compile
The object file is incomplete, and therefore cannot be linked, because an error oc-
curred during the incremental compile.
You defined the same segment with the use32 attribute in one module and with
the use 16 attribute in another module.
run-time relocations. For example, the following code causes this error:
The disk is full or the .SYM file ah^ady exists and has the READONfLY
attribute.
A FIXUPP object record with the given location referred to a target too far away
to be correctly processed. This message indicates an error in translation by the
compiler or assembler.
Recompile without the /Gi or /Li option; or use LINK directly to perform a
full link.
If the error persists, note the circumstance of the error and notify Microsoft Cor-
poration by following the directions in the Microsoft Product Assistance Request
form at the back of one of your manuals.
The .ILK file is too large for the incremental linker to process.
Recompile without the /Gi or /Li option or use LINK directly to perform a
full link.
To correct the problem, do a full (not incremental) link of the program. If the
error persists, contact Microsoft using one of the Product Assistance Request
forms at the back of a manual.
1
Try to rebuild the .OBJ file by recompiling without the /Gi or /Li option.
Note the circumstance of the failure and notify Microsoft Corporation by follow-
ing the directions in the Microsoft Product Assistance Request form at the back
of one of your manuals.
288 Microsoft QuickC Tool Kit
The segment-sector alignment value in the .EXE file is too small to express the
size of one of the segments.
Recompile without the /Gi or /Li option, or use LINK directly to perform a full
link. You may also need to increase the alignment value with the /ALIGNMENT
option to LINK.
The operating system returned an error when the linker attempted to close one of
the hbraries (.LIB files).
Do a full link. If the error persists, note the circumstance of the failure and notify
Microsoft Corporation by following the directions in the Microsoft Product As-
sistance Request form at the back of one of your manuals.
The operating system returned an error when ILINK attempted to update the
time on the given file. Possibly the file had the READONLY attribute set.
L1224 invalid flag cliaracter
You pressed CTRL+C or CTRL+BREAK, which interrupts and terminates the linker.
be read or found.
The given .OBJ file has an invalid format or one that is not recognized by the
linker.This message may indicate an error in translation by the compiler or
assembler.
You specified an .OBJ file in the ILINK command hne that was not in the list of
files in the most recent full link.
Make sure the program is in the search path and is an .EXE or .COM file.
L1233 program returned return-code
The given program was specified with the /e option. When ILINK executed this
program, it terminated with the given nonzero return code. ILINK cannot con-
tinue to the next commands, if any.
ILINK was unable to create the batch file for executing the /e commands.
Make sure the directory given in TMP or TEMP, or the current directory, exists
and can be written to.
ILINK experienced an error while writing the batch file for executing the /e
commands.
Make sure the drive for TMP or TEMP or the current drive has enough free
space.
290 Microsoft QuickC Tool Kit
Change your code to get rid of the far address within the STRUC. Alternatively,
do not attempt to incrementally Unk.
Reduce the number of segments and relink. Alternatively, do not use the A-i or
/Gi option.
ILINK cannot handle programs linked with the /EXEPACK linker option.
L1250 number undefined symbols
A number of symbols were referred to in fixups but never publicly defined in the
program. The given number indicates how many of these undefined symbols
were found.
The segment contribution changed for the given module; it contributed to a seg-
ment to which it did not previously contribute, or a segment contribution was
removed.
The given segment grew beyond the padding for the given module.
A symbol that was previously a code symbol became a data symbol or vice versa.
L1263 new Codeview symbolic info
A module previously compiled without /Zi or fZd was compiled with /Zi or /Zd.
292 Microsoft QuickC Tool Kit
The .ILK file is invalid. Make sure you are using an up-to-date linker.
The .S YM and .ILK files are out of sync. Make sure you are using an up-to-
date linker. If the error persists, note the circumstance of the failure and notify
Microsoft Corporation by following the directions in the Microsoft Product As-
sistance Request form at the back of one of your manuals.
The program call tree changed in such a way that ILINK could not process it
correctly.
The given segment, referred to by its index within the program's segment table,
is too big along with its run-time relocations for ILINK to process the segment
correctly.
The .ILK file does not exist or was not in the expected format.
Error-Message Reference 293
If you are linking incrementally from within an NMAKE description file, try
A FIXUPP record occurred without a data record immediately preceding it. This
isprobably a compiler error. (See the Microsoft MS-DOS Programmer' s Refer-
ence for more information on FIXUPP.)
The name of a data item in the program conflicts with that of a library sub-
routine included in the hnk.
Revise the source file and re-create the object file. (For information about frame
and target segments, see the Microsoft MS-DOS Programmer' s Reference.)
294 Microsoft QuickC Tool Kit
A fixup type occurred that is not supported by the Microsoft linker. This is prob-
ably a compiler error.
Note the circumstances of the failure and contact Microsoft Corporation using
the Microsoft Product Assistance Request form at the back of one of your
manuals.
A far communal array was declared with two or more different array-element
sizes (for instance, an array was declared once as an array of characters and once
as an array of real numbers). This error occurs only with the Microsoft FOR-
TRAN Compiler and any other compiler that supports far communal arrays.
L2013 LIDATA record too large
A LIDATA record contained more than 512 bytes. This is probably a compiler
error.
Your program defined a symbol name already used by the linker for one of its
own low-level symbols. (For example, the linker generates special symbols used
in overlay support and other operations.)
When creating a Quick hbrary, you did not link with the required QUICK-
LIB. OBJ object module.
L2045 segname : segment with >1 class name not allowed with /INC
When linking incrementally, segments cannot be defined with more than one
class. The following segment definition causes this error:
This is the warning generated by the AVARNFIXUP option. See Section 5.5.6,
"Fixups," for more information.
A reference is made relative to a segment that is different from the target seg-
ment of the reference. For example, if _f oo is _TEXT, the
defined in segment
instruction call DGROUP :_f oo produces this The frame DGROUP
warning.
is ignored, so the linker treats the call as if it were call _TEXT :_f oo.
are absolute (defined with AT). The linker treats the executable file as if the file
were to run in real mode only.
The linker found an intersegment self-relative fixup. This error may be caused
by compiling a small-model program with the /NT option.
The given option does not apply to real-mode executable files, so the linker
ignored it.
Reorganize segments and group definitions so that the groups do not overlap.
Refer to the map file. Normally this message applies only to OS/2 and Windows
programs. If you receive this message when linking a DOS file, the incremental
linker is probably being used because you specified either /Gi or /Li on the QCL
command line. Unless you change your program as instructed above, you cannot
link incrementally.
The given logical segment in the group DGROUP was defined as a code seg-
ment. (DGROUP cannot contain code segments because the linker always con-
sidersDGROUP to be a data segment. The name DGROUP is predefined as the
automatic data segment.) The linker converts the named segment to type "data."
298 Microsoft QuickC Tool Kit
The given code group has a size between 65,500 and 65,536 bytes, a size that is
unreliable on some steppings of the 80286 processor.
The application did not define a group named DGROUP. DGROUP has special
meaning to the linker, which uses it to identify the automatic or default data seg-
ment used by the operating system. Most OS/2 protected-mode and Windows ap-
plications require DGROUP. This warning is not issued if DATA NONE is
declared or if the executable file is a dynamic-link library.
If you get this message when linking a DOS program, the incremental linker is
probably being used. If you are using the QCL command, try omitting the /Gi
and /Li options.
Ifyou get this message when linking a DOS program, the incremental linker is
probably being used. Try compiling with neither the /Gi nor /Li option.
VM.TMP appeared as an object-file name. This is the name the linker uses for
its temporary file.
The free list in the .EXE file has been corrupted. The free list represents "holes"
in the .EXE file made available when segments moved to new locations.
The program starting address changed. You may want to consider doing a
full link.
300 Microsoft QuickC Too! Kit
The page size of an input library was too small, which indicates an invalid input
.LIB file.
A command operator such as a minus sign (-) was given without a following
module name.
The given command did not follow correct LIB syntax as specified in Chapter 6,
"LIB."
U 1 1 56 sy n tax error
The given command did not follow correct LIB syntax as specified in Chapter 6,
"LIB."
;
Either the response to the "Output library" prompt or the last Une of the response
file used to start LIB did not end with a carriage return.
LIB couldnot rename the old library to have a .BAX extension because the
.BAK version already existed with read-only protection.
Change the protection on the old .BAK version.
The old library could not be reopened after it was renamed to have a ,B AK
extension.
Remove any shells or resident programs and try again, or add more memory.
Note the circumstances of the failure and notify Microsoft Corporation by using
the Microsoft Product Assistance Request form at the back of one of your
manuals.
Note the circumstances of the failure and notify Microsoft Corporation by using
the Microsoft Product Assistance Request form at the back of one of your
manuals.
Note the circumstances of the failure and notify Microsoft Corporation by using
the Microsoft Product Assistance Request form at the back of one of your
manuals.
The disk or root directory was full, or the specified extract file already existed
with read-only protection.
Make space on the disk or change the protection of the extract file.
The disk or root directory was full, or the library file akeady existed with read-
only protection.
Make space on the disk or change the protection of the library file.
Error-Message Reference 303
The input library file had an invalid format. It was either not a library file, or it
The directory or disk, was full, or the cross-reference-listing file already existed
with read-only protection.
The signature byte or word hexnumber of the given file was not one of the fol-
lowing recognized types: Microsoft library, Intel library, Microsoft object, or
XENIX archive.
A module was specified to be added to a library, but a module with the same
name was already in the library, or a module with the same name was found
more than once in the hbrary.
The value specified in the /PAGESIZE option was less than 16.
A module specified to be replaced does not already exist in the library. LIB adds
the module anyway.
An output library was specified in addition to a new library name. For example,
specifying
A single dollar sign ($) appeared without a macro name associated with it. The
correct form is ${name). To use a dollar sign in the file, type it twice or precede
it with a caret (^).
The equal sign (=) was missing in a macro definition. The correct form is
'name= value'.
An opening double quotation mark (") appeared without a closing double quota-
tion mark.
An !ELSE directive was found that was not preceded by !IF, IIFDEF, or
IIFNDEF, or was placed in a syntactically incorrect place.
The closing double quotation mark (") in a string comparison in a directive was
missing, or the closing bracket (]) in a program invocation in a directive was
missing.
An include directive was found, but the name of the file to include was missing.
The specified string is not part of the valid syntax for a makefile.
Either a colon (:), implying a dependency line, or an equal sign (=), implying a
macro definition, was expected.
Error-Message Reference 307
Note the circumstances of the failure and notify Microsoft Corporation by using
the Microsoft Product Assistance Request form at the back of one of your
manuals.
Note the circumstances of the failure and notify Microsoft Corporation by using
the Microsoft Product Assistance Request form at the back of one of your
manuals.
Note the circumstances of the failure and notify Microsoft Corporation by using
the Microsoft Product Assistance Request form at the back of one of your
manuals.
Note the circumstances of the failure and notify Microsoft Corporation by using
the Microsoft Product Assistance Request form at the back of one of your
manuals.
Note the circumstances of the failure and notify Microsoft Corporation by using
the Microsoft Product Assistance Request form at the back of one of your
manuals.
Note the circumstances of the failure and notify Microsoft Corporation by using
the Microsoft Product Assistance Request form at the back of one of your
manuals.
Note the circumstances of the failure and notify Microsoft Corporation by using
the Microsoft Product Assistance Request form at the back of one of your
manuals.
308 Microsoft QuickC Tool Kit
Note the circumstances of the failure and notify Microsoft Corporation by using
the Microsoft Product Assistance Request form at the back of one of your
manuals.
The file was not found. The file name might not be properly specified in the
makefile.
The file cannot be read. The file might not have the appropriate attributes for
reading.
A circular dependency was detected in the dependency tree for the specified tar-
get. This is invalid.
A circular inclusion was detected in the include files specified. That is, each file
includes the other.
The macro name, target name, or build-command name would overflow an inter-
nal buffer. Macro names may be at most 128 characters.
The given program invoked from NMAKE failed, returning the error code value.
U1078 constant overflow at ^directive*
NMAKE could not find the given program in order to run it.
Make sure that the program is in the current path and has the correct extension.
NMAKE cannot execute the given command because there is not enough
memory available.
Free some memory and run NMAKE again.
A regular target was specified along with the target for a rule (which has the
form fromext.toext). This is invalid.
A target cannot have both a single-colon (:) and a double-colon (::) dependency.
U1088 invalid separator on inference rules: '::'
An inference rule cannot have more than one pair of extensions (fromext.toext)
as a target.
Error-Message Reference 311
The name by which this program was invoked is not a tagged section in the
TOOLS.INI file.
There are no file names that match the specified target or dependent file with the
wild-card characters asterisk (*) and question mark (?).
Multiple blocks of build commands are specified for a target using single colons
(:) as separators.
The rule was ignored because the suffix(es) in the rule are not listed in the
.SUFFIXES list.
The base name of the file has more than eight characters or the extension has
more than three characters. NMAKE truncates the name to an eight-character
base and a three-character extension.
Execution of NMAKE was interrupted while it was trying to build the given tar-
get, and therefore the target was incomplete. Because the target was not
specified in the .PRECIOUS list, NMAKE has deleted it.
312 Microsoft QuickC Tool Kit
The correct form is /Rvalue, where value specifies the amount of compression
requested.
The /S option requires specification of the type of input file. There was an in-
valid file-type identifier specified.
The correct form is /Sfiletype, -whe^re filetype specifies theformat of the input
help text file. The only valid values are 1 (RTF), 2 (QuickHelp format), and 3
(minimally formatted ASCII).
The /S option requires specification of the type of input file. There was no file-
The correct form is /Sfiletype, where filetype specifies the format of the input
help text file. The only valid values are 1 (RTF), 2 (QuickHelp format), and 3
(minimally formatted ASCII).
The /O, /L, and /C options are invalid with the /DS option.
Error-Message Reference 313
One of the files specified on the HELPMAKE command line could not be found
or created.
The output file could not be written, probably because the disk is full.
The input file specified for a decompression operation is not a valid help data-
base file.
The help data-base file you are attempting to decompress is locked (that is, the
/L option was specified when the help file was created).
A line exceeded the fixed width specified by the /W option. The extra characters
have been truncated.
The same context string appeared preceding more than one block of topic text. A
context string may be associated with one and only one block of topic text.
This error occurs in conjunction with HELPMAKE error H400L The maximum
number (16,000) of unique keywords has been encountered during keyword com-
pression. This happens only in very large help files. No further keywords will be
included in the analysis.
The definitions in this glossary are intended primarily for use with this manual. Neither
individual definitions nor the list of terms is comprehensive.
8087 or 80287 coprocessor Intel® hardware products that provide very fast and precise floating-
point number processing.
ANSI (American National Standards Institute) The national institute responsible for defining
programming-language standards to promote portability of these languages between different
computer systems.
argument A value passed to a function. In the QuickC Tool Kit, a string or value that modifies
the effects of a compiler, linker, or utihty option.
ASCII (American Standard Code for Information Interchange) A set of 256 codes that many
computers use to represent letters, digits, special characters, and other symbols. Only the first
128 of these codes are standardized; the remaining 128 are special characters that are defined
by the computer manufacturer.
base name The portion of the file name that precedes the file-name extension. For example,
samp is the base name of the file samp , c.
batch file A text file containing DOS commands that can be invoked from the DOS com-
mand line.
block A sequence of declarations, definitions, and statements enclosed within braces ({ }).
canonical frame number Part of the starting address for a segment. The canonical frame number
specifies the address of the first paragraph in memory that contains one or more bytes of the
segment.
constant expression Any expression that evaluates to a constant. A constant may involve in-
teger constants, character constants, floating-point constants, enumeration constants, type
casts to integral and floating-point types, and other constant expressions.
context A key word or phrase that is recognized by the help system and that defines a topic.
cross-reference A string of text that is associated with a hyperlink or location in the displayed
help text. When activated, the cross-reference string may reference another help context or
another help file.
318 Microsoft QuickC Tool Kit
declaration A construct that associates the name and the attributes of a variable, function, or type.
decoding The process of decompressing a help-data-base file into its component parts, thereby
creating one or more QuickHelp text files.
definition A construct that initializes and allocates storage for a variable or that specifies the
name, formal parameters, body, and the return type of a function.
dependency line A line in an NMAKE description file that defines one or more targets and the
files they depend on.
description block A dependency Une in an NMAKE description file and all the statements (com-
mands, comments, and directives) that apply to it.
description file The text file that NMAKE reads to determine what to do. A description file is
also called a makefile.
encoding The process of compressing a help text file into a help data base.
environment variable A variable stored in the environment table that provides DOS with infor-
mation (where to find executable files and library files, where to create temporary files, etc.).
escape character A character that, when used immediately preceding a special character, causes
the special character to lose its special meaning.
executable image The code and data that make up an executable file; that is, a compiled, linked
program that DOS can execute.
exit code A code returned by a program to DOS indicating whether the program ran successfully.
function A collection of declarations and statements that has a unique name and can return a
value.
function body A statement block containing the local variable declarations and statements of a
function.
function call An expression that passes control and arguments (if any) to a function.
Glossary 319
function declaration A declaration that establishes the name, return type, and storage class of a
function that is defined explicitly elsewhere in the program.
function definition A definition that specifies a function's name, its formal parameters, the
declarations and statements that define what it does, and (optionally) its return type and
storage class.
function prototype A function declaration that includes a list of the names and types of formal
parameters in the parentheses following the function name.
global region The area of a source file between the beginning of the file and the first curly brace
of a function, or between the ending curly brace of a function and the beginning curly brace of
another function. If no edits have occurred within a global region, incremental compilation is
usually possible.
help screen An application window that displays information on a single topic. The help screen
can be sized and may be scrolled onto additional topics.
huge memory model A memory model that allows for more than one code segment. Individual
data items may exceed 64K in length
hyperlink A location in the topic text of an on-line-help file to which a cross-reference has been
attached.
include file A text file that is merged into another text file through use of the #include preproces-
sor directive.
incremental compilation The compilation mode, specified by the /Gi option to the QCL com-
mand, in which only changed functions are recompiled.
inference rule A template that the NMAKE utility follows to update a target in the absence of ex-
plicit commands.
keyword A word with a special, predefined meaning for the QuickC compiler.
large memory model A memory model that allows for more than one segment of code and more
than one segment of data, but with no individual data items spanning a single segment.
library A file containing compiled modules. Also called an object-code library. The linker ex-
tractsmodules from the library and combines them with object files to create executable pro-
gram files. A load library is a library specified in the object-files field as input to the linker.
The linker links every module in a load library into the executable file.
load-time-relocation table A table of references, relative to the start of the program, that are
resolved when the program is loaded into memory.
loop optimization Optimization that reduces the amount of code executed for each loop iteration
in a program, thereby increasing the speed with which the loop executes.
320 Microsoft QuickC Tool Kit
lvalue An expression (such as a variable name) that refers to a memory location and is required
as the left-hand operand of an assignment operation or as the single operand of a unary
operator.
medium memory model A memory model that allows for more than one code segment and only
one data segment.
module-description table (M DT) A file created or updated during incremental compilation that
saves information about changes to a source file.
NAN (Not a number) The 8087 or 80287 coprocessor generates NANs when the result of an
operation cannot be represented in the IEEE format. For example, if you try to add two posi-
tive numbers whose sum is larger than the maximum value permitted by the processor, the co-
processor returns a NAN instead of the sum.
new-line character The character used to mark the end of a line in a text file, or the escape
sequence (\n) used to represent this character.
null character The ASCII character encoded as the value 0, represented as an escape sequence
(\0) in a source file.
object file A file containing relocatable machine code, created as the result of compiling a
source file.
object module A component of a library. An object file becomes an object module when it is
loaded into a library.
overlay Part of a program that is read into memory from disk only if and when it is needed.
parent process A process that generates a child process using one of the spawn, exec, or system
families of run-time-library functions.
Glossary 321
precedence The relative position of an operator in the hierarchy that determines the order in
which expressions are evaluated.
preprocessor A text processor that manipulates the contents of a C source file during the first
phase of compilation.
pseudotarget A target, in an NMAKE description file, that is not a file but is used as a label for
performing a set of commands.
QCL The command that invokes the Microsoft QuickC Compiler to compile and link programs.
QuickHelp An ASCII text format that supports implicit cross-references, hyperlinks, and screen
formatting flags for input to a help data base.
relocatable Not containing absolute addresses; therefore, eligible to be placed in memory at any
location.
response file A file that contains command-line arguments or responses to program prompts. Re-
sponse files may be used as input to LINK, LIB, and NMAKE.
RTF (Rich Text Format) An ASCII text format for storing documents and their format
information.
run time The time during which a previously compiled and linked program is executing.
run-time library A file containing the routines needed to implement certain functions of the
Microsoft QuickC language.
scope The parts of a program in which an item can be referenced by name. The scope of an item
may be limited to the file, function, block, or function prototype in which it appears.
segment An area of memory, less than or equal to 64K long, that contains code or data.
small memory model A memory model that allows for only one code segment and only one data
segment.
stack probe A short routine called on entry to a function to verify that there is enough room in
the program stack to allocate local variables required by the function and, if so, to allocate
those variables.
static A storage class that allows variables to keep their values even after the program exits the
block in which the variable is declared.
322 Microsoft QuickC Tool Kit
string constant A string of characters and escape sequences enclosed in double quotation marks
(" "). Every string constant is an array of elements of type char,
type cast An operation in which a value of one type is converted to a value of a different type.
type checking An operation in which the compiler verifies that the operands of an operator are
valid or that the actual arguments in a function call arc of the same types as the corresponding
formal parameters in the function definition and function prototype.
type declaration A declaration that defines the name and members of a structure or union type,
or the name and enumeration set of an enumeration type.
unary operator An operator that takes a single operand. Unary operators in the C language are
the complement operators (- " !), indirection operator (*), increment (++) and decrement
(- -) operators, addrcss-of operator (&), and sizeof operator. The unary plus operator (+) is
legal but has no effect.
unresolved reference A
reference to a global or external variable or function that cannot be
found, either in the modules being linked or in the libraries that are linked with those modules.
wild card One of the DOS characters (? and *) that can be expanded into one or more characters
in file-name references.
Index 323
LIB command symbol, 33, 143, 145, 150-151 HELPMAKE special character, 189
LINK command symbol, 111,114,116 NMAKE special character, 50, 161, 163
; (semicolon)
LIB command symbol, 142, 147
LINK command symbol, 1 12, 1 14-1 15
B
NMAKE command separator, 42, 160 /BA option (LINK), 25, 121
Backslash (\), NMAKE continuation character, 41, 157
80286 processor, 18,84 Batch files, exit codes, 201
8087/80287 coprocessor, suppressing use of, 18, 83 BEGDATA class name, 124
/BI option (LINK), 122
324 Microsoft QuickC Tool Kit
(NMAKE)
Directives warning, 226
ICMDSWITCHES, 171 floating-point exceptions, 271
defined, 38 HELPMAKE, 312
described, 170 LIB, 300
326 Microsoft QuickC Tool Kit
H /D, 183
/E, 182
/H option (HELPMAKE), 183-184 /H, 183-184
/HE option (LINK), 126 /L, 182
Help data base /O. 182
creating, 184 /S. 182
defined. 177 /v. 182, 184
formatting. 191 AV, 183
Help delimiter (»), HELPMAKE, 186, 196-197 Hercules display adapter, 221
/HELP option (QCL), 10,92 /HIoption(LINK), 124, 127
HELPMAKE Huge arrays, 212
anchored text. 188, 193-194 huge keyword
application-specific control characters. 189 default addressing conventions, 212
command-line syntax, 180 described, 100
contexts Huge memory model. See Memory models
conventions for, 186 Hyperlinks
default, 187 anchored, 188
defined, 178 conventions, 188
local, 189 defined, 179
minimally formatted ASCII, 180, 191, 195 QuickHelp, 193
QuickHelp format, 191 Rich Text Format, (RTF), 196
Rich Text Format (RTF), 196
conventions, 185-186
/
creating a help data base, 184
cross-references A option
explicit, 178 LIB, 144
implicit, 178 NMAKE. 47, 158
QuickHelp, 193 QCL, 17,92
text, 188
328 Microsoft QuickC Tool Kit
M_I286, 98 NMAKE
M_I8086, 98 command line, 45, 156
M_I86xM, 98 QCL, 7. 67
MSDOS, 98
NO_EXT_KEYS, 98, 101
removing definitions of, 98
_QC, 98 /J option (QCL), 93
!IF directive (NMAKE), 60, 170
IIFDEF directive (NMAKE), 61, 170 K
IIFNDEF directive (NMAKE), 61, 170
.IGNORE pseudotarget, 172 Keywords
Ignoring cdecl, 86, 100
defined, 16
directory specification, 92 /L option (HELPMAKE), 182
nesting, maximum level of, 266 Language extensions
search paths disabling, 13, 100
specifying, 92, 100 Large memory model. See Memory models, large
N precedence, 58
predefined, 56, 169
/N option (NMAKE). 47, 158 using, 55, 167
Names invoking, 45, 155-156
DOS file, 9 macro substitution, 54, 169
executable files, 13, 76, 111 options. See NMAKE options
332 Microsoft QuickC Tool Kit
i
Index 335
/S option
HELPMAKE, 182 /T option (NMAKE), 47, 158
NMAKE, 48, 158 Targets
SAMPLE.TXT, HELPMAKE sample file, 184 default, 45, 156
/SE option (LINK), 27, 133 defined, 39, 159
Search paths macros for, 53, 165
dependents, 41, 159 specifying
include files, 16,92, 100 description blocks, 40, 159
libraries, 117 multiple description blocks, 162
overlays, 139 Temporary files, 119, 265
/X option
NMAKE, 48, 158
QCL, 17, 93, 100
/Zaoption(QCL), 100,213
13,
/Zdoption(QCL), 102 15,
/Ze option (QCL) 100 ,
Instructions Product
When you need assistance with a Microsoft pro-
duct, call our Product Support Servicesgroup at Product name
Name/Version number
Diagnosing a Problem
So that we can assist you more effectively, please
Windowing Environment
be prepared to answer the following questions Ifyou were running Microsoft Windows or another
regarding your problem, your software, and your windowing environment, give name and number of
hardware. windowing software:
Peripherals
Hard Disk
Network
Manufacturer/model Capacity(megabyte)
Is your system part of a network? 3 Yes 3 No
Printer/Plotter Manufacturer/model
D Serial D Parallel
Printer peripherals, such as font cartridges,
downloadable fonts, sheet feeders:
Documentation Feedback - QuickC® Version 2.0
Help us improve our documentation. After you've become familiar with our product, please complete and
Comments and suggestions become the property of Microsoft Corporation.
return this postage-paid mailer.
Which statement best describes your experience Ifyou normally program from outside the QuickC
with C? environment, using the utilities documented in the
I haven't had much programming experience
Tool Kit, which part contains the information you
in any language. need the most?
I have used other languages, but I'm new to C. I find most material I need in Part 1,
'Tool Kit Tutorial."
I have used C occasionally, but I'm still
unfamiUar with many of its features. I find most material I need in Part 2,
"Reference to QuickC Tools."
I use C regularly in my professional work, but
I'm not a full-time programmer or developer. I use both parts about equally.
through?
I haven't used it at all. I wish more information were available in
book form. Please specify.
I've read part of it. Which parts?
Outside the environment (compiling from the us, in the space after each item, the main reason
command line)? for your rating.
Use the space below and on the back of this card for additional comments. Please note any errors and
special strengths or weaknesses in areas such as programming examples, indexing, overall organization.
Which parts do you refer back to most frequently?
3J3H ^^1
Name
Microsoft Corporation
16011 NE 36th Way
Box 97017
Redmond, WA 98073-9717
MiaosoA