diff

Mike McNally m5 at lynx.uucp
Sat Jan 7 11:21:12 AEST 1989


While hacking on GNU diff to add the -D option, I noticed a seemingly
unavoidable problem with the whole concept.  The -D option generates
from two input files a single file containing all common lines from the
files, along with differences cleverly surrounded by cpp-style #ifdef's
(actually #ifndef's).  The idea is to produce a single source file from
two C modules (I guess it could be anything that normally gets cranked
through cpp on its way to fulfillment) and then get either version by
appropriate compilation switches.

The problem does not really lie with diff.  Rather, it appears because
cpp eats comments, and thus confuses itself.  Consider this possible
output from diff -DBALLOON version1.c version2.c:

/* 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.

Is my cpp screwed up (Greenhills)?  Should I worry about this?  Are there
ways known to smart people to avoid these problems?  Is the -D option
ever used anyway?  Did I waste my time kludging it into GNU diff?

-- 
Mike McNally                                    Lynx Real-Time Systems
uucp: {voder,athsys}!lynx!m5                    phone: 408 370 2233

            Where equal mind and contest equal, go.



More information about the Comp.unix.wizards mailing list