PATH  Documentation > Mac OS X > Developer Tools > The GNU C Preprocessor


Previous | Contents | Next

Combining Source Files

One of the jobs of the C preprocessor is to tell the C compiler the source file and line number that each line of C code came from.

C code can come from multiple source files if you use #include or #import . If you include header files, or if you use conditionals or macros, the line number of a line in the preprocessor output may be different from the line number of the same line in the original source file. Normally you would want both the C compiler (in error messages) and the GDB debugger to use the line numbers of your source file.

The C preprocessor offers a #line command by which you can control this feature explicitly. #line specifies the original line number and source file name for subsequent input in the current preprocessor input file. #line has three variants:

Command
Description

#line linenum

linenum is a decimal integer constant. This resets the current line number in the source file to linenum.

#line linenum " file "

linenum is a decimal integer constant and " file "    is a string constant. This resets the line number to linenum and changes the name of the file referred to by file .

#line macros

macros should be one or more macros that have been defined by earlier preprocessing directives. When the macros have been expanded by the preprocessor, the #line instruction will then resemble one of the first two forms and be interpreted appropriately.

#line commands alter the results of the __FILE__ and __LINE__ predefined macros from that point on. See the section " See Predefined Macros ."

The output of the preprocessor (which is the input for the rest of the compiler) contains commands that look much like #line commands. They start with just # instead of #line , but this is followed by a line number and file name as in #line .


The GNU C Preprocessor

Previous | Contents | Next