3 ms·
I can take a stab at it. I think what trips many new C people is the fact that include is just what it says on the tin, include. You can put anything in there
by sumtechguy 6y ago
I can take a stab at it. I think what trips many new C people is the fact that include is just what it says on the tin, include. You can put anything in there and it is subject to the pre-processor. Many books/faqs/stackoverflow/videos however implicitly tie library include and headers together. So the idea that include means include this library comes somewhat from that. It tripped me up some 27+ years ago when I started on C. The actual include a library comes from a different part of the system, the linker. The includes just handily have the bits needed to have the external references to it so the linker knows what to do. You do not need them in the include to do that. Since they were including those they usually have predefined bits in there.
Like you say pythons import is a different beast and it can run code at runtime when it comes across that statement. Some training is not clear on that. Like you point out import does not just import the file it runs the thing. If the file only contains def's then it effectively just defines a bunch of functions/objects and does nothing else But it can. C is not like that. It is more copy the whole file here and apply the current state of pre-processor rules.
- m463 6y agoyes, includes are pretty much all syntactic, no semantic.