ID: Q40777
6.00 6.00a 6.00ax 7.00 | 6.00 6.00a | 1.00 1.50
MS-DOS | OS/2 | WINDOWS
kbtool
The information in this article applies to:
- Microsoft C for MS-DOS, versions 6.0, 6.0a, and 6.0ax
- Microsoft C for OS/2, versions 6.0, and 6.0a
- Microsoft C/C++ for MS-DOS, version 7.0
- Microsoft Visual C++ for Windows, versions 1.0 and 1.5
The /ND compiler switch can be used to name data segments and force certain data into these segments. Named data segments are always far segments, so far pointers and addressing must be used.
Using /ND causes the program to assume that the DS register points to the named segment, not to the default data segment. SS is no longer assumed to be equal to DS, so functions may need to use _loadds (__loadds) to ensure that DS is loaded correctly.
/ND is used mostly for shared data segments and is really a special purpose option. A better technique for forcing data into a particular segment is to use the _based (__based) keyword with a segment variable name.
Variables that are declared outside of a function and not initialized are communal. That is, they are not placed in the named data segment if /ND is used. The reason for this is because the compiler places data in named segments, but communal items are assigned to segments by the linker. With /ND initialized global data and all static data go into named segments rather than the default segments.
So, when compiling with /ND mydata:
int a; /* goes to default segment */
int b = 5; /* goes to MYDATA */
static c; /* goes to MYDATA_BSS */
The reason "int a;" is treated in this way is because it is legal to
have such declarations in several modules as long as at most one of
the declarations contains an initializer. The linker combines all
these definitions into one. If it were subject to the /ND switch, the
variable could be in different segments in different modules, which
would be impossible to link.
So, to put the variable in the named data group, either declare the variable static or initialize it (as in either b or c above).
In Microsoft C version 6.0 and later, the _based (__based in C/C++ 7.0 and later) keyword can be used to specify in which segment the data item will reside. This is generally preferred to using /ND. Refer to the manuals for more information on using based variables.
Additional reference words: kbinf 1.00 1.50 6.00 6.00a 6.00ax 7.00 8.00 8.00c KBCategory: kbtool KBSubcategory: CLIss Keywords : kb16bitonly
Last Reviewed: July 18, 1997