Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why #include directive doesn't have a semi-colon at the end of statement?

Tags:

c

include

In C, semicolons (;) are used to indicate the end of the statement. Why do #include lines not need a semicolon?

like image 760
Ant's Avatar asked Apr 04 '12 12:04

Ant's


3 Answers

#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.

like image 113
Some programmer dude Avatar answered Sep 30 '22 14:09

Some programmer dude


#include is processed by the pre-processor and the compiler doesn't see these statements. Hence ; is not required at the end of statement.

like image 22
Naveen Avatar answered Sep 30 '22 15:09

Naveen


Because preprocessing directives are not statements.

Even not all statements are required to have a final ;. For example:

int bla = 1;

if (bla) {
}

After the declaration of bla we have two statements: one if statement and one empty compound statement. There is no ; but the program is valid.

like image 23
ouah Avatar answered Sep 30 '22 15:09

ouah