This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Constant singleton object initialization


Helge Bahmann <hcb@chaoticmind.net> writes:

> class C {
> public:
> 	inline C(int _x) : x(_x) {}
> 	virtual ~C(void) {}
> 	int x;
> };
> 
> Now assume the following definitions:
> 
> const A a={42};
> const B b(42);
> const C c(42);
> 
> If I compile this, a will end up in the ".rodata" section with the correct 
> initialization value written to the segment, while b and c end up in BSS and 
> are initialized at runtime. While I think that at least b could reasonably be 
> put into rodata, I am more interested in c -- is there a fundamental reason 
> why this is not possible? (i.e. is this an artifact of the presence of a 
> constructor, or does the virtual methods table pointer affect initialization 
> as well?)

There is no fundamental reason why it is not possible.

Unfortunately, as you've seen, gcc does not implement this
optimization.

This is listed in the bug database:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=4131

which as you can see does not mean that it is going to be fixed any
time soon.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]