Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site elsie.UUCP Path: utzoo!watmath!clyde!burl!mgnetp!ihnp4!houxm!houxz!vax135!cornell!uw-beaver!tektronix!hplabs!hao!seismo!rlgvax!cvl!elsie!ado From: ado@elsie.UUCP Newsgroups: net.bugs.4bsd Subject: 4.1bsd lint and cc differ on syntax Message-ID: <1126@elsie.UUCP> Date: Sat, 21-Jul-84 18:06:30 EDT Article-I.D.: elsie.1126 Posted: Sat Jul 21 18:06:30 1984 Date-Received: Mon, 23-Jul-84 02:11:44 EDT Organization: NIH-LEC, Bethesda, MD Lines: 64 Patient-- /usr/src/cmd/cpp/cpp.c Symptom-- "lint" gives "syntax error" diagnostics on some programs that "cc" is happy with. Repeat by-- Pass this program through "cc" and "lint"; compare diagnostic output. #define NBPC 8 /* Number of Bits Per Character */ main() { #if NBPC == 8 return 0; #else return -1; #endif } Diagnosis-- "lint" does a "/lib/cpp -C ..." to do preprocessing. "cc" does a "/lib/cpp" without the -C. A line like #if 8 /* comment */ == 8 (which is what the #if directive in the example above "expands" to) is syntactically correct if the comment is removed, and is a syntax error if the comment is allowed to stand. Cure-- Always remove comments in preprocessor directives. The changes below will do this, changing the "syntax error" you get when lint is run to one about "nonportability." ed /usr/src/cmd/cpp/cpp.c /passcom/a #ifndef OLDVERSION STATIC int inif; /* we're in an #if directive */ STATIC int oldpasscom; /* saved passcom for duration of #if */ #endif . /comment/a #ifndef OLDVERSION if (oldpasscom && inif) ppwarn("nonportable comment in #if"); #endif . /yyparse/i #ifndef OLDVERSION inif = 1; oldpasscom = passcom; passcom = 0; #endif . /yyparse/a #ifndef OLDVERSION inif = 0; passcom = oldpasscom; #endif . -- ...decvax!allegra!umcp-cs!elsie!ado (301) 496-5688 (DEC, VAX and Elsie are Digital Equipment Corp. and Borden's trademarks)