diff

Steve Summit scs at adam.pika.mit.edu
Sun Jan 8 05:39:06 AEST 1989


In article <5174 at lynx.UUCP> m5 at lynx.UUCP (Mike McNally) writes:
>While hacking on GNU diff to add the -D option, I noticed a...problem.
>The -D option generates...a single file containing all common lines...
>along with...[clever]...cpp-style #ifdef's.  The problem...appears because
>cpp eats comments, and thus confuses itself.
>
>/* This is the beginning of a multi-line comment.  It describes a certain
>#ifndef BALLOON
>   C function, which might be used to open text files.  The comment ends
>#else BALLOON
>   C function, which might be used to close text files.  The comment ends
>#endif BALLOON
>   with a single uninteresting line. */
>
>The preprocessor can't deal with this setup; the interaction of #things and
>comments causes lots of problems.

I wouldn't think this particular example would cause a problem,
since all three preprocessor directives are commented out, and
should be ignored.  (Maybe there is a problem with your
preprocessor.)  Truly problematic cases can certainly be
imagined, involving unmatched comments within the #ifdef.

In general, it's a good idea to double-check the output of diff -D
to see if it behaved reasonably.  (In the example given, you'd
probably just scratch the #ifdefs within a comment anyway.)

>Is the -D option
>ever used anyway?  Did I waste my time kludging it into GNU diff?

diff -D is very handy; I use it all the time.  (It's often
superior to rcsmerge, since it only requires two versions, not
three -- rcsmerge needs a common ancestor.)  However, if you're
working with diff -D, fix its other problem: the

	#else BALLOON
and
	#endif BALLOON

forms have never been portable, and are (I believe) explicitly
disallowed by ANSI-C.  If you like the comments on #else and
#endif lines (I can take them or leave them), change them (in
this case, change the printf statements within diff which
generate them) to bona-fide comments:

	#else /* BALLOON */
	#endif /* BALLOON */

                                            Steve Summit
                                            scs at adam.pika.mit.edu



More information about the Comp.unix.wizards mailing list