PRB:Incorrect Evaluation of Array of Pointers to Constant Data

ID Number: Q71000

6.00 6.00a 6.00ax | 6.00 6.00a

MS-DOS | OS/2

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

Summary:

SYMPTOMS

When an array of pointers to constant data items is declared, the

compiler may incorrectly consider both pointers and data to be

constant. This problem occurs in C version 6.0, QuickC versions 2.5

and 2.51, and C versions 6.0a and 6.0ax with the /qc (quick

compile) option. When the sample code below is compiled at warning

level 3 (/W3) with any of the above compilers, the following three

messages are produced:

error C2166: lvalue specifies const object

warning C4090: different 'const/volatile' qualifiers

warning C4090: different 'const/volatile' qualifiers

CAUSE

The compiler incorrectly generates a C2166 error when trying to

modify the pointers in the array because it interprets the pointers

as being constant. The sample code will also incorrectly generate

the C4090 warning when assigning the array address to a pointer of

the same type because it interprets the type of the array

incorrectly.

RESOLUTION

The C versions 6.0a and 6.0ax compilers contain partial corrections

for these errors and the first two of these messages does not

appear as long as the /qc option is not used. The second C4090

message DOES get generated because the C 6.0a and 6.0ax compilers

do not correctly evaluate arrays of constant pointers to functions.

STATUS

Microsoft has confirmed this to be a problem in C versions 6.0,

6.0a, and 6.0ax and QuickC versions 2.5 and 2.51 (buglist2.50 and

buglist2.51). This problem was corrected in C version 7.0.

More Information:

Sample Code

-----------

/* Compile options needed: /W3

*/

#include <stdio.h>

int * const * ptr2const_ptr;

int * const arr2const_ptr[4];

int const * * ptr2ptr2const;

int const * arr2ptr2const[4];

void (* const * ptr2constfunc)(void);

void (* const arr2constfunc[4])(void);

void main ()

{

**ptr2const_ptr= 0;

*(arr2const_ptr[0])= 0;

*ptr2ptr2const= NULL;

(arr2ptr2const[0])= NULL;

/* this incorrectly generates a C2166 */

/* this is corrected in C 6.00a full compile */

ptr2const_ptr= arr2const_ptr;

ptr2ptr2const= arr2ptr2const;

/* this incorrectly generates a C4090 */

/* this is corrected in C 6.00a full compile */

ptr2constfunc= NULL;

ptr2constfunc= arr2constfunc;

/* this incorrectly generates a C4090 */

}