Alex Rivera | Logout

What does #include actually do?

Asked 2011-04-20T19:09:37.457
38

In C (or a language based on C), one can happily use this statement:

#include "hello.h";

And voila, every function and variable in hello.h is automagically usable.

But what does it actually do? I looked through compiler docs and tutorials and spent some time searching online, but the only impression I could form about the magical #include command is that it "copy pastes" the contents of hello.h instead of that line. There's gotta be more than that.

Edit
Report

1 Answer

0

Not really, no. The compiler saves the original file descriptor on a stack and opens the #included file; when it reaches the end of that file, it closes it and pops back to the original file descriptor. That way, it can nest #included files almost arbitrarily.

answered 2011-04-20T19:12:42.823

Your Answer