BUG: Incorrect C4050 Warning When Using Function Pointers

ID: Q110717

7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbbuglist

The information in this article applies to:

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 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:

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

Last Reviewed: July 23, 1997