Path: utzoo!attcan!uunet!husc6!bloom-beacon!adam.pika.mit.edu!scs From: scs@adam.pika.mit.edu (Steve Summit) Newsgroups: comp.unix.wizards Subject: Re: diff Message-ID: <8660@bloom-beacon.MIT.EDU> Date: 7 Jan 89 19:39:06 GMT References: <5174@lynx.UUCP> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: scs@adam.pika.mit.edu (Steve Summit) Distribution: na Lines: 50 In article <5174@lynx.UUCP> m5@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@adam.pika.mit.edu