This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: g++: a bug or a feature ???
- From: Gokhan Kisacikoglu <kisa at centropolisfx dot com>
- To: Yzhar Keysar <yzhark at milk dot silicon-value dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 09 Jul 2002 10:13:24 -0700
- Subject: Re: g++: a bug or a feature ???
- Organization: Centropolis Effects, LLC
- References: <Pine.LNX.4.33.0207091728001.1353-100000@milk.silicon-value.com>
- Reply-to: kisa at centropolisfx dot com
you should use namespaces around your functions, especially with the
same names, you can easily choose whatever you want then.
Yzhar Keysar wrote:
>
> Hi,
>
> I have some linkage problems, probably relates to "6.4 Vague Linkage"
> section in the "Using GCC" document.
>
> I'm working on a linux/Unix based project, where writing functors and
> using them with the STL is a way of life.
> when writing two fuctors ( or for simplicity : inline functions ) with
> the same prototype ( i.e. signature) but in different objects ,
> I get no warning in compile time nor in linkage time. and runtime uses
> only ONE copy of them.
>
> the problem is that in a large project, I could choose by mistake an
> already existed function prototype but have a different implementation.
> thus using only one copy at runtime will be wrong. further more, using -O
> (optimization directive) inlines the corresponded function,
> such that it calls to the correct function result in an inconsistency
> with non optimized objects.
>
> I'm aware of the advantages of such feature ( as described for the weak
> (W) symbol ), but I really wish to have a warning of "duplicate
> declaration",
> which I can turn off in case I wish it not.
>
> I tried to turn of -fno-weak, but newly bigger problems have arisen from
> the depth. so I decided to stay with a quite well defined problem.
>
> Example code:
> -----------------------
>
> //main.cc
> #include <iostream>
> #include "test.hh"
>
> inline void g() { cerr<<"Main.g()\n" ; }
>
> void main() {
> g(); // wish to activate g() in main.cc
>
> f(); // wish to activate g() in test.cc through f().
> }
> //--------end of main.cc
>
> //test.cc
> #include <iostream>
> #include "test.hh"
>
> inline void g() { cerr<<"Test.g()\n" ; }
>
> void f() {
> g(); // wish to activate g() in test.cc
> }
> //--------end of test.cc
>
> // test.hh
>
> void f();
> //--------end of test.hh
>
> output:
>
> Main.g()
> Main.g() *** WRONG ***
>
> Working Environment
> -------------------------------
> compiler: g++_3.0.2 and g++_2.95.3
> linker: GNU ld version 2.11.90.0.8 (with BFD 2.11.90.0.8)
>
> thanx in advance
> --
> Yzhar Keysar
> Malcha Technological Park Tel: +972-2-6491476
> Building No. 9 Fax: +972-2-6491445
> P.O.B 48182 new_user@silicon-value.com
> Jerusalem 91481 http://www.silicon-value.com
--
Gökhan Kisacikoglu Centropolis Effects, LLC
Senior Technical Director 10950 W Washington Blvd
kisa@centropolisfx.com 310.204.7300 x263 Culver City, CA, 90232
Key: Gö(GIrl)-khan Kis(cirCUS)-a-(Art)-cik(loGIC)-og(thOUGH)-lu(fLU)