[net.bugs.4bsd] 4.1bsd lint and cc differ on syntax

ado@elsie.UUCP (07/22/84)

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)