DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

(cpp.info.gz) Combining Sources

Info Catalog (cpp.info.gz) Conditionals (cpp.info.gz) Top (cpp.info.gz) Other Directives
 
 Combining Source Files
 ======================
 
    One of the jobs of the C preprocessor is to inform the C compiler of
 where each line of C code came from: which source file and which line
 number.
 
    C code can come from multiple source files if you use `#include';
 both `#include' and the use of conditionals and macros can cause the
 line number of a line in the preprocessor output to be different from
 the line's number in the original source file.  You will appreciate the
 value of making both the C compiler (in error messages) and symbolic
 debuggers such as GDB use the line numbers in your source file.
 
    The C preprocessor builds on this feature by offering a directive by
 which you can control the feature explicitly.  This is useful when a
 file for input to the C preprocessor is the output from another program
 such as the `bison' parser generator, which operates on another file
 that is the true source file.  Parts of the output from `bison' are
 generated from scratch, other parts come from a standard parser file.
 The rest are copied nearly verbatim from the source file, but their
 line numbers in the `bison' output are not the same as their original
 line numbers.  Naturally you would like compiler error messages and
 symbolic debuggers to know the original source file and line number of
 each line in the `bison' input.
 
    `bison' arranges this by writing `#line' directives into the output
 file.  `#line' is a directive that specifies the original line number
 and source file name for subsequent input in the current preprocessor
 input file.  `#line' has three variants:
 
 `#line LINENUM'
      Here LINENUM is a decimal integer constant.  This specifies that
      the line number of the following line of input, in its original
      source file, was LINENUM.
 
 `#line LINENUM FILENAME'
      Here LINENUM is a decimal integer constant and FILENAME is a
      string constant.  This specifies that the following line of input
      came originally from source file FILENAME and its line number there
      was LINENUM.  Keep in mind that FILENAME is not just a file name;
      it is surrounded by doublequote characters so that it looks like a
      string constant.
 
 `#line ANYTHING ELSE'
      ANYTHING ELSE is checked for macro calls, which are expanded.  The
      result should be a decimal integer constant followed optionally by
      a string constant, as described above.
 
    `#line' directives alter the results of the `__FILE__' and
 `__LINE__' predefined macros from that point on.   Standard
 Predefined.
 
    The output of the preprocessor (which is the input for the rest of
 the compiler) contains directives that look much like `#line'
 directives.  They start with just `#' instead of `#line', but this is
 followed by a line number and file name as in `#line'.   Output.
 
Info Catalog (cpp.info.gz) Conditionals (cpp.info.gz) Top (cpp.info.gz) Other Directives
automatically generated byinfo2html