C++ to ASM linkage in GCC: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
No edit summary
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
Line 40:
In assembly, (NASM, specifically; the author does not use GAS. Anyone who knows how GAS works may add to this article as they see fit.) all symbols are automatically local to the particular assembly file in which they appear. To make a symbol global, you must use the 'global _SYMBOL_NAME_' directive. If I remember right, in GAS, that's '.globl _SYMBOL_NAME'.
 
<sourcesyntaxhighlight lang="ASM">
;-------------------------------------
; I usually like to place all my directives in a section above the code:
Line 61:
ret
 
</syntaxhighlight>
</source>
 
To clarify, technically, the linker can 'see' all symbols. It just chooses to ignore linkage between files for symbols not exclusively declared global. If you were to write a second file:
 
<sourcesyntaxhighlight lang="ASM">
;--------------------------------------
; Extern directives here
Line 73:
extern mylocalsymbol
;--------------------------------------
</syntaxhighlight>
</source>
 
This file will assemble, but when passed through the linker, you will receive a message to the effect that no such symbol has been defined for 'mylocalsymbol'.
Line 120:
If you do the following:
 
<sourcesyntaxhighlight lang="cpp">
class foo {
public:
Line 128:
extern foo fubar;
extern "C++" foo fubar
</syntaxhighlight>
</source>
 
The compiler will take them both to mean the same thing: 'Link to an external symbol which has the ''demangled'' name fubar, and is of type foo'.