7.1. Effect of the Standard
There's a neither-fish-nor-fowl feel to the preprocessor. It leads an uncomfortable existence bolted on to the side of C without the benefit of either integrating properly with the rest of the language or, given one's natural reaction of revulsion at its ugly nature, being something that you could choose to do without. Back in the pre-history of C it actually was optional and people did write C without it; it's more or less an accident that it's come to be seen as being part of the bag and baggage of the C programming environment. It was used to make up for a couple of modest deficiencies in the language—the definition of constants and the inclusion of standard definitions—and slipped in through the back door as a result.
There has never been a widely accepted formal standard for a lot of what the preprocessor does and differing versions of it have been implemented in different systems. As a result, programs using anything other than the very basic features have proved to be a problem: it's hard to port them.
The primary job of the Standard was to define the behaviour of the preprocessor in line with common practice; this has been done and will not surprise anyone who was familiar with Old C. The Standard has gone further, amid an element of controversy, and specifies a number of additional features that were pioneered in some of the preprocessor's more popular dialects. The controversy results from the fact that although these features may be useful, there has never been much agreement on how to implement them. On the grounds that programs using these techniques were clearly non-portable already, the Standard has not worried too much about backwards compatibility in these areas. The fact that there is now a standard for these advanced features should improve the overall portability of C programs in the future.
At the simplest level the preprocessor is easy to use and can help
a lot to make programs easy to read and maintain. Using the advanced
features is best left to experts. In our experience, only the very
simplest use of #define
and the conditional compilation
#if
family are suitable for beginners. If this is your first
encounter with C, read the chapter once to see what you can pick up and
use the exercises to test your basic understanding. Otherwise, we would
suggest that at least six months experience is the minimum prerequisite
for a full attack. Because of that, we don't try too hard to give an easy
introduction in this chapter, but concentrate on getting down to
detail.