PRB: C 6.x Online Help Example for _heapwalk() Is Incorrect

ID Number: Q66703

6.00 6.00a 6.00ax | 6.00 6.00a

MS-DOS | OS/2

docerr

Summary:

The program example HEAPWALK.C that is found in the C versions 6.0,

6.0a, and 6.0ax online Help is incorrect. Compiling the program under

large model in OS/2 causes a general protection error. When compiling

the program without the Quick Compile option (/qc) turned on, the

following warning message will appear twice:

Warning c4061: long/short mismatch in argument: conversion supplied

This warning message is caused by the failure to type cast the

following statement

heapdump(254);

to the following:

heapdump((char)254);

The second "for" loop in the program causes the general protection

fault. The variable "i" is not initialized to the correct value. The

code currently reads as follows:

for( ; i >= 0; i-- )

{

free( p[i] );

printf("Deallocating %u at %Fp\n",

_msize( p[i] ), (void _far *)p[i]);

}

It should read as follows:

for( i=9; i >= 0; i-- ) // <--- THIS LINE HAS BEEN CHANGED.

{

free( p[i] );

printf( "Deallocating %u at %Fp\n",

_msize( p[i] ), (void _far *)p[i] );

}

The problem with the loop is that the value of i is equal to 10 when

the loop begins; it should be 9.

Microsoft C/C++ version 7.0 documents this correctly.

Additional reference words: 6.00 6.00a 6.00ax _heapwalk