PRB: C4047 Incorrectly Generated on Void Pointer Assignment

ID Number: Q62422

6.00 6.00a 6.00ax | 6.00 6.00a

MS-DOS | OS/2

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

Summary:

SYMPTOMS

The Microsoft C Compiler versions 6.0, 6.0a, and 6.0ax and QuickC

versions 2.5 and 2.51 incorrectly generate the following error

message when the sample code below is compiled at warning level 1

(/W1) or higher:

warning C4047: '=' : different levels of indirection

CAUSE

According to the ANSI C standard (Section 3.2.2.3):

"A pointer to void may be converted to or from a pointer to any

incomplete or object type."

In this case, the assignment is to a pointer to a pointer, which is

a pointer to an object type. So, this warning is being incorrectly

generated for the assignment. As can be seen from the sample code,

the same assignment does not cause an error for a pointer to

pointer to function returning int.

Microsoft C 5.1 compiles this code correctly, without generating

any warning diagnostics.

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/C++ version 7.0.

More Information:

Sample Code

-----------

/* Compile options needed: none

*/

#include <stdlib.h>

typedef void (*PFV)( void ); /* ptr to func returning void */

typedef int (*PFI)( void ); /* ptr to func returning int */

void test( void )

{

PFV *pPFV; /* ptr to ptr to func returning void */

PFI *pPFI; /* ptr to ptr to func returning int */

/* This assignment is made correctly with no warnings. */

pPFI = malloc( 10 * sizeof( *pPFI ) );

/* This assignment generates a warning C4047. */

pPFV = malloc( 10 * sizeof( *pPFV ) );

}

Additional reference words: 2.50 6.00 6.00a 6.00ax