Please mark my answers
Hi, everyone. I'm self-teaching C and I want to post my answers to the questions in my book so that you can correct me. Please peruse my answers and tell me what you think.
1. Does your compiler do both the linking and compiling with just one command, or do you have to enter separate commands?
My compilers (gcc and clang) each do compiling then linking with one command.
2. What extension should you use for your C source files?
3. Is FILENAME.TXT a valid name for a source file?
Yes, but it is against convention and doesn't describe its content, so it's a bad choice of filename.
4. If you execute a program that you have compiled and it doesn't work as you expected, what should you do?
Figure out where the bug is - which might involve simply reading the code and conducting a thought experiment, or might involve more complicated debugging techniques. Then edit the source code, recompile and retest.
5. What is machine language?
It is the set of instructions that the CPU of the computer executes. It is specific to a CPU architecture (whereas C is portable). Executable files typically contain machine language.
6. What does the linker do?
It converts object code into an executable. It allows me to combine multiple source files into one big program.
Sounds reasonable, although a lot of times the "thought" experiment may involve actual pencils and paper. :)
The linker answer can be a little improved, I think, by writing it in a more technical language, thus explaining what the 'link' in linker means
What about this?
Originally Posted by manasij7479
A linker is a computer program that takes one or more object files and creates an executable program. These object files might represent the output of the compiler from translation units that I have created, or they might contain library functions written by someone else, or they might contain data.
The linker allows me to combine my translation units with those written by others, allows those others to hide their source code from me, and allows me to use multiple translation units to make my source code manageable.