In C, semicolons (;
) are used to indicate the end of the statement. Why do #include
lines not need a semicolon?
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
#include
(and all other lines beginning with#
like#define
) is part of the preprocessor. This is actually a separate programs that runs before the main compiler and does things like include files into the source and macro expansion.The directive is processed by the preprocessor It is not a compiler, it is a simple text substitution processor. Which uses end-of-line
(\n)
as a significant character, unlike the C compiler which just treats it as whitespace. Also the reason that\
at the end of the line has an effect.#include
is processed by the pre-processor and the compiler doesn't see these statements. Hence;
is not required at the end of statement.Because preprocessing directives are not statements.
Even not all statements are required to have a final
;
. For example:After the declaration of
bla
we have two statements: oneif
statement and one empty compound statement. There is no;
but the program is valid.It just replaces that line in your source file with "whatever.h". So you don't need to put
;
at the end of "whatever.h". The pre-processor will give you a warning and ignore it.