0

As far as I understand:

provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control.

The one I'm concerned with is the inclusion of header files, it does so by replacing #include blabla.h with the actual code of blabla.h. And it is invoked before compiling.

takes one or more object files generated by a compiler and combines them into a single executable file, library file, or another object file.

Reading many answers here on StackOverflow, I understood that it "links" the other libraries whose functions I may be using in my code with my actual code, e.g., stdio.h and printf();. And it is invoked after compiling.

Now my question is, if the preprocessor has already --literally-- included that library's code in my code, why do we need linking? Assuming they've become one file.

Community
  • 1
  • 1
Abdelrahman Eid
  • 881
  • 2
  • 13
  • 28
  • The preprocessor doesn't include any library code. It just includes the _header files_ which are not the same thing as _library code_. – Jabberwocky Oct 20 '16 at 12:10
  • Care to elaborate the difference, please? – Abdelrahman Eid Oct 20 '16 at 12:11
  • 1
    Very basically: The header files contain only _declarations_. For example the declaration of the `printf` function in the `` header file just declares that a function named `printf` exists. But the actual _code_ of the `printf` function is not in that header file. That code is linked to _your _ code by the linker. – Jabberwocky Oct 20 '16 at 12:15
  • I see, sorry for my ignorance. Thank you. – Abdelrahman Eid Oct 20 '16 at 12:42

0 Answers0