INF: Using /ND to Put Uninitialized Data in a Named Segment

ID Number: Q40777

5.00 5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a

MS-DOS | OS/2

Summary:

In Microsoft C versions 5.1, 6.0, 6.0a, 6.0ax, and C/C++ version 7.0,

variables that are declared outside of a function and not initialized

are communal. The BTDATA_BSS segment is for uninitialized static data.

So, when compiling with /ND:

int a; /* goes to FAR_BSS */

int b = 5; /* goes to STUFF */

static c; /* goes to STUFF_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 STUFF group, either declare the

variable static or initialize it (as in either b or c above).

In Microsoft C version 6.0, the _based keyword can be used to specify

in which segment the data item will reside. Refer to section 2.5 of

"Microsoft C Advanced Programming Techniques" for more information on

using based variables.

Additional reference words: 5.10 6.00 6.00a 6.00ax 7.00