help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Compiler doesn't create some static class members


From: Larry I Smith
Subject: Re: Compiler doesn't create some static class members
Date: Wed, 02 Feb 2005 01:53:42 GMT
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041220

Paul Pluzhnikov wrote:
johan_de_taeye@yahoo.com (Johan_De_Taeye) writes:

The following behavior is noticed:
- when the number of source files with static member definitions
increases, not all of my metadata objects are being created.
- when I move all the definitions of the static objects into a single
file, all objects are created as expected.  Strange...
- when multiple static libraries (each with a certain set of static
metadata objects) are being linked together, only static members of
one of the libraries are created.
- When I explicitly reference the metadata object of a class in the
main application, that metadata object is created correctly. Looks
like a way to force the instantiation, albeit clumsy.

All of the above could be explained if some of the objects in which
you define your metadata objects are simply not linked into the
final executable (e.g. because no other object references them).

To understand how the linker decides whether to pull an object
from the library or whether to skip it, read this:
http://webpages.charter.net/ppluzhnikov/linker.html

Cheers,

His example had this for the initialization code:

  const metadata A::metadata("my class A");

Since the class-static variable names are all 'meta', the
correct initialization code would be this:

  const metadata A::meta("my class A");

IF his example reflects his true code, that's the
problem.  That would explain why they are created
when they're explicitly ref'd by other code.

Larry


--
Anti-spam address, change each 'X' to '.' to reply directly.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]