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

3

u/torsten_dev Oct 16 '26

The preprocessor is not smart.

The compiler needs to read the entire file anyway.

import {x, y, z} wouldn't make your binary smaller than Dead code elimination.

All the globals and functions without static will still need unique names for the linker. C doesn't mangle names, and it doesn't have namespaces.

import {x,y,z} only benefit I could see in C is telling you why you includes the header.