4

The man page of nm here: MAN NM says that

The symbol type. At least the following types are used; others are, as well, depending on the object file format. If lowercase, the symbol is usually local; if uppercase, the symbol is global (external)

And underneath it has "b" and "B" for "uninitialized data section (known as BSS)" and "d" and "D" for "initialized data section"

But I thought local variables always goto Stack/Heap and not to "Data" or "BSS" sections. Then what local variables is nm talking about?

Kartik Anand
  • 4,513
  • 5
  • 41
  • 72
  • [Related post regarding where variables are allocated](http://stackoverflow.com/questions/12798486/bss-segment-in-c) – Lundin Jun 15 '15 at 06:40

2 Answers2

3

"local" in this context means file scope.

That is:

static int local_data = 1; /* initialised local data */
static int local_bss; /* uninitialised local bss */
int global_data = 1; /* initialised global data */
int global_bss; /* uninitialised global bss */

void main (void)
{
   // Some code
}
kaylum
  • 13,833
  • 2
  • 22
  • 31
1

Function-scope static variables go in the data or BSS (or text) sections, depending on initialization:

void somefunc(void)
{
    static char array1[256] = "";            // Goes in BSS, probably
    static char array2[256] = "ABCDEF…XYZ";  // Goes in Data
    static const char string[] = "Kleptomanic Hypochondriac";
                                             // Goes in Text, probably
    …
}

Similar rules apply to variables defined at file scope, with or without the static storage class specifier — uninitialized or zero-initialized data goes in the BSS section; initialized data goes in the Data section; and constant data probably goes in the Text section.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278