[comp.lang.c++] is type-safe linkage safe?

dld@F.GP.CS.CMU.EDU (David Detlefs) (10/28/89)

Isn't it true that there is a sense in which the C++ 2.0 "type-safe
linkage" mechanism is not type-safe, because they do not include the
return types?  If I do

a.c:
----------------------------------------------------------------------
int foo() {
  return 7;
};
----------------------------------------------------------------------

b.c:
----------------------------------------------------------------------
#include <stream.h>
#include <string.h>

extern char* foo();

void main() {
  cout << strlen(foo()) << "\n";
}
----------------------------------------------------------------------

and make a.o and b.o, won't the foo's in both files end up with the
same "mangled" names, allowing everything to link without complaint.
I just tried this in g++ and it doesn't complain -- the resulting
executable produces the output '0' (on a vax).  I expect the result
would be the same in AT&T 2.0.

The only reason I can think of for not including the return type (and
thus detecting type errors like the one above) in the mangled name is
concern about the length of the names.  Are there other reasons that
I'm missing?

  
--
Dave Detlefs			Any correlation between my employer's opinion
Carnegie-Mellon CS		and my own is statistical rather than causal,
dld@cs.cmu.edu			except in those cases where I have helped to
				form my employer's opinion.  (Null disclaimer.)