{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Since a traditional compiler does its own

Info iconThis preview shows pages 53–55. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Since a traditional compiler does its own tokenization of the output of the preprocessor, this means that comments can effectively be used as token paste operators. However, comments behave like separators for text handled by the preprocessor itself, since it doesn’t re-lex its input. For example, in #if foo/**/bar ‘ foo ’ and ‘ bar ’ are distinct identifiers and expanded separately if they happen to be macros. In other words, this directive is equivalent to #if foo bar rather than #if foobar Generally speaking, in traditional mode an opening quote need not have a matching closing quote. In particular, a macro may be defined with replacement text that contains an unmatched quote. Of course, if you attempt to compile preprocessed output containing an unmatched quote you will get a syntax error. However, all preprocessing directives other than #define require matching quotes. For example: #define m This macro’s fine and has an unmatched quote "/* This is not a comment. */ /* This is a comment. The following #include directive is ill-formed. */ #include <stdio.h Just as for the ISO preprocessor, what would be a closing quote can be escaped with a backslash to prevent the quoted text from closing. 10.2 Traditional macros The major difference between traditional and ISO macros is that the former expand to text rather than to a token sequence. CPP removes all leading and trailing horizontal whitespace from a macro’s replacement text before storing it, but preserves the form of internal whitespace. One consequence is that it is legitimate for the replacement text to contain an unmatched quote (see Section 10.1 [Traditional lexical analysis], page 48 ). An unclosed string or char- acter constant continues into the text following the macro call. Similarly, the text at the end of a macro’s expansion can run together with the text after the macro invocation to produce a single token. Normally comments are removed from the replacement text after the macro is expanded, but if the ‘-CC ’ option is passed on the command line comments are preserved. (In fact, the current implementation removes comments even before saving the macro replacement text, but it careful to do it in such a way that the observed effect is identical even in the function-like macro case.) The ISO stringification operator ‘ # ’ and token paste operator ‘ ## ’ have no special mean- ing. As explained later, an effect similar to these operators can be obtained in a different way. Macro names that are embedded in quotes, either from the main file or after macro replacement, do not expand. Chapter 10: Traditional Mode 50 CPP replaces an unquoted object-like macro name with its replacement text, and then rescans it for further macros to replace. Unlike standard macro expansion, traditional macro expansion has no provision to prevent recursion. If an object-like macro appears unquoted in its replacement text, it will be replaced again during the rescan pass, and so on ad infinitum...
View Full Document

{[ snackBarMessage ]}

Page53 / 83

Since a traditional compiler does its own tokenization of...

This preview shows document pages 53 - 55. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online