[net.bugs.4bsd] Block Structure Declarations

jim@kovacs.UUCP (05/24/84)

>
According to K&R in "The C Programming Language" Sect 4.8, page 81:

   "Declarations of variables (including initializations)
   may follow the left brace that introduces *ANY* compound
   statement, not just the one that begins a function.
   Variables declared in this way supersede any identically
   named variables in outer blocks..."

Three examples are given. One example not given is:

	f(x)
	double x;
	{
		short x;
		...
	}

Within function "f", occurences of "x" refer to the internal "short"
variable. The compiler will not say a word about this. Lint says
"argument x unused in function f". Since I cannot think of a single
case where one would intentionally do this, I think the compiler
should warn that argument x is being redeclared.

-Jim Keating-
R. Abel & Assoc.
Hollywood, CA 90038
(213) 462 8100

mp@whuxle.UUCP (Mark Plotnick) (05/27/84)

This was fixed in the Draft ANSI C Standard I saw.  It says:
"Every formal parameter is in effect declared at the head of the
compound statement constituting the function body, so redeclaration
in the function body is an error."

Doesn't prevent you from redeclaring the function name itself, of course...
	Mark

gwyn@brl-vgr.ARPA (Doug Gwyn ) (05/29/84)

The UNIX System V "lint" claims:
	warning: x redefinition hides earlier one
which sounds like just what you wanted to be told about this usage.