Why writing anything after the fileName of a #include directive does't give any errors in a C program?

Kevin

Why doesn't writing anything after the fileName of a #include directive give any errors in a C program?

#include <fileName.h> we can write anything in here and it will not give an error after program compilation
main() {
  printf("Hello World");
}

heres another example:

#include "fileName.h" we can write here anything and its fine this will not give an error after compilation
main() {
  printf("Hello World");
}

Reading the Documentation didn't help please if you find anything about this behavior from the C specification lemme know heres the link C Documentation

dbush

There shouldn't be any text after the included file.

Section 6.10.2 of the C standard regarding #include states:

2 A preprocessing directive of the form

# include <h-char-sequence> new-line

searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined.

3 A preprocessing directive of the form

# include "q-char-sequence" new-line

causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the searchfails, the directive is reprocessed as if it read

# include <h-char-sequence> new-line

with the identical contained sequence (including > characters, if any) from the original directive.

4 A preprocessing directive of the form

# include pp-tokens  new-line

(that does not match one of the two previous forms) is permitted. The preprocessing tokens after include in the directive are processed just as in normal text. (Each identifier currently defined as a macro name is replaced by its replacement list of preprocessing tokens.) The directive resulting after all replacements shall match one of the two previous forms. The method by which a sequence of preprocessing tokens between a < and a > preprocessing token pair or a pair of"characters is combined into a single header name preprocessing token is implementation-defined.

None of these forms allows for text after the included filename. In fact, both gcc and MSVC issue warnings in this case.

Given this code:

#include <stdio.h> bogus text

int main()
{
    return 0;
}

gcc 4.8.5 outputs:

x1.c:1:20: warning: extra tokens at end of #include directive [enabled by default]
 #include <stdio.h> bogus text
                    ^

And MSVC 2015 outputs:

x1.c
x1.c(1): warning C4067: unexpected tokens following preprocessor directive - expected a newline

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

C++ Why does this program does not give any output?

c program doesn't give me errors

Why does writing main; in C give a segfault

Why this Ansi C program does not give result?

Why my Racket program does not give me any output?

Why does my program give me the excess output? C program

Why does this program not print anything?

I'm writing a C program on visual studio. But my program doesn't run nor it returns any errors. Can someone take a look at it?

Why does my C program give different outputs in different compilers?

Why does this program give a Invalid memory access error in C?

Why does this C program give me an missing integer from an For loop?

Intellij does not show any errors in the syntax/does not give any suggestions

why does this give a nullptr writing access violation

Why does this program throw errors?

Python app not working after using pyinstaller but doesn't give any errors

Why does foreach not bring anything to the driver program?

Why does my program compile but not do anything?

No Output - The program doesn't give any output

Why does lapply with closures give errors?

Why does the function glViewport () give me errors?

Why doesn't this SpriteKit program draw anything?

Why does console give errors after fetching data from API Angular

No syntax errors, but program does not produce any results

Why does this program give an error when run

Why does list in program give an unexpected output?

Why does clock_t only give me integers in C

Why this C++ program is not printing anything?

Why does routing defined after app.use isn't returning anything after get requests?

Why printf("test"); does not give any error?