public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* g++: a bug or a feature ???
@ 2002-07-17  1:12 Yzhar Keysar
  2002-07-17  1:28 ` Nathan Sidwell
  0 siblings, 1 reply; 7+ messages in thread
From: Yzhar Keysar @ 2002-07-17  1:12 UTC (permalink / raw)
  To: gcc, gcc-help

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

^ permalink raw reply	[flat|nested] 7+ messages in thread
* g++: a bug or a feature ???
@ 2002-07-15 10:46 Yzhar Keysar
  2002-07-15 10:53 ` Gokhan Kisacikoglu
  0 siblings, 1 reply; 7+ messages in thread
From: Yzhar Keysar @ 2002-07-15 10:46 UTC (permalink / raw)
  To: gcc, gcc-help

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

^ permalink raw reply	[flat|nested] 7+ messages in thread
* g++: a bug or a feature ???
@ 2002-07-09  7:33 Yzhar Keysar
  2002-07-09 10:13 ` Gokhan Kisacikoglu
  0 siblings, 1 reply; 7+ messages in thread
From: Yzhar Keysar @ 2002-07-09  7:33 UTC (permalink / raw)
  To: gcc-help


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-07-17  8:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-17  1:12 g++: a bug or a feature ??? Yzhar Keysar
2002-07-17  1:28 ` Nathan Sidwell
  -- strict thread matches above, loose matches on Subject: below --
2002-07-15 10:46 Yzhar Keysar
2002-07-15 10:53 ` Gokhan Kisacikoglu
2002-07-15 11:27   ` Oscar Fuentes
2002-07-09  7:33 Yzhar Keysar
2002-07-09 10:13 ` Gokhan Kisacikoglu

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).