The common and nocommon variable attributes (IBM extension)

The variable attribute common allows you to specify that an uninitialized global variable or a global variable explicitly initialized to 0 should be allocated in the common section of the object file. The variable attribute nocommon specifies that an uninitialized global variable should be allocated in the data section of the object file. The variable is automatically initialized to zero.

Read syntax diagramSkip visual syntax diagram
nocommon and common variable attribute syntax

>>-__attribute__--((--+--------------+--))---------------------><
                      +-nocommon-----+       
                      +-__nocommon__-+       
                      +-common-------+       
                      '-__common__---'       

For example:
int i __attribute__((nocommon));      /* allocate i at .data  */
int k __attribute__((common));        /* allocate k at .comm  */

You can only apply the variable attributes to global scalar or aggregate variables. If you try to assign either attribute to a static or automatic variable or structure or union member, the attribute is ignored and a warning is issued.

Note that using nocommon to allocate uninitialized global variables in the data section can dramatically increase the size of the generated object. Also, specifying nocommon on a global variable that is simultaneously defined in different object files will cause an error at link time; such variables should be defined in one file and referred to in other files with an extern declaration.

The attributes take precedence over the -qcommon|nocommon compiler option.

If multiple specifications of the attribute appear in the same attribute statement, the last one specified will take effect. For example:
int i __attribute__((common, nocommon));            /* allocate i at .data  */
int k __attribute__((common, nocommon, common));    /* allocate k at .comm  */

If both the common or nocommon attribute and the section attribute are applied to the same variable, the section attribute takes precedence.