Why is # required before #include <stdio.h>?

What is the function # ?

+7
c c-preprocessor
source share
6 answers

denotes a preprocessor directive :

It is important to remember that the C preprocessor is not part of the C compiler.

The C preprocessor uses a different syntax. All directives in the C preprocessor begin with a pound sign (#). In other words, the pound sign marks the beginning of the preprocessor directive, and this should be the first opaque character in the string.

# was probably chosen arbitrarily as an otherwise unused character in C syntax. @ would work just as well, I suppose.

If there wasn’t a symbol for it, then there would probably be a problem with the difference between the code intended for the preprocessor β€” how would you determine if if (FOO) should be pre-processed or not?

+15
source share

Because # is the standard prefix for introducing preprocessor instructions.

In early C compilers, the pre-processor was a separate program that would process all preprocessor statements (similar to earlier C ++ compilers), such as C-code generated by C-code) and generate C code for the compiler (it can still be a separate program, but at the same time it may just be the compiler phase).

The # symbol is only a useful symbol that can be recognized by the preprocessor and acts, for example:

 #include <stdio.h> #if 0 #endif #pragma treat_warnings_as_errors #define USE_BUGGY_CODE 

etc.

+4
source share

Preprocessor directives are lines included in the code of our programs, which are not program statements, but directives for the preprocessor. These lines are always preceded by a hash sign (#). The preprocessor is executed before the actual compilation of the code begins, so the preprocessor digests all these directives before any code is generated by the operators.

Source: http://www.cplusplus.com/doc/tutorial/preprocessor/

+4
source share

This is because # is an indicator that its preprocessor statement

before it compiles your code, it will contain the stdio.h file

+2
source share

# is a preprocessor directive. The preprocessor processes the directives to include the source file ( #include ), macro definitions ( #define ), and conditional inclusion ( #if ). When the preprocessor encounters this, it will include the headers, expand the macros, and continue compiling. It can be used for other purposes, such as stopping compilation using the #error directive. This is called conditional compilation.

+1
source share

We know that without a preprocessor the program does not start. And the preprocessor # or #include or #define or another. So # is required before #include.

0
source share

All Articles