Matthias wrote:[color=blue]
>
> Andrey Tarasevich wrote:[color=green]
> > Dave wrote:
> >[/color]
>
> I still don't understand:
> What is internal linkage good for?[/color]
Less troubles in compilation (putting the problem of name clashes
aside).
[color=blue]
> If the object is const, where is the
> benefit of each translation unit having its own copy?[/color]
Well. This is not why that concept was introduced. The automatic
internal linkage was not introduced because of the possibility
of having its own copy. Having its own copy is a side effect
that was considered to be an acceptable minor problem.
So then why are things the way they are?
If the rule for const weren't the way it is, then you would
have to do:
Header.h
********
extern const int NrItems;
extern const double Euler;
main.cpp
********
const int NrItems = 42;
const double Euler = 2.71;
use_the_globals.cpp
*******************
#include "Header.h"
See. You have a lot of extern declarations in a header file, while the
actual definitions are at a very different place. Especially you cannot
put together a header file which simply gets included (without any
further action required in the project) to have some constants with you.
The alternative:
define const objects to automatically have internal linkage
Then you can write:
Header.h
********
const int NrItems = 42;
const double Euler = 2.71;
main.cpp
********
#include "Header.h"
use_the_globals.cpp
*******************
#include "Header.h"
Everything in one place and only one place without a violation of the
one defintion rule.
--
Karl Heinz Buchegger
kbuchegg@gascad.at