Title: | C++ |
Notice: | Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS) |
Moderator: | DECCXX::AMARTIN |
Created: | Fri Nov 06 1987 |
Last Modified: | Thu Jun 05 1997 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 3604 |
Total number of notes: | 18242 |
Following code compiles and links fine if you do: $ cxx test $ link test class A { private: static int m_nStatic; }; int main() { return 0; } But it gets errors if you use /debug $ cxx/deb/noopt test $ link/deb test %LINK-W-NUDFSYMS, 1 undefined symbol: %LINK-I-UDFSYM, M_NSTATIC__1A %LINK-W-USEUNDEF, undefined symbol M_NSTATIC__1A referenced in debug or traceback record in module TEST file DKB500:[V_HAVER]TEST.OBJ;11 Using /deb without /noopt makes no difference. Also tried /names=as_is, and other combinations. There are some related notes, but they seem to have to do with templates, functions, name mangling, etc. Sorry if this has been discussed before. It's as if the reference is optimized away regardless, but the debug record needs to see that it is defined. Without using /debug it would be nice to know there are unreferenced symbols. Tested on DEC C++ V5.5-017, OpenVMS Alpha V7.0
T.R | Title | User | Personal Name | Date | Lines |
---|---|---|---|---|---|
3560.1 | CXXC::MJHANS | Matthew Hanselman, DEC C/C++ | Mon May 05 1997 13:12 | 29 | |
This has been logged as CXXC_BUGS 4335. For the time being, my suggestion is to define the static data member. Note that the linker gives warnings, not errors; the program will still run perfectly fine. I'm still looking into this, and will write more later. It's not that it's optimized away, it's that you don't use that static data member anywhere. If you were to change the program to the following, you would get link warnings regardless (but this program would not run correctly, as you actually use the data member): --------------------- class A { public: static int m_nStatic; }; int main() { return A::m_nStatic; } --------------------- Re warnings: We always used to put out linker warnings for undefined static data members, but we were inundated with complaints from customers; we don't warn anymore. - Matt |