This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: c++ static object initialization
- To: "Joel W. Reed" <jreed at support dot ddiworld dot com>, GCC List <gcc at gcc dot gnu dot org>
- Subject: Re: c++ static object initialization
- From: Fergus Henderson <fjh at cs dot mu dot oz dot au>
- Date: Thu, 8 Mar 2001 04:50:14 +1100
- References: <OFED5E4F3C.7F3D4986-ON88256A08.005F8672@LocalDomain>
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.