Preprocessing Programs

It is a curious fact that C#, which aims to correct the mistakes of Java, has a limited form of the C preprocessor. Originally, when C was first developed, the preprocessor was a separate program, which removed comments, included files, made macro substitutions, did conditional compilation, and then passed the resulting output to the compiler. That is, the preprocessor is the 'front end' of a C++ compiler, which always gets to do any processing before passing source onto the compiler, hence the name pre-processor. The GCC compiler included with this book has a standalone preprocessor cpp, which you can use to see preprocessor output as the compiler sees it. The following DOS command will redirect this output (which is often very long) into another file (by default it writes to standard output):

C:gcc	est> cpp hello.cpp > hello.pcc
					

Most modern compilers, including UnderC, include the preprocessor as an integral part of their input stage for efficiency reasons, but they still have to do the tasks that are discussed in this appendix.

The #include Directive

The #include directive inserts a source file into the stream of code that the compiler sees. That source file in turn may contain #include directives, but the result is a single stream of source code. This is, incidentally, why traditional C++ compilers can be so slow; your program may have 15 lines, but when all the headers are included, the compiler sees thousands, and sometimes even hundreds of thousands, of lines of code.

The simple rule is that #include "file" loads the file from the current directory and #include<file> loads the file from the include directory, but you can specify multiple include paths in some compilers. The idea is to separate application header files from library files that are common to all applications.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.29.22