FIX: Linker Errors on Array of Constant Pointers to Constants (129210)
The information in this article applies to:
- Microsoft Visual C++ 1.5
- Microsoft Visual C++ 1.51
- Microsoft Visual C++ 1.52
- Microsoft Visual C++ 1.0
This article was previously published under Q129210 SYMPTOMS
Building a project that includes the code listed in the "Sample Code"
section of this article results in the following link error or warning:
For Visual C++ for Windows:
MODULE2.OBJ(module2.cpp) : error L2025: char const __near*
__near* __near str : symbol defined more than once
LINK returned error code 2.
For Visual C++, 32-bit Edition:
module2.obj: warning LNK4006: xxxxx already defined in
module1.obj; second definition ignored.
Here xxxxx is the decorated name for str.
RESOLUTION
To work around the problem, explicitly declare the const as static, as in
this example:
static const char *const str[2] = { "string1", "string2" };
This definition can be placed in a header file, and can be included in
multiple source files. However, there are implications for the size of the
program when you use this workaround. That is, a copy of the array and of
the strings will be in every module that includes the header file, whether
you use it or not. The sample code below shares this problem.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. This bug was corrected in Visual C++, 32-
bit Edition, version 2.0.
Modification Type: | Major | Last Reviewed: | 10/17/2003 |
---|
Keywords: | kbbug kbCodeGen kbCompiler kbCPPonly kbfix KB129210 |
---|
|