Knowledge (XXG)

Linkage (software)

Source 📝

69:
would denote a distinct entity, although using the same name, but its entity could be referred to by distinct declarations within the same translation unit. A name that has no linkage at all cannot be referred to from declarations in different scopes, not even from within the same translation unit. Examples of such names are parameters of functions and local variables. The details differ between C (where only objects and functions - but not types - have linkage) and C++ and between this simplified overview.
65:. The scope of a name is the part of a translation unit where it is visible. For instance, a name with global scope (which is the same as file-scope in C and the same as the global namespace-scope in C++) is visible in any part of the file. Its scope will end at the end of the translation unit, whether or not that name has been given external or internal linkage. 68:
If the name has external linkage, the entity that name denotes may be referred to from another translation unit using a distinct declaration for that same name, and from other scopes within the same translation unit using distinct declarations. Were the name given internal linkage, such a declaration
90:
Definition of 'linkage' quoted from ISO/IEC 9899:TC3 (C99 Standard). C uses the term "identifier" where this article uses "name" (the latter of which is what C++ uses to formalize linkage):
46:
is used in C to restrict the visibility of a function or variable to its translation unit. This is also valid in C++. (C++ 98/03 deprecated this usage in favor of
94:
An identifier declared in different scopes or in the same scope more than once can be made to refer to the same object or function by a process called linkage.
312: 302: 33: 270:. Official C99 documents, including technical corrigenda and a rationale. As of 2007 the latest version of the standard is 239: 233: 25: 17: 32:
describes how names can or can not refer to the same entity throughout the whole program or one single
62: 47: 307: 244: 78: 272: 40: 267: 296: 249: 73: 54:
namespace-scope variable as having internal linkage unless it is explicitly declared
72:
Linkage between languages must be done with some care, as different languages
50:, but is no longer deprecated in C++ 11.) Also, C++ implicitly treats any 283: 21: 16:
In programming languages, particularly the compiled ones like
200:
is declared in two files, with its function body defined in
224:. This is an example of external linkage for a function. 76:
their external symbols differently. A common idiom uses
61:
A name's linkage is related to, but distinct from, its
98:The following is a common example of linkage: 8: 124:/* extern optional - it's the default */ 260: 7: 313:Programming language implementation 14: 1: 234:Application binary interface 329: 240:Compatibility of C and C++ 303:C (programming language) 164: 100: 82:to link C++ and C code. 96: 92: 48:anonymous namespaces 273:"ISO/IEC 9899:TC3" 245:Linker (computing) 167:/* file demo2.c */ 103:/* file demo1.c */ 320: 288: 287: 279: 277: 265: 223: 219: 215: 211: 207: 203: 199: 192: 189: 186: 183: 180: 177: 174: 171: 168: 161: 158: 155: 152: 149: 146: 143: 140: 137: 134: 131: 128: 125: 122: 119: 116: 113: 110: 107: 104: 81: 57: 53: 43: 34:translation unit 328: 327: 323: 322: 321: 319: 318: 317: 293: 292: 291: 281: 275: 271: 266: 262: 258: 230: 221: 217: 213: 209: 205: 204:. Via linkage, 201: 197: 194: 193: 190: 187: 184: 181: 178: 175: 172: 169: 166: 163: 162: 159: 156: 153: 150: 147: 144: 141: 138: 135: 132: 129: 126: 123: 120: 117: 114: 111: 108: 105: 102: 88: 77: 55: 51: 41: 12: 11: 5: 326: 324: 316: 315: 310: 305: 295: 294: 290: 289: 259: 257: 254: 253: 252: 247: 242: 237: 229: 226: 165: 101: 87: 84: 13: 10: 9: 6: 4: 3: 2: 325: 314: 311: 309: 306: 304: 301: 300: 298: 285: 274: 269: 264: 261: 255: 251: 250:Name mangling 248: 246: 243: 241: 238: 235: 232: 231: 227: 225: 99: 95: 91: 85: 83: 80: 75: 70: 66: 64: 59: 49: 45: 37: 35: 31: 27: 23: 19: 268:ISO/IEC 9899 263: 195: 106:/* extern */ 97: 93: 89: 86:Linkage in C 71: 67: 60: 58:, unlike C. 38: 29: 15: 282:(3.61  297:Categories 256:References 216:refers to 208:called in 79:extern "C" 308:Compilers 196:Function 228:See also 222:demo2.c 214:demo1.c 212:inside 202:demo2.c 44:keyword 30:linkage 280:  210:main() 151:return 56:extern 42:static 24:, and 276:(PDF) 236:(ABI) 74:adorn 63:scope 52:const 179:void 170:void 136:void 130:main 118:void 109:void 39:The 284:MiB 220:in 218:foo 206:foo 198:foo 188:... 173:foo 148:(); 145:foo 127:int 112:foo 22:C++ 299:: 121:); 36:. 28:, 20:, 286:) 278:. 191:} 185:{ 182:) 176:( 160:} 157:; 154:0 142:{ 139:) 133:( 115:( 26:D 18:C

Index

C
C++
D
translation unit
static keyword
anonymous namespaces
scope
adorn
extern "C"
Application binary interface
Compatibility of C and C++
Linker (computing)
Name mangling
ISO/IEC 9899
"ISO/IEC 9899:TC3"
MiB
Categories
C (programming language)
Compilers
Programming language implementation

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.