r/C_Programming • • Oct 16 '26

Question Why not specifying what to include ?

Hi, sorry if there is English mistake, it's not my first language.

I found online that the #include is replaced by preprocessor by the whole file being included, and I wondered why C isn't made so we can specify only parts of the files to include (like `import { x, y, z } from "file"` in typescript) so the compiled file is lighter ?

20 Upvotes

28 comments sorted by

View all comments

Show parent comment

17

u/vcunat Oct 16 '26

Yes, but it's good to note that the primary use of includes is to get declarations and not definitions (which live in a .c), so you normally get how to call functions but not the functions themselves. Of course there are common static inline cases, and you can "misuse" includes, etc.

5

u/pfp-disciple Oct 16 '26

I wanted to say something about that, but couldn't word it as well as you did. Thanks!