Wolfgang Roemer wrote on 06/10/2005 10:52:35:
>
> I don't know whether it is a bug or feature and I searched through the
mailing
> lists without success therefor I write my question this way:
>
> If you have a global variable inside a cpp file and create a library out
of
> that, the symbol name for that global variable does in no way take the
> variable type into account. A user of that variable can "make" it any
type
> with its extern declaration and thus produce subtle errors. An example:

It's a feature. It is undefined behavior to have conflicting declarations
in different translation units.
[...]
>
> I tested that on Windows with Visual C++ as well and there main.obj won't
link
> because the variable type is part of the symbol name and everthing is
fine.

In that case, how does VC++ implement cout,cin,.... construction?
In libstdc++ (well, at least in gcc-3.4) it is implemented by doing
something like:

namespace std{
...

// Note that this is different from <iostream>'s definition of cin
// (it's declared as "extern istream cin" in there).
char cin[ sizeof(istream) ];
...
ios::Init::Init()
{
  if (count++ == 0)
     new (&cin) istream(cin_constuction_flags);
....
}

> I think it would be very very important for the binary interface (ELF
here,
> or?) to have that feature as well. What do you think?

Doing so may break the (standardized) ABI.

  Michael

Reply via email to