Common and local common symbol declarations enable you to define a symbol with the same name in different object files. The difference between a common symbol and local common symbol is as follows:
The linker merges two or more common symbol declarations for the same symbol.
The assembler merges two or more local common symbol declarations for the same symbol.
If a symbol is declared as both common and local common, the common declaration overrides the local common declaration. Any definition of a symbol supersedes either type of common declaration.
To declare a symbol as a common symbol, use the .common directive. Common symbols have a global scope, and do not necessarily have the same size and alignment attributes. The .common directive has the following format:
.common name,size,alignment
Where:
name |
Represents a symbol name. |
size |
Represents an absolute integer expression. |
alignment |
Represents an absolute integer expression to the power of two. Not supported in COFF32 format. |
When the object file format is COFF32 (Windows NT), the alignment operand is not supported.
To declare a symbol as a local common symbol use the .lcomm directive. The .lcomm directive has the following format:
.lcomm name,size,alignment
Where:
name |
Represents a symbol name. |
size |
Represents an absolute integer expression. |
alignment |
Represents an absolute integer expression to the power of two. |
The assembler allocates storage in the .bss or .sbss sections for undefined symbols declared as local common. The .bss or .sbss sections are chosen according to the size of the local common symbol. The assembler defines the symbol with the relocatable address of the allocated storage. The symbol is declared with a local scope, and assigned the largest size and alignment attributes of the local common declarations for that symbol.