M
M
Mishka_Sev2020-07-12 03:28:29
C++ / C#
Mishka_Sev, 2020-07-12 03:28:29

Do preprocessors insert the whole file through #include or partially?

If you write down and use only one printf function with the first line of code , then the rest of the scanf-type functions from there will also be added to the program code, or only those functions that were used in the program? Are preprocessors "stupid" and shove all the code from the included header files, or just the one that the program needs after the linker inserts ? If so, is there a way to enable only those functions that you need? To minimize the weight of the program. PS I.e. rephrasing the question, it would sound like this: is it possible to selectively include only the necessary functions from the included libraries? #include <stdio.h>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2020-07-12
@Mishka_Sev

Are preprocessors "stupid" and shove all the code from the included header files, or only the one that the program needs after the linker inserts?

Yes.
Those. preprocessors are stupid and shove all the code from included header files. But the fact is that there is almost no code as such in C header files. Usually there are type definitions and function declarations. Function definitions are compiled and found in libraries. And the linker pulls from the libraries and links only those functions that are actually used.
PS I.e. rephrasing the question, it would sound like this: is it possible to selectively include only the necessary functions from the included libraries?

This happens by default.
If the first line of code is written#include <stdio.h>

Take a look at stdio.h for fun and try to find the definition (not the declaration) of the printf function there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question