[ACCEPTED]-What does #include actually do?-include
Logically, that copy/paste is exactly what 8 happens. I'm afraid there isn't any more 7 to it. You don't need the ;
, though.
Your 6 specific example is covered by the spec, section 5 6.10.2 Source file inclusion, paragraph 3:
A preprocessing directive 4 of the form
# include
"
q-char-sequence"
new-linecauses the replacement of that 3 directive by the entire contents of the 2 source file identified by the specified 1 sequence between the
"
delimiters.
That (copy/paste) is exactly what #include "header.h"
does.
Note 3 that it will be different for #include <header.h>
or when the 2 compiler can't find the file "header.h"
and it tries 1 to #include <header.h>
instead.
Not really, no. The compiler saves the 5 original file descriptor on a stack and 4 opens the #include
d file; when it reaches the end 3 of that file, it closes it and pops back 2 to the original file descriptor. That way, it 1 can nest #include
d files almost arbitrarily.
The # include
statement "grabs the attention" of 24 the pre-processor (the process that occurs 23 before your program is actually compiled) and 22 "tells" the pre-processor to include 21 whatever follows the # include
statement.
While the 20 pre-processor can be told to do quite a 19 bit, in this instance it's being asked to 18 recognize a header file (which is denoted 17 with a .h
following the name of that header, indicating 16 that it's a header).
Now, a header is a file 15 containing C declarations and definitions 14 of functions not explicitly defined in your 13 code. What does this mean? Well, if you 12 want to use a function or define a special 11 type of variable, and you know that these 10 functions/definition are defined elsewhere 9 (say, the standard library), you can just 8 include (# include
) the header that you know contains 7 what you need. Otherwise, every time you 6 wanted to use a print function (like in 5 your case), you'd have to recreate the print 4 function.
If its not explicitly defined in 3 your code and you don't #include
the header file 2 with the function you're using, your compiler 1 will complain saying something like: "Hey! I don't see where this function is defined, so I don't know what to with this undefined function in your code!".
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.