linkage specifiers

Norman Diamond diamond at jit345.swstokyo.dec.com
Thu Apr 4 14:20:52 AEST 1991


In article <14094 at darkstar.ucsc.edu> daniel at terra.ucsc.edu () writes:
>What does it mean for an extern linkage specifier
>to refer to a non-file scope object?
No meaning.  It cannot do so.

>	int foo = 2;
>	int bar(int foo) {
>		{ extern int foo; return foo; }
>	}
>Paraphrased from 3.1.2.2: 
>  ''If the declaration of an identifier ... contains "extern", the
>	identifier has the same linkage as any visible declaration
>	of the identifier with file scope.''
>This sentence clearly does not apply,
It's not clear to me.
>because the file-scope declaration is not visible;
>the parameter declaration hides it.
Ahhh... you are right, because the first paragraph of section 3.1.2.1
defines visibility.

>To what object does the extern declaration refer?
It must be a declaration of an object with external linkage.
Now, the first foo is also an object with external linkage, so it ends
up being the same object, indirectly.

A more interesting case would be if the first foo were declared static.
Then the third one (the external one) could not be the same as the
first one (the internal one).  However, it still could not be the second
one (the parameter).

>It appears to refer to the parameter declaration. 
>Is this necessarily the case?
Exactly the opposite.  This is necessarily NOT the case.  Always.
Parameters do not have file scope.

>Could it denote some as-yet-unseen file-scope object having external linkage?
Not in this case, but it is possible.  For example:
  int bar(int foo) { { extern int foo; return foo } }
  extern int foo;
Again, the two extern declarations denote the same object, but that is an
indirect result, not due to the quoted part of 3.1.2.2.
--
Norman Diamond       diamond at tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.



More information about the Comp.std.c mailing list