BUG: Incorrect C4050 Warning When Using Function Pointers

Last reviewed: July 22, 1997
Article ID: Q110717
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbbuglist

The information in this article applies to:

  • The Microsoft C/C++ Compiler (CL.EXE), included with:

        - Microsoft C/C++ for MS-DOS, versions 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

SYMPTOMS

Attempting to assign the address of a function marked as __loadds or __export to a correctly declared function pointer will cause the compiler to incorrectly generate a C4050 warning when the following conditions are true:

  • The code being compiled is in a .C file
  • Warning level 4 of the compiler is being used

The complete C4050 warning message generated is:

   warning C4050: 'argument' : different code attributes

The sample code shown below illustrates this problem.

RESOLUTION

To avoid the C4050 warning, use one of the following methods:

  • Provide a cast when assigning the address of the function to the function pointer

    -or-

  • Compile at warning level 3 with the /W3 compiler switch

    -or-

  • Disable the C4050 warning with the following #pragma warning directive:

    #pragma warning ( disable: 4050 )

STATUS

Microsoft has confirmed this to be a bug in the products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

This is not a problem in the 32-bit compiler.

MORE INFORMATION

NOTE: The C4050 warning message is not generated when code matching the scenario listed above is located in a .CPP file.

Sample Code

/* Compile options needed: /W4 /c
* * Compile this sample code as a .C file
*/

#include <windows.h>

void Function();

int FAR PASCAL __loadds CallbackProc1(int i) { return i; }
typedef int (FAR PASCAL __loadds *FNPROC1)(int);

int FAR PASCAL __export CallbackProc2(int i) { return i; }
typedef int (FAR PASCAL __export *FNPROC2)(int);

/* Uncomment the following line to disable the C4050 warning
*/

/*
#pragma warning ( disable: 4050 )
*/

void Function()
{
  /* Function pointer variables */
  int (FAR PASCAL *lpfnProc1)(int);
  int (FAR PASCAL __export *lpfnProc2)(int);

  lpfnProc1 = CallbackProc1;          /* This line generates C4050 */
  lpfnProc1 = (FNPROC1)CallbackProc1; /* No warning on this line   */

  lpfnProc2 = CallbackProc2;          /* This line generates C4050 */
  lpfnProc2 = (FNPROC2)CallbackProc2; /* No warning on this line   */
}


Additional reference words: 1.00 1.50 7.00 8.00 8.00c
KBCategory: kbtool kbbuglist
KBSubcategory: CLIss
Keywords : kb16bitonly


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.

Last reviewed: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.