public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Yzhar Keysar <yzhark@milk>
To: gcc@gcc.gnu.org, gcc-help@gcc.gnu.org
Subject: g++: a bug or a feature ???
Date: Mon, 15 Jul 2002 10:46:00 -0000	[thread overview]
Message-ID: <GZAXCL00.L3S@antares.silicon-value.com> (raw)

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

             reply	other threads:[~2002-07-15 17:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-15 10:46 Yzhar Keysar [this message]
2002-07-15 10:53 ` Gokhan Kisacikoglu
2002-07-15 11:27   ` Oscar Fuentes
  -- strict thread matches above, loose matches on Subject: below --
2002-07-17  1:12 Yzhar Keysar
2002-07-17  1:28 ` Nathan Sidwell
2002-07-09  7:33 Yzhar Keysar
2002-07-09 10:13 ` Gokhan Kisacikoglu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=GZAXCL00.L3S@antares.silicon-value.com \
    --to=yzhark@milk \
    --cc=gcc-help@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).