r/C_Programming • u/International_Hat178 • 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
View all comments
14
u/SmokeMuch7356 Oct 16 '26
You're not importing code as such; you're just loading symbol and function declarations so that your code will compile.
For example, C requires functions to be declared before they can be used. IOW, if you write
and try to build it, the compiler will complain that
printfhasn't been declared.1 There has to be a declaration ofprintfsomewhere before it's called:stdio.hjust contains the declarations forprintfandscanfand other functions, not their actual implementations. It also contains typedefs for theFILEandfpos_ttypes, definitions for macros likeNULL, etc.int.