both internal and external linkage

A

annalissa

Hi all,


The following is what I have read in a tutorial on C by arthur griffith

if within the same scope an identifier appears to have both internal and
external linkage, the linkage is un defined ...????

can anyone give example(s) for the above statement ?

BTW linkage is defined as follows isn't it ?

a identifier declared in different scopes or greater than once in the
same scope with the same name can be made to refer to the same object by
the process of linkage
 
J

Julienne Walker

Hi all,

The following is what I have read in a tutorial on C by arthur griffith

if within the same scope an identifier appears to have both internal and
external linkage, the linkage is un defined ...????

There's no such thing as undefined linkage. However, I recognize that
statement from the standard, and it actually says the *behavior* is
undefined. If the tutorial says "the linkage is undefined" instead of
"the behavior is undefined", you should let the author know, because
it's an error.

http://en.wikipedia.org/wiki/Undefined_behavior
 
K

Kaz Kylheku

Hi all,


The following is what I have read in a tutorial on C by arthur griffith

if within the same scope an identifier appears to have both internal and
external linkage, the linkage is un defined ...????

The behavior is undefined; there is no such thing as ``undefined
linkage''.
can anyone give example(s) for the above statement ?

extern int x; /* declaration with external linkage */
static int x; /* definition with internal linkage */
BTW linkage is defined as follows isn't it ?

a identifier declared in different scopes or greater than once in the
same scope with the same name can be made to refer to the same object by
the process of linkage

An identifier doesn't have to be declared more than once for linkage to
work in one translation unit. An name with linkage which is used must
be /defined/ exactly once. (A name that is not used doesn't need a
definition; declarations may appear that are not definitions.)

Linkage simply means that multiple occurences of a name refer to the
same object or function (not necessarily multiple declarations).

Of course of an external name (name with external linkage) is referenced
from N different translation units, there have to be at least N
declarations, since every translation unit needs at least one; a name
cannot be used if it is not declared. Declarations in one translation
unit are not available to another one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top