INF: LINK Option /INC May Decrease .EXE Size Under DOS

ID Number: Q71972

5.10 5.11 5.13 5.15

MS-DOS

Summary:

In some cases, using the LINK option /INC[REMENTAL] when linking a DOS

program will cause a decrease in size of the resulting executable

(.EXE) file. For example, when the sample program below is prepared

for incremental linking by using the /INC option, the .EXE size is

significantly smaller than when the program is linked without the /INC

option (8677 bytes vs. 68227 bytes).

More Information:

Linking with the /INC option prepares an .EXE file for subsequent

linking with ILINK (Incremental Linker). The /INC option changes the

.EXE file from a DOS format to a Windows and OS/2 format called a

"segmented executable file." If the program is a DOS application, LINK

adds a stub loader to the .EXE file so the program can still run under

DOS.

The sample program below declares a 65000-byte uninitialized global

array. Therefore, this program will need space for 65000 zeros and,

under the DOS format, all those zeros are also represented in the

.EXE file as zeros.

On the other hand, the segmented executable file does not contain all

the actual zeros. Instead, LINK creates an iterated segment entry in

the .EXE header that directs the loader to create a segment of size

65000 bytes and initialize it to zeros. This method requires only 5

bytes, rather than the 65000 bytes used under DOS, which explains why

the .EXE file ends up so much smaller.

Sample Code

-----------

/* Compile options needed: /AL /c

LINK options needed: /INC

*/

char a[65000];

void main(void)

{

}

Additional reference words: 5.10 5.11 5.13 5.15