cpp: Line Control
1
1 6 Line Control
1 **************
1
1 The C preprocessor informs the C compiler of the location in your source
1 code where each token came from. Presently, this is just the file name
1 and line number. All the tokens resulting from macro expansion are
1 reported as having appeared on the line of the source file where the
1 outermost macro was used. We intend to be more accurate in the future.
1
1 If you write a program which generates source code, such as the
1 'bison' parser generator, you may want to adjust the preprocessor's
1 notion of the current file name and line number by hand. Parts of the
1 output from 'bison' are generated from scratch, other parts come from a
1 standard parser file. The rest are copied verbatim from 'bison''s
1 input. You would like compiler error messages and symbolic debuggers to
1 be able to refer to 'bison''s input file.
1
1 'bison' or any such program can arrange this by writing '#line'
1 directives into the output file. '#line' is a directive that specifies
1 the original line number and source file name for subsequent input in
1 the current preprocessor input file. '#line' has three variants:
1
1 '#line LINENUM'
1 LINENUM is a non-negative decimal integer constant. It specifies
1 the line number which should be reported for the following line of
1 input. Subsequent lines are counted from LINENUM.
1
1 '#line LINENUM FILENAME'
1 LINENUM is the same as for the first form, and has the same effect.
1 In addition, FILENAME is a string constant. The following line and
1 all subsequent lines are reported to come from the file it
1 specifies, until something else happens to change that. FILENAME
1 is interpreted according to the normal rules for a string constant:
1 backslash escapes are interpreted. This is different from
1 '#include'.
1
1 '#line ANYTHING ELSE'
1 ANYTHING ELSE is checked for macro calls, which are expanded. The
1 result should match one of the above two forms.
1
1 '#line' directives alter the results of the '__FILE__' and '__LINE__'
11 predefined macros from that point on. ⇒Standard Predefined
Macros. They do not have any effect on '#include''s idea of the
1 directory containing the current file.
1