Declarations and defaulting in C

boykin at datagen.UUCP boykin at datagen.UUCP
Thu Jul 5 00:43:36 AEST 1984


RE: Hans Albertson's question about declarations and defaults
in C, the following, taken from both K&R and the ANSI draft standards
document is legal:

	a;
	int b[10];
	c = 4;
	main()
	{
	...
	}

In call cases the declarations are of type 'int' and storage class
'extern' i.e. global variables.  Personally I think the declarations
of both 'a' and 'c' are terrible programming practice, but it IS legal.

As Hans said in his note, K&R allows defaults for both type-declaration
and storage class.  After those two, there isn't much left to a declaration!

As also pointed out, how do you tell the difference between the
declaration of 'c' and an assignment to 'c' if this is within
a function body?  Answer, you can't.  Hence this type of declaration
is only allowable outside the scope of a function.

The ANSI committee has ruled that this type of declaration has been
and will continue to be legal even though none of the members of
the committee like that type of declaration.  The point is is that
taking it out would break some user code.  One of the chief
concerns of the ANSI committee is that we never break user code,
even if we don't like the 'cracks' in the language that that code
takes advantage of.

I hope that clears up the question(s).

Joe Boykin
Member, ANSI Committee X3J11

Data General Corp.
Distributed Systems Group
(allegra, ihnp4)!datagen!boykin



More information about the Comp.lang.c mailing list