C9112002: Incorrect Segment Assigned for Initialized Pointer

ID Number: Q78860

6.00 6.00a 6.00ax | 6.00 6.00a

MS-DOS | OS/2

buglist6.00 buglist6.00a buglist6.00ax fixlist7.00

Summary:

PROBLEM ID: C9112002

SYMPTOMS

In Microsoft C versions 6.0, 6.0a, and 6.0ax, initializing a

pointer to one byte less than the address of a previously declared

array in the large or huge memory model will assign an incorrect

segment value to the pointer.

The segment address of the initialized pointer will be 1000h less

than the address of the original array when C is run with MS-DOS.

When C is run with MS OS/2, the address of the pointer will be 20h

less than the address of the original array.

RESOLUTION

The problem can be resolved with either of the following

workarounds:

- Make the assignment within a section of code as is shown in the

sample below.

- or -

- Compile with the /qc option.

STATUS

Microsoft has confirmed this to be a problem in Microsoft C

versions 6.0, 6.0a, and 6.0ax. This problem was corrected in C

version 7.0.

More Information:

Sample Code

-----------

/* Compile options needed: /AL

*/

#include <stdio.h>

char temp[5];

char pbuff[2000];

char *pbad = pbuff - 1; // This line does an incorrect assignment

char *pgood;

void main() {

pgood = pbuff - 1 ; // This line does a correct assignment

// Workaround number 1

printf("The value of pbuff is %p\n", pbuff);

printf("The value of pbad is %p\n", pbad);

printf("The value of pgood is %p\n", pgood);

}

Some output for this program might be:

The value of pbuff is 2547:000A

The value of pbad is 1547:0009

The value of pgood is 2547:0009

Additional reference words: 6.00 6.00a 6.00ax