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
76
u/pfp-disciple Oct 16 '26
C is much older, and its design is much more straightforward. The behavior you're describing could be crudely done with macros at compile time. See
#ifdef.Modern linkers (and probably not so modern ones) will eliminate unused code, anyway. So, if a file is included that has functions a(), b(), c,(), and d() but only b() and d() are used, the final executable won't have the code for a() and c().