Are C preprocessor statements part of C?

I recall an expression made by one of my professors in the introductory course C. He stated that the #define preprocessor command allows the programmer to create a constant for use in later code and that the command was part of the C language .

 /* Is this truly C code? */ #define FOO 42 

Since this was in the introductory programming class, I suspect that it simply simplified the connection between the source file and the compiler, but nonetheless I want to confirm my understanding.

Are the preprocessor instructions completely independent of the C language (depending on the particular compiler used) or are explicitly described in the C99 standard ? Out of curiosity, has K & R ever mentioned preprocessor macros?

+4
source share
3 answers

Yes, the standard describes a preprocessor. This is a standardized part of C.

Note that #include , which is necessary for modulating code, is a preprocessor directive.

In a public draft of the C99 standard, the preprocessor is described in section 6.10.

+7
source

The preprocessor is indeed part of the C and C ++ standard (chapter 16 of the C ++ standard), and the standards describe how the preprocessor and language interact (for example, it is forbidden to repeat #define C keywords).

However, the C preprocessor can work with languages ​​other than C for any simple file preprocessing (I saw that it was used with LaTeX files, for example).

+2
source

Yes, the preprocessor is part of the C language. Conceptually, it starts before compiling the source.

Along with constant definitions, the preprocessor is used to implement two very important constructions:

  • #include , which adds other files to the compilation unit.

  • turn on the guards; those. template,

     #if !defined(METAWORD) #define METAWORD 1 /* struct definition, function prototype */ #endif 

Out of interest, these two uses are preserved in C ++, a constant definition can be implemented in other ways (better?).

0
source

Source: https://habr.com/ru/post/1486625/


All Articles