Article ID: 116172 - Last Review: July 5, 2005 - Revision: 2.1 BUG: Based Ptr. Init Fails at Global Scope in CPP FileThis article was previously published under Q116172 On This PageSYMPTOMS
When attempting to compile an application written in C++ that contains a
based pointer initialized at global scope, the compiler incorrectly returns
the error message
error C2440 : 'initializing' : cannot convert from 'int __far *' to
'int __based(xxxx) *'
This error does not occur for based pointers that are initialized at function scope. RESOLUTIONSample Code 1With the 16-bit compilers listed above, this error can be eliminated by typecasting the constant that is used to initialize the based pointer to a type "_based(void) *". The following code demonstrates how to generate the compiler error as well as the workaround:Sample Code 2In the 32-bit compiler for Windows NT, version 8.0, the workaround given for the 16-bit compilers does not work. The "_based(void) *" cast generates the following two error messages if you are using the 32-bit compiler:
error C2493: illegal form of __based
error C2440: 'initializing' : cannot convert from 'int *' to 'int
__based(BasePtr) *'
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. APPLIES TO
| Article Translations
|

Back to the top
