/ND, /NM /NQ, /NT, /NV (Name the Data or Code Segments)

Options

/NDdatasegment

/NMmodulename

/NQpcodesegment

/NTcodesegment

/NVvtablesegment

These options allow you to name or rename existing data and text segments, or to name a temporary p-code segment or a segment for far C++ virtual tables (v-tables). All options take an argument that names or renames the affected segment. The new name can include any combination of letters and digits. The space between the option and the name is optional.

The compiler places code and data into separate segments in the object file. Every segment in every object file has a name. The linker uses these names to determine which segments are combined during linking, and how the segments are ultimately grouped in the executable file.

The compiler usually 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 13.7 summarizes the naming conventions for code and data segments.

Table 13.7 Segment-Naming Conventions

Model Code Data

Tiny _TEXT _DATA
Small _TEXT _DATA
Medium name_TEXT _DATA
Compact _TEXT _DATA
Large name_TEXT _DATA
Huge name_TEXT _DATA

The /ND option renames the default data segment of your code. This option is useful mainly for shared data segments. When compiled with /ND, the program assumes that the data register (DS) contains the address of this new segment so that it can access the segment's contents using near pointers instead of far. In doing so, your program no longer assumes that the address in the stack segment register (SS) is the same as the address in the data register (DS). You must therefore use the __loadds modifier for function declarations or the /Au segment setup option to ensure that DS is loaded on entry to a function.

Note that the C run-time system stores important data in its default data segment (DGROUP). To use the run-time system, DS must contain the address of this data segment. A call to the run-time system will fail if DS currently points to the data segment named with /ND. A safer and a more flexible way to place data into a special segment is to use the __based keyword with a segment variable in your C code instead of the /ND option on the command line.

The /NM and /NT options are similar; they rename the default code segment. The /NM option sets the name of a module used in naming the _TEXT segment of medium-, large-, or huge-model programs. It appends _TEXT to the specified module name to create a new code segment, modulename_TEXT. The /NM option is included in Microsoft C/C++ for compatibility with previous versions.

The /NT option gives the code segment the specified name. In general, you should not use the /NT option with the tiny, small and compact memory models. Doing so may cause overflow errors at link time.

The /NQ option sets the name of a temporary segment for the p-code compiler; the temporary segment is removed before the program is run. This option can only be used with the /Oq (p-code optimization) option. During its operation, the p-code compiler generates several temporary segments. If you encounter LINK error 1049 (“too many segments”), use /NQ to combine these temporary segments into one temporary segment.

The /NV option sets the name of a segment for far v-tables. All far v-tables in a C++ program are grouped in the specified segment.