INF: Initialized Global Data May Be Placed in Far Data Segment

ID Number: Q79070

6.00 6.00a 6.00ax 7.00 | 6.00 6.00a

MS-DOS | OS/2

Summary:

Under the Microsoft convention, initialized global data is normally

placed in segment _DATA in the default data segment DGROUP. However,

the Microsoft C Compiler versions 6.0, 6.0a, 6.0ax, and 7.0 may place

data items in a far data segment if all of the following conditions are

met:

1. Compile options include /qc

2. Compile options include /AC, /AL, or /AH

3. The data is an undimensioned, initialized global array.

When conditions 2 and 3 are met, Microsoft QuickC versions 2.5 and

2.51 and Microsoft QuickC for Windows (QC/Win) version 1.0 will also

place items in a far data segment.

Usually, this will cause a problem only if the data must be in _DATA

rather than _FAR_DATA (when linking with an assembly module, for

instance).

More Information:

The example below illustrates the situation. The variable Array is an

undimensioned initialized global array. If the program is compiled as

indicated below, Array will be placed in _FAR_DATA rather than _DATA.

To ensure that Array is placed in _DATA, do one of the following:

1. Explicitly declare Array to be near using the _near keyword.

-or-

2. Specify the number of elements in Array.

-or-

3. Use small or medium memory model.

Sample Code

-----------

/* Compile options needed: /qc /AL (/AC or /AH)

*/

#include <stdio.h>

int Hello( void );

int (*Array[])( void ) = { Hello, Hello, Hello };

int Hello()

{

printf( "Hello world.\n" );

}

void main()

{

int i;

for (i=0; i<3; i++)

(*Array[i])( );

}

Additional reference words: 6.00 6.00a 6.00ax 7.00 2.50