Assigning Functions to Overlays Using MOVE

ID: Q87938

5.30 5.31 5.50 5.60 MS-DOS kbtool

The information in this article applies to:

SUMMARY

The text below is designed to supplement section 15.2, "How to Create an Overlaid Program" in the Microsoft C/C++ "Environment and Tools" manual for version 7.0. Specifically, the article provides additional details about using the FUNCTIONS statement in a module-definition (.DEF) file to create an application that uses the Microsoft Overlaid Virtual Environment (MOVE). It does not discuss using the SEGMENTS statement to assign code segments to overlays. For information on the latter process, query in the Microsoft Knowledge Base on the following words:

   file4.c and overlaid and segments and move and resident and def

The article is titled "Assigning Code Segments to Overlays Using MOVE."

Consider an application that contains three source files. The functions in the files are as follows:

   MAIN.C:
           int main(void);

   MOD1.C:
           int __cdecl func11(int);
           int __cdecl func12(int);
           int __cdecl func13(int);

   MOD2.C:
           int __pascal func21(int);
           int __pascal func22(int);

The __cdecl declaration indicates a function that uses the C calling and naming conventions and the __pascal declaration indicates a function that use the Pascal calling and naming conventions. By default, each function in a C program is declared with __cdecl and main() must be a __cdecl function.

To use the FUNCTIONS statement, packaged functions and the medium or large memory model are required. The following compiler command line satisfies these requirements:

   cl /c /AM /Gy main.c mod1.c mod2.c

The /Gy option instructs the compiler to place all functions into the comdat_seg1 segment. The segments that the compiler normally creates for a medium memory model application (named <modulename>_TEXT) are empty, but do appear in the map file.

The .DEF file specifies the organization of the overlays. An appropriate LINK command line is as follows:

   link main mod1 mod2, test.exe, test.map /MAP,, ovl.def

If you use the Programmer's WorkBench (PWB) to build your application, add the .DEF file to the project list.

As the first example, the following .DEF file places func11 and func21 into an overlay. LINK puts the functions into a comdat_seg2 segment in overlay 1 (as indicated in the map file). The other functions remain in the comdat_seg1 segment in the resident portion of the program.

Sample DEF File #1

   NAME test.exe
   FUNCTIONS:1 _func11 FUNC21

Note that the functions names in the .DEF file conform to the calling and naming convention specified in the source code. The name of each __cdecl function has an underscore prepended to its name and its case is preserved. The name of each __fortran and __pascal function is converted to uppercase letters. In a C++ application, the function names specified in the .DEF file must be the fully decorated names. To determine the decorated names the correspond to each function, specify /MAP:FULL on the LINK command line.

As a second example, consider the following .DEF file:

Sample DEF File #2

   NAME test.exe
   FUNCTIONS:1 _func11 FUNC22
   FUNCTIONS:2 _func12

Linking the source code with this file creates an overlaid executable file with the main(), func13(), and func21() functions in the comdat_seg1 segment in the resident portion of the program; func11() and func22() in the comdat_seg2 segment in overlay one; and func12() in overlay two. Because the functions are packaged, LINK can put functions from the same file into different overlays. The order in which the functions appear in the FUNCTIONS statement determines their order in the comdat segment.

Additional reference words: kbinf kbinf visualc 5.30 5.31.009 5.50 5.60 KBCategory: kbtool KBSubcategory: MoveOverlay

Keywords          : kb16bitonly MoveOverlay 
Version           : 5.30 5.31 5.50 5.60
Platform          : MS-DOS

Last Reviewed: July 19, 1997