This is the mail archive of the gcc@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]

Re: c++ static object initialization


Joel W. Reed wrote:

> i have two .so files each with a static object that is named
> the same. this seems to confuse gcc/ld/something as one .so
> file is incorrectly using the object from the other .so file.
>
> this problem went away if i put one of the objects in one
> of the .so files in its own separate namespace.
>
> is this a known problem?
> am i just doing something wrong?

Yes, you're doing something wrong.
Your code violates the "One Definition Rule":

 |    3.2 - One definition rule [basic.def.odr]
 ...
 |    -3- Every program shall contain exactly one definition of every
 |    non-inline function or object that is used in that program; no
 |    diagnostic required.

This means that if a program contains more than one object
with the same name, then the program is ill-formed, but the
implementation doesn't have to warn you.  So the behaviour is
undefined, and the implementation can do anything it wants.

Some would say that the first thing you did wrong was using C++ ;-)

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.


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