MFC Programmer's SourceBook : Thinking in C++
Bruce Eckel's Thinking in C++, 2nd Ed Contents | Prev | Next

Begin and end comment tags

A very important issue with this book is that all code that you see in the book must be automatically extractable and compilable, so it can be verified to be correct (with at least one compiler). To facilitate this, all code listings that are meant to be compiled (as opposed to code fragments, of which there are few) have comment tags at the beginning and end. These tags are used by the code-extraction tool ExtractCode.cpp in chapter 23 to pull each code listing out of the plain-ASCII text version of this book (which you can find on the Web site http://www.BruceEckel.com).

The end-listing tag simply tells ExtractCode.cpp that it’s the end of the listing, but the begin-listing tag is followed by information about what subdirectory the file belongs in (generally organized by chapters, so a file that belongs in Chapter 8 would have a tag of C08), followed by a colon and the name of the listing file.

Because ExtractCode.cpp also creates a makefile for each subdirectory, information about how a program is made and the command-line used to test it is also incorporated into the listings. If a program is stand alone (it doesn’t need to be linked with anything else) it has no extra information. This is also true for header files. However, if it doesn’t contain a main( ) and is meant to be linked with something else, then it has an {O} after the file name. If this listing is meant to be the main program but needs to be linked with other components, there’s a separate line that begins with //{L} and continues with all the files that need to be linked (without extensions, since those can vary from platform to platform).

Here’s an example of a stand-alone program:

Here’s a more complicated example that involves two header files, two implementation files and a main program that requires a link line:

Here’s the makefile that ExtractCode.cpp generated for this appendix:

If a file should be extracted but the begin- and end-tags should not be included in the extracted file (for example, if it’s a file of test data) then the begin-tag is immediately followed by a ‘ !’, like this:

Contents | Prev | Next


Go to CodeGuru.com
Contact: webmaster@codeguru.com
© Copyright 1997-1999 CodeGuru