What you could do is to compile to assembly then you can look this stuff up in the generated code.

xpi0t0s

6Nov2008 02:56

Re: Memory Segments Queries

> Will be assigned in Stack section Right ?

Doesn't make sense. Assignments don't happen in specific sections; the result is assigned to the variable wherever it is. If you assign to something on the stack, you could argue the assignment is done "in the stack section", but that doesn't really make a lot of sense.

> Generally every function call has its own stack.

Not true. Functions usually share the same stack, and as you nest deeper and deeper you will go further and further up the stack, which is why you can blow the stack if you nest too deeply.

Sharing depends largely on how the OS works. Generally threads refer to lightweight processes that share the same data, whereas processes have their own address space.

> Will the compiler assign the sections during the program compilation itself?

Yes, the compiler handles all this for you.

BSS is static data, which is not the same as variables initialised with the static keyword. For example static char *foo="Hello"; foo is in the data section, "Hello" is in BSS and in this case static means it can't be modified. char bar[32]; strcpy(bar,foo); - bar is on the stack. In strcpy, pointers foo and bar are on the stack as strcpy's arguments, and bar points further down the stack (or up, depending which way you look. Stacks usually grow downwards from high memory, although conceptually they grow upwards. If you push something on the stack at 1000, the next push (assuming 1-byte pushes) will be at 999. So it grows upwards conceptually, but downwards in memory).