Meaning of -fcommon and -fno-common
David Given
dg@cowlark.com
Mon May 28 11:16:00 GMT 2012
Amittai Aviram wrote:
> The GCC manual explains the -fcommon and -fno-common flag with reference to traditional Unix practice: "In C code, controls the placement of uninitialized global variables. Unix C compilers have traditionally permitted multiple definitions of such variables in different compilation units by placing the variables in a common block." What exactly is a "common block" in this context? Where is it in the file and--assuming it's an ELF executable to be run on a Linux system--what segment (virtual address range) would the OS use for it, as opposed to the data section? Thanks!
Variables in common blocks get folded into each other. So:
---file 1---
int i;
---file 2---
int i;
---end---
...will refer to the *same* global variable. After linking they end up
in the data segment just like any other global variable. They're not
really recommended these days due to principle of least surprise; people
are much better off using explicit declarations with extern instead.
--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "Parents let children ride bicycles on the street. But parents do not
│ allow children to hear vulgar words. Therefore we can deduce that
│ cursing is more dangerous than being hit by a car." --- Scott Adams
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20120528/ea025350/attachment-0001.sig>
More information about the Gcc-help
mailing list