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
Show parent comment
2
u/Zirias_FreeBSD Oct 16 '26
This, at least as long as header files are used in the way they were intended to be used.
Might want to explicitly add what this means for
When used correctly, the contents of header files don't add anything to the compiled file, as they are only needed during compilation. Whether (and if so, how much) code is added by using stuff declared in headers depends entirely on linking.