123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- [Main]
- Title=Initial processing
- [Top]
- The preprocessor performs a series of textual transformations on its
- input. These happen before all other processing. Conceptually, they
- happen in a rigid order, and the entire file is run through each
- transformation before the next one begins. CPP actually does them
- all at once, for performance reasons. These transformations correspond
- roughly to the first three "phases of translation" described in the C
- standard.
- <OL>
- <LI>
- The input file is read into memory and broken into lines.
- <BR><BR>
- CPP expects its input to be a text file, that is, an unstructured
- stream of ASCII characters, with some characters indicating the end of a
- line of text. Extended ASCII character sets, such as ISO Latin-1 or
- Unicode encoded in UTF-8, are also acceptable. Character sets that are
- not strict supersets of seven-bit ASCII will not work. We plan to add
- complete support for international character sets in a future release.
- <BR><BR>
- Different systems use different conventions to indicate the end of a
- line. GCC accepts the ASCII control sequences <CODE>LF</CODE>, <CODE>CR
- LF</CODE>, <CODE>CR</CODE>, and <CODE>LF CR</CODE> as end-of-line markers. The first
- three are the canonical sequences used by Unix, DOS and VMS, and the
- classic Mac OS (before OSX) respectively. You may therefore safely copy
- source code written on any of those systems to a different one and use
- it without conversion. (GCC may lose track of the current line number
- if a file doesn't consistently use one convention, as sometimes happens
- when it is edited on computers with different conventions that share a
- network file system.) <CODE>LF CR</CODE> is included because it has been
- reported as an end-of-line marker under exotic conditions.
- <BR><BR>
- If the last line of any input file lacks an end-of-line marker, the end
- of the file is considered to implicitly supply one. The C standard says
- that this condition provokes undefined behavior, so GCC will emit a
- warning message.
- <BR><BR>
- </LI>
- <LI>
- If trigraphs are enabled, they are replaced by their
- corresponding single characters. By default GCC ignores trigraphs,
- but if you request a strictly conforming mode with the <B>'-std'</B>
- option, or you specify the <B>'-trigraphs'</B> option, then it
- converts them.
- <BR><BR>
- These are nine three-character sequences, all starting with <CODE>??</CODE>,
- that are defined by ISO C to stand for single characters. They permit
- obsolete systems that lack some of C's punctuation to use C. For
- example, <CODE>??/</CODE> stands for <CODE>\</CODE>, so <CODE>'??/n'</CODE> is a character
- constant for a newline.
- <BR><BR>
- Trigraphs are not popular and many compilers implement them incorrectly.
- Portable code should not rely on trigraphs being either converted or
- ignored. If you use the <B>'-Wall'</B> or <B>'-Wtrigraphs'</B> options,
- GCC will warn you when a trigraph would change the meaning of your
- program if it were converted.
- <BR><BR>
- In a string constant, you can prevent a sequence of question marks from
- being confused with a trigraph by inserting a backslash between the
- question marks. <CODE>"(??\?)"</CODE> is the string <CODE>(???)</CODE>, not
- <CODE>(?]</CODE>. Traditional C compilers do not recognize this idiom.
- <BR><BR>
- The nine trigraphs and their replacements are
- <PRE>Trigraph: ??( ??) ??< ??> ??= ??/ ??' ??! ??-
- Replacement: [ ] { } # \ ^ | ~
- </PRE>
- </LI>
- <LI>
- Continued lines are merged into one long line.
- <BR><BR>
- A continued line is a line which ends with a backslash, <CODE>\</CODE>. The
- backslash is removed and the following line is joined with the current
- one. No space is inserted, so you may split a line anywhere, even in
- the middle of a word. (It is generally more readable to split lines
- only at white space.)
- <BR><BR>
- The trailing backslash on a continued line is commonly referred to as a
- <U>backslash-newline</U>.
- <BR><BR>
- If there is white space between a backslash and the end of a line, that
- is still a continued line. However, as this is usually the result of an
- editing mistake, and many compilers will not accept it as a continued
- line, GCC will warn you about it.
- <BR><BR>
- </LI>
- <LI>
- All comments are replaced with single spaces.
- <BR><BR>
- There are two kinds of comments. <U>Block comments</U> begin with
- <CODE>/*</CODE> and continue until the next <CODE>*/</CODE>. Block comments do not
- nest:
- <PRE>/* this is /* one comment */ text outside comment
- </PRE>
- <U>Line comments</U> begin with <CODE>//</CODE> and continue to the end of the
- current line. Line comments do not nest either, but it does not matter,
- because they would end in the same place anyway.
- <PRE>// this is // one comment
- text outside comment
- </PRE>
- </LI>
- </OL>
- It is safe to put line comments inside block comments, or vice versa.
- <PRE>/* block comment
- // contains line comment
- yet more comment
- */ outside comment
- // line comment /* contains block comment */
- </PRE>
- But beware of commenting out one end of a block comment with a line
- comment.
- <PRE> // l.c. /* block comment begins
- oops! this isn't a comment anymore */
- </PRE>
- Comments are not recognized within string literals. <CODE>"/* blah
- */"</CODE> is the string constant <CODE>/* blah */</CODE>, not an empty string.
- <BR><BR>
- Line comments are not in the 1989 edition of the C standard, but they
- are recognized by GCC as an extension. In C++ and in the 1999 edition
- of the C standard, they are an official part of the language.
- <BR><BR>
- Since these transformations happen before all other processing, you can
- split a line mechanically with backslash-newline anywhere. You can
- comment out the end of a line. You can continue a line comment onto the
- next line with backslash-newline. You can even split <CODE>/*</CODE>,
- <CODE>*/</CODE>, and <CODE>//</CODE> onto multiple lines with backslash-newline.
- For example:
- <PRE>/\
- *
- */ # /*
- */ defi\
- ne FO\
- O 10\
- 20
- </PRE>
- is equivalent to <CODE>#define FOO 1020</CODE>. All these tricks are
- extremely confusing and should not be used in code intended to be
- readable.
- <BR><BR>
- There is no way to prevent a backslash at the end of a line from being
- interpreted as a backslash-newline. This cannot affect any correct
- program, however.
|