cgram.y boost to warn of null declarations

Arthur David Olson ado at elsie.UUCP
Thu Jun 13 07:39:32 AEST 1985


Maybe the error in the following program is obvious to you:

    #include <stdio.h>
    
    double;
    squared(x)
    double x;
    {
    	return x * x;
    }
    
    main()
    {
    	double	r;
    
    	for (r = 1.0; r < 1.5; r = r + 0.1)
    		printf("radius: %f; area: %f\n", r, 3.1415926535 * squared(r));
    }

Alas, the error isn't obvious to the 4.[12]bsd C compiler or to 4.[12]bsd lint.
Here's a change to "cgram.y" to warn about such problems.  Change the lines
reading:

	data_def:
			   oattributes  SM
				={  $1->in.op = FREE; }

to read:

	data_def:
			   oattributes  SM
				={
	#ifndef OLDVERSION
				    if ($1->in.type != STRTY &&
					$1->in.type != UNIONTY &&
					$1->in.type != ENUMTY)
						werror("null effect");
	#endif
				    $1->in.op = FREE;
				    }

--
UNIX is an AT&T Bell Laboratories trademark.
Lint is an Oscar Madison trademark.
--
	UUCP: ..decvax!seismo!elsie!ado    ARPA: elsie!ado at seismo.ARPA
	DEC, VAX and Elsie are Digital Equipment and Borden trademarks



More information about the Comp.unix.wizards mailing list