Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are C preprocessor statements a part of the C language?

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

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

Since this was in an introductory programming class, I suspect that he was merely simplifying the relationship between the source file and the compiler, but nevertheless I wish to verify my understanding.

Are preprocessor statements completely independent from the C language (dependent on the specific compiler used) or are they explicitly described in the C99 standard? Out of curiosity, did K&R ever mention preprocessor macros?

like image 200
Vilhelm Gray Avatar asked Dec 26 '22 01:12

Vilhelm Gray


2 Answers

Yes, the standard describes the preprocessor. It's a standardized part of the C language.

Note that #include, which is essential for modularization of code, is a preprocessor directive.

In the publically-available draft of the C99 standard, the preprocessor is described in section 6.10.

like image 61
unwind Avatar answered Dec 29 '22 09:12

unwind


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

However the C preprocessor can work with other languages than C for any kind of simple file preprocessing (I have seen it used with LaTeX files for example).

like image 30
Louen Avatar answered Dec 29 '22 07:12

Louen