Can someone tell me what is a 'text segment' in C, and if possible show me a simple example?
Asked
Active
Viewed 4,917 times
5
-
2segments 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 Answers
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
-
1Yes I've understood all other memory segments. So correct me if i'm wrong the main() in a c program is the text segment? – Matt_p Jan 23 '14 at 18:00
-
1The `main()` is _in_ the text segment; so are the functions it calls. – Jonathan Leffler Jan 23 '14 at 18:01
-