This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: ordering of constructors
Gabriel Dos Reis wrote:
> Neal Becker <ndbecker2@verizon.net> writes:
>
> | Hi. I'm trying to port CLN-1.1.6 to x86_64. Currently it segfaults on
> | all
> | tests. The problem appears to be some asm code whose purpose is to make
> | sure global constructors are ordered.
> |
> | I'm not that familiar yet with this code, but I think the way it is used
> | is that if a file F.cc needs a global object A, and A requires B, then a
> | macro is used to ensure the constructor for B was called before A.
>
> Why not put a function call in the constructor for A that make sure B
> initialized?
>
I'm not sure what you mean. Consider this example:
A.H:
struct A{ some constructor ...};
extern A a;
A.cc:
A a;
B.H:
#include "A.H"
struct B{...}
B.cc:
B b;
Let's assume that B's constructor uses the global object 'a', so that the
global cons for A must run before that for B.
What do you suggest?