Naming Modules and Segments

Option Effect

/NM modulename Names the module
/NT textsegment Names the code segment
/ND datasegment Names the data segment

“Module” is another name for an object file created by the C/C++ compiler from a single source file. Every module has a name. The compiler uses this name in error messages if problems are encountered during processing. The module name is usually the same as the source-file name. You can change this name using the /NM (name module) option. The new modulename can include any combination of letters and digits. The space between /NM and modulename is optional.

Every module has at least two segments: a code segment (sometimes called the text segment) containing the program instructions, and a data segment containing the program data.

The compiler normally creates the code and data segment names. The default names depend on the memory model chosen for the program. For example, in small-model programs the code segment is named _TEXT and the data segment is named _DATA.

Table 4.4 summarizes the naming conventions for code and data segments.

Table 4.4 Segment-Naming Conventions

Model Code Data Module

Tiny _TEXT _DATA —-
Small _TEXT _DATA —-
Medium module_TEXT _DATA filename
Compact _TEXT _DATA filename
Large module_TEXT _DATA filename
Huge module_TEXT _DATA filename

In memory models that contain multiple data segments (compact, large, and huge), _DATA is the name of the default data segment. Other data segments have unique private names. You can override the default names with the options /NT (name text) and /ND (name data).

The /ND option is commonly used to create and compile modules that contain data only. Such modules can be accessed from other parts of the program by declaring their variables as external.

If you change the name of the default data segment with /ND, your program must load the DS register with the segment selector of your named data segment before it accesses it. You must therefore compile your program either with the /Astring form of the memory-model option and the /Au option for the segment setup, or with the /A option for a standard memory model followed by /Au. For example,

CL /AS /Au /ND DATA1 PROG1.C

The /Au option forces the compiler to generate code to load DS with the correct data-segment value on entry to the code.

All modules whose data segments have the same name have these segments combined into a single segment named DATA1 at link time.

The functions in the small data model run-time libraries that rely on the default data segment being named “_DATA” will fail if you use the /ND option to rename the default data segment. This restriction affects tiny-, small-, and medium-model programs.