#line feature in C preprocessor

utzoo!decvax!duke!mcnc!rlgvax!guy utzoo!decvax!duke!mcnc!rlgvax!guy
Sat Feb 19 03:37:57 AEST 1983


I looked at the source to:

1) the V7 version of cpp

2) the 4.1BSD version of cpp

3) the USG UNIX 3.0.1 (System III) version of cpp

and my scan *seems* to indicate that this "feature" may be present in all
versions.  The problem *seems* to be that the only thing that "cpp" does
when it sees '#line nnn file' is to write '# nnn file' to the output.
It also writes '# nnn file', where here nnn is its internal idea of the
current line number and file is its internal idea of the current file,
whenever these change.  Unfortunately, '#line' does NOT change its internal
idea of the current line number or of the current file, it merely causes the
directive to the C compiler to be output.  It looks like it could be made
to reset its internal counters, so I suspect it doesn't for some reason
(i.e., it's probably not a bug).

As of USG UNIX 5.0 (System V), Our Mother who art in Murray Hill documents
both of the major undocumented features of the V7 (John Reiser) C preprocessor.
To wit, the "defined()" operator in #if (permitting you to get the equivalent
of

#ifdef FOO || BAR

by saying

#if defined(FOO) || defined(BAR)

and the __FILE__ and __LINE__ built-in variables.  As such, all you people
who implemented your own preprocessors should go back and put those features
in (especially given that a lot of people have been using them already).

					Guy Harris
					RLG Corporation
					...!decvax!mcnc!rlgvax!guy



More information about the Comp.lang.c mailing list