473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

link,ge related to long distant friendship

I have encountered certain confusion while scrutinizing the long
distance friendship engendering violation of encapsulation.

If object (be it a class, variable, function, etc) has an internal
linkage let's say defined in the .c file or with a word static (by the
way definition of anything in .c imply internal linkage?). And the same
name object is defined with external linkage; let's say in the .h file.
The question is whether there is a conflict during linking/compilation
phase.

Does internal linkage override the external one?

thanks...

Jul 23 '05 #1
4 1344

"puzzlecracker" <ir*********@gmail.com> wrote in message
I have encountered certain confusion while scrutinizing the long
distance friendship engendering violation of encapsulation.

If object (be it a class, variable, function, etc) has an internal
linkage let's say defined in the .c file or with a word static (by the
way definition of anything in .c imply internal linkage?). And the same
name object is defined with external linkage; let's say in the .h file.
The question is whether there is a conflict during linking/compilation
phase.
Read 7.1.1/7 - "The linkages implied by successive declarations for a given
entity shall agree. That is, within a given scope, each declaration
declaring the same object name or the same overloading of a function name
shall imply the same linkage. Each function in a given set of overloaded
functions can have a different linkage, however."
Does internal linkage override the external one?


Yes. The examples given are -

static int a; // a has internal linkage
int a; // error: two definitions

static int b; // b has internal linkage
extern int b; // b still has internal linkage

int c; // c has external linkage
static int c; // error: inconsistent linkage

extern int d; // d has external linkage
static int d; // error: inconsistent linkage

Sharad
Jul 23 '05 #2

puzzlecracker wrote:
If object (be it a class, variable, function, etc) has an internal
linkage let's say defined in the .c file or with a word static (by the way definition of anything in .c imply internal linkage?). And the same name object is defined with external linkage; let's say in the .h file. The question is whether there is a conflict during linking/compilation phase.


I think you're confusing linkage with visibility. After the
preprocessor
is done with the #include's, the compiler can't see where what
originated.
It doesn't care. On the other hand, the preprocessor doesn't deal with
linkage.

To get internal linkage, you typically write static int x; at file
scope.
Now, you typically want it to be internal to one .cpp file, so you put
it
in a .cpp file. It is legal to put it in a .h file. In that case, every
..cpp file that includes the .h (in)directly gets a separate x.

With external linkage, every declaration refers to the same object.
That
in turn means you should have one definition, but you can have a lot of
declarations. The linker will enforce this.

HTH,
Michiel Salters

Jul 23 '05 #3

Sharad Kala wrote:
"puzzlecracker" <ir*********@gmail.com> wrote in message
I have encountered certain confusion while scrutinizing the long
distance friendship engendering violation of encapsulation.

If object (be it a class, variable, function, etc) has an internal
linkage let's say defined in the .c file or with a word static (by the way definition of anything in .c imply internal linkage?). And the same name object is defined with external linkage; let's say in the .h file. The question is whether there is a conflict during linking/compilation phase.
Read 7.1.1/7 - "The linkages implied by successive declarations for a

given entity shall agree. That is, within a given scope, each declaration
declaring the same object name or the same overloading of a function name shall imply the same linkage. Each function in a given set of overloaded functions can have a different linkage, however."
Does internal linkage override the external one?


Yes. The examples given are -

static int a; // a has internal linkage
int a; // error: two definitions

static int b; // b has internal linkage
extern int b; // b still has internal linkage

int c; // c has external linkage
static int c; // error: inconsistent linkage

extern int d; // d has external linkage
static int d; // error: inconsistent linkage

Sharad


'7.1.1/7' - where is it? in FAQ? couldnt find it there even slightly
related to the linkage. Could you please link me to it?

By the way, thanks for your kind help!

Jul 23 '05 #4

"puzzlecracker" <ir*********@gmail.com> wrote in message
'7.1.1/7' - where is it? in FAQ? couldnt find it there even slightly
related to the linkage. Could you please link me to it?
My bad, I must have explicitly said that I was making reference to the Holy
Standard ISO/IEC (14882:2003). I sometimes take things to be self
explanatory :-)
By the way, thanks for your kind help!


You are quite welcome.

Sharad
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: David Abrahams | last post by:
Since a significant part of Python is only documented in PEPs, I am disappointed to see that they can't be easily found. Where are they? -- Dave Abrahams Boost Consulting...
7
by: Erik | last post by:
private and protected members can only be accessed by deriving a class or by giving friendship. The problem with friendship is that friend statements are written inside the class. A FriendShip...
14
by: Steve McLellan | last post by:
Hi, Sorry to repost, but this is becoming aggravating, and causing me a lot of wasted time. I've got a reasonably large mixed C++ project, and after a number of builds (but not a constant...
4
by: Mr Dyl | last post by:
I'm trying to declare the following friendship and VS.Net 2003 is complaining: template <class T> class Outter { class Inner {...} ... }
3
by: tom.s.smith | last post by:
I know that friendship isn't inherited in C++, and have two questions. (1) Why? Is it a technical problem, or just by design? If the latter, isn't this a little prescriptive, and shouldn't there...
15
by: Killer42 | last post by:
Hi all. Ok, I'm using VB6 but I think the answer to this (if there is one) is more likely to be found in the Access forum. I have a situation where I've got tens of millions of records, spread...
4
by: werasm | last post by:
I've read the following somewhere: "Friendship is the strongest form of coupling there is. That is, you introduce a high degree of dependency when you declare a friend, since the friend becomes...
2
by: BASSPU03 | last post by:
I used the Common Dialog API to store file paths on my form's underlying table. These paths are displayed in a textbox that I can click to open the selected file. Having stored the file paths in...
6
by: Hicham Mouline | last post by:
Hello, A semi-skeptical colleague is asking me why friendship is not inheritable, specifically: class Base { public: virtual void f() const =0; }; class Derived : public Base {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.