why do include lines not end with a semicolon?
when i开发者_运维百科ncluding libraries c, the line does not end with a semicolon, while other statements do. what is the reason behind this ?
Same reason #define macros don't -- they are for the preprocessor, which expands things like includes and defines before the compiler proper takes over.
lines starting with a # aren't part of the C language itself, they are instructions for a pre-processor. When it was first designed, semi-colons just wasn't required.
"...while other statements do".
Firstly, preprocessor directives are not statements. Statement is an entity that exists at the syntactical/semantical level only. Preprocessor directives are processed at relatively early stages of translation, before any syntax analysis begins, so at that stage there's no such thing as "statement" yet. And, for this reason, there's no meaningful rationale to demand ending the #include
directive with a semicolon. If fact, preprocessor directives by definition occupy the entire line, meaning that they are already terminated by a new-line character. Any additional terminator would be redundant.
Secondly, not all "other statements" end with semicolon. A compound statement, for example, doesn't
i = 5;
{ /* <- compound statement begins here... */
i = 10;
} /* <- ... and ends here. Note: no semicolon */
i = 15;
#include
is a pre-processing command like #define
. #include
tells the compiler to include the specified file in your source code before your code actually gets compiled.
精彩评论