The information in this article applies to:
SYMPTOMSThe Microsoft C/C++ versions 7.0 and later compilers eliminate unreferenced constant strings. This happens only with C++ source, not C source. The string is declared in the source file, but is not included in the resulting object module. CAUSE
In C++, const variables have internal linkage. This is different from the
way that C handles const variables.
RESOLUTIONThe solution is to declare the const string as "extern". This provides external linkage, telling the compiler that the string may be used in another module, and not to assume that it is an unreferenced symbol; for example
would be optimized away in a C++ module, but the following string would
not:
MORE INFORMATION
While this behavior is not a bug in the compiler, the effects of this
optimization may cause unexpected results. If a string is declared and
initialized in one module, and referenced only in another module, the
string will be eliminated from the first module. This means that the other
file will not have access to the information used in the initialization of
the string.
Additional query words: 8.00 8.00c 9.00 9.10 L2029
Keywords : kbCompiler kbCPPonly kbVC100 kbVC150 kbVC151 kbVC152 kbVC200 kbVC210 kbVC410 kbVC420 kbVC500 kbVC600 |
Last Reviewed: July 1, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |