This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
g++: a bug or a feature ???
- From: Yzhar Keysar <yzhark at milk>
- To: gcc at gcc dot gnu dot org, gcc-help at gcc dot gnu dot org
- Date: Mon, 15 Jul 2002 20:45:56 +0300
- Subject: g++: a bug or a feature ???
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
--
-- Yzhar Keysar