The form of horizontal whitespace in the input file

Info icon This preview shows pages 52–54. Sign up to view the full content.

View Full Document Right Arrow Icon
The form of horizontal whitespace in the input file is preserved in the output. In partic- ular, hard tabs remain hard tabs. This can be useful if, for example, you are preprocessing a Makefile. Traditional CPP only recognizes C-style block comments, and treats the ‘ /* ’ sequence as introducing a comment only if it lies outside quoted text. Quoted text is introduced by the usual single and double quotes, and also by an initial ‘ < ’ in a #include directive.
Image of page 52

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

View Full Document Right Arrow Icon
Chapter 10: Traditional Mode 49 Traditionally, comments are completely removed and are not replaced with a space. 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.
Image of page 53
Image of page 54
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern