BUG: Incorrect C4762 Generated with Optimizing Compiler

ID: Q113061

7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbbuglist

The information in this article applies to:

SYMPTOMS

When compiling in compact, large, or huge memory model, the optimizing compiler incorrectly generates the warning:

   warning C4762: Near/far mismatch in argument: conversion supplied

The warning appears when generating far pointer references to near variables and then passing those references to functions that explicitly expect near pointers.

STATUS

Microsoft has confirmed this to be a problem in C/C++ versions 7.0, 8.0, and 8.0c. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Code demonstrating this problem is shown below. When building under large or compact model, cases 1 and 2 will force a near/far conversion. Because the compiler does not know where the pointer reference to the near variables will be used, it produces a far pointer to conform with the model chosen. The compiler then converts the far pointer into a near pointer again because func1 expects a near pointer. Despite these warnings, the code is correct and the two function calls execute correctly.

In the Case 3, the variable is already a near pointer. No conversions are necessary, and therefore no warning occurs.

Sample Code

/* Compile options needed:   /AL ( or /AC or /AH) /f-   */ 
/* Any type for "testtype" produces the error where noted */ 

typedef int testtype;

 testtype _near narrtype[ 100 ];
 testtype _near ntype;
 testtype _near *nptype;

void _near func1( testtype _near *np_funcvar)
{}

void main(void)
{
   func1(narrtype);   // Causes C4762
   func1(&ntype);     // Causes C4762

   nptype  = narrtype;
   func1(nptype);     //Does NOT cause C4762
}

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