0

Doubt:

If we execute a program, the following is the type of memory allocated to that program.

                                            __________________
                                            |                |
                                            |      stack     |
                                            |                |
                                            ------------------
                                            |                |
                                            |   <Un Allocated|
                                            |       space>   |
                                            ------------------
                                            |                |
                                            |                |
                                            |       Heap     |
                                            |                |
                                            |                |
                                            __________________
                                            |                |
                                            |       data     |
                                            __________________
                                            |       text     |
                                            __________________

here the data segment places a vital role. All the initialized data and the uninitialized datas are present in data segment. But, I did not know about the order of storing the data in the data segment. For Ex, the initialized data, uninitialized data, read only and the read write data. I think the above are the four types are present in data segment.

so, in which order the data's will be placed in data segment. Like first intialized data which have the address less than all. And the next is uninitialized data's which have the higher address than the initialized data's like that.

Thanks in Advance.

mohangraj
  • 9,842
  • 19
  • 59
  • 94

1 Answers1

0

The order of global variables in the data segment cannot be determined in advance - it is up to your linker and compiler. Normally linkers preserve the order in which variables appear in the linked object files, but this is not a hard requirement (for example, the linker could put double variables first and char last to conserve the required alignment bytes).

Uninitialized global data are generally present in the .bss segment, which is placed after the .data segment (in your picture, "above" it, since higher portions of your picture = larger addresses). The .bss segment is all zeros and only its size is stored in the executable. This way, we don't need to store long strings of zeros in the binary image.

Krzysztof Kosiński
  • 4,225
  • 2
  • 18
  • 23