Q62422: C4047 Incorrectly Generated on Void Pointer Assignment
Article: Q62422
Product(s): See article
Version(s): 6.00 | 6.00
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | buglist6.00 | mspl13_c
Last Modified: 22-JUN-1990
The code below, when compiled with Microsoft C 6.00 at warning level 1
or higher, incorrectly produces the following error message:
test.c(15) : warning C4047: '=' : different levels of indirection
Sample Code
-----------
#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 ) );
}
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.10 compiles this code correctly, without generating any
warning diagnostics.
Microsoft has confirmed this to be a problem with C version 6.00. We
are researching this problem and will post new information here as it
becomes available.
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
Copyright Microsoft Corporation 1986-2002.