From: Arch on
Hi All,

I have seen this question(mentioned in subject) posted in various
forums but some how
I am not statisfied with the answer.

1- Is this because of where static variables are placed in c and c++
2- or There is a constraint from the language(C) (didn't understand
this much)

and also related to this any links where I can find differences in c
and c++ not related
to language ie not like
c++ has class and c has not
but like
const has external linkage in c but
in c++ it has external linkage.

Thanks,
Manas

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Johannes Schaub (litb) on
Arch wrote:

> Hi All,
>
> I have seen this question(mentioned in subject) posted in various
> forums but some how
> I am not statisfied with the answer.
>
> 1- Is this because of where static variables are placed in c and c++
> 2- or There is a constraint from the language(C) (didn't understand
> this much)
>

I think it is because C does only use linkage when defining what object is
linked to what other object in another translation unit (identity matching).

For instance, local extern declarations of identifiers are said in C to have
external linkage. That's enough to say that two such declarations declare
the same object. The object has no "member"-ness that would set it apart
from other such objects like in C++.

So, in C you would need considerably more rules (including some sort of name
mangling) to say the following declare distinct objects:

struct A {
static int a;
};

struct B {
static int a;
};

You could give these objects no linkage and denote them using "A.a" and
"B.a" (that is, they would not be ordinary identifiers - just like other
struct members). But to be frank, i think this is disgusting. And i'm sure
there are quite a bit of other difficulties i'm not seeing right now that
would make it even more disgusting.

Tho i think this is more of a C than a C++ question. Try in comp.std.c
maybe.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]