5

Can someone tell me what is a 'text segment' in C, and if possible show me a simple example?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Matt_p
  • 125
  • 2
  • 5
  • 2
    segments are not programming concepts, they're how code and data are laid out in executable files and in memory when a program is running. Take a look at the documentation for your linker for some possible hints. – woolstar Jan 23 '14 at 17:41

1 Answers1

7

The 'text' segment of a program on Unix systems is the code — the machine code, the functions that make up the program (including, in particular, main() if the program is written in C or C++). It can also include read-only data. The other segments in a classic program are the 'data' segment and the 'bss' segment. The 'data' segment holds initialized data; the 'bss' segment holds zeroed data. Once running, the data and bss segments are indistinguishable.

You also end up with the stack and 'the heap'.

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