INFO: Declaring a Pointer to a Function: C4071, C4001, or C4220Last reviewed: September 2, 1997Article ID: Q49064 |
The information in this article applies to:
SYMPTOMSIn Microsoft C, the old method of declaring a pointer to a function,
type (*ptr)(); ptr = function;causes the following compiler warnings when compiling with the "/W3" option in C versions 6.0, 6.0a, and 6.0ax:
C4071: 'ptr' : no function prototype givenMicrosoft C/C++ version 7.0 generates the following warning when the "/W4" option is used:
C4001: nonstandard extension [...] was usedVisual C++, 16- and 32-bit editions, versions 1.0 and above generate the following warning when the "/W4" option is used:
C4220: varargs matches remaining parameters RESOLUTIONUse one of the following methods to avoid the warning message:
type function(parameter_list); type (*ptr)(parameter_list); ptr = function;Note: The parameter list must be exactly the same parameter list with which the function was declared.
MORE INFORMATIONThe following program will generate a warning when compiled with the warning level set as specified by the "compile options needed" comment. To eliminate the warning use the prototype which is shown in the comment.
Sample Code
/* Compile options needed: /W3 - Microsoft C version 6.xx /W4 - Microsoft C/C++ version 7.0, Visual C++, all versions */ #include <stdio.h> void main (void) { /* Declare 'fun_ptr' as a pointer to a function */ /* Use the following line to correct the warning */ /* int (*fun_ptr)(const char *, ... ); */ int (*fun_ptr)(); int other_args; /* Assign pointer to the specific function, 'printf' */ fun_ptr = printf; /* Standard usage in calling environment */ fun_ptr("format string goes here", other_args); } Keywords : CLngIss kbcode kbfasttip Version : MS-DOS:5.1,6.0,6.00a,6.00ax,7.0; WINDOWS:1.0,1.5; WINDOWS NT:1.0,2.0,2.1,4.0,5.0 Platform : MS-DOS NT WINDOWS Issue type : kbinfo |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |