From: Amitha P. <pe...@cs...> - 2003-10-16 13:12:24
|
On Wed 15 Oct 2003, Brad King wrote: > The Visual Studio 7 and 7.1 compilers introduce a new problem. They > support the in-class initialization of the constant, but incorrectly > allocate space for the constant automatically. If the constant's > namespace-level definition is ever given, it becomes a multiply defined > symbol if any other translation unit uses the constant. [...] > We could change the macros to work like this: > > class A > { > public: > static const int x VCL_STATIC_CONST_INIT_INT_DECL(27); > }; > > // In one .cxx file: > VCL_STATIC_CONST_INIT_INT_DEFN(const int A::x, 27); > > and then add another try-compile to detect this strange behavior. I guess the macros you are proposing not is much uglier than the existing ones, so it is worthwhile to get that little bit of extra conformance. The macro needs to be used anyway, and writing it your way is not much harder than writing the current way. > Alternatively, we could make the test for the support robust enough to > include the possibility of multiply defined symbols and fail in that case. > This would require fewer changes to the code, but would lose the > compile-time benefits of in-class initialization. I think this shouldn't be an alternative; the multiply defined symbols test should occur anyway. Thus, the test for static constant integral (and floating point) initializers should use two object files. We should make sure that whatever macro definition we generate is correct. Amitha. |