[net.lang.c] K&R App A, par. 8 & 8.2, on Declarations, Defaulting.

hans@log-hb.UUCP (Hans Albertsson) (06/24/84)

[]
In K&R App A, para 8, it is stated
declaration:
	decl-specifiers declarator-list(optional);

and
decl-specifiers:
	type-specifier decl-specifiers(optional);
	sc-specifiers decl-specifiers(optional);


In para 8.2 it is stated: If the type-specifier is missing from a
declaration, it is taken to be int.

I interpret this to mean that a declaration MUST have either a minimum
of one type-specifier, or a minimum of one sc-specifier, and, PROVIDING
this condition is being met, int may be assumed, that is, 
all of

auto a;
int b;
short c;
register int d;
register e;

are acceptable, as opposed to 

a = 1;

since there is NO specifier of any sort in the latter case.

Am I right or wrong? What will ANSI say in this matter?

I know that the Sargasso C for TOPS10/20 requires what I consider correct.
UNIX pcc-based compilers permit the "a = 1;" form. 


-- 
			{decvax,philabs}!mcvax!enea!log-hb!hans
			Hans Albertsson, 
			TeleLOGIC AB
			Box 1001,
			S-14901 Nynashamn,
			SWEDEN

woods@hao.UUCP (Greg "Bucket" Woods) (07/04/84)

  I don't know what the manual or the standards say, but under no
circumstances should

a = 1;

be allowed as a valid declaration. Gramatically it is indistinguishable
from an assignment statement! If it were the first statement after the
declaration section, should it be flagged as a multiple declaration
error if "a" were declared above as a pointer to something, or should
it assign a pointer of the appropriate type to location 1? If it is legal,
it stinks.

--Greg
-- 
{ucbvax!hplabs | allegra!nbires | decvax!stcvax | harpo!seismo | ihnp4!stcvax}
       		        !hao!woods
   
   "I only want to hold you, I don't want to tie you down"

dgary@ecsvax.UUCP (07/11/84)

<>
>From: ka@hou3c.UUCP Thu Jul  5 23:59:08 1984
>The statement "a = 1;" should be a valid global declaration.  For
>declarations inside a function, "int a = 1;" should be required.
>				Kenneth Almquist

I agree that "a = 1;" should be a valid global declaration, but see
nothing wrong with it as a local one.  The statements "int a=1;"
"int a; a = 1;" and "a = 1;" should all produce equivalent code!
This is because of the way C handles initialization of automatic
local variables.  The only problem I can see is in letting the
compiler tell where the declarations end and the statements begin.
If you allow this as a valid declaration, that's not a problem.

D Gary Grady
Duke University Computation Center, Durham, NC  27706
(919) 684-4146
USENET:  {decvax,ihnp4,akgua,etc.}!mcnc!ecsvax!dgary

jdb@mordor.UUCP (John Bruner) (07/12/84)

Allowing automatic variables to be declared with "x = 1;" instead of
"int x = 1;" can produce ambiguities.  Consider

int *p = &something;			int *p = &something;

func()					func()
{					{
	*p = 0;					int *p = 0;
	return(p);				return(p);
}					}

This should not treat "*p = 0;" as an automatic variable definition;
rather, it must be interpreted as a reference to the global "p".

Also, "int *p = 0;" does not do the same thing as "int *p; *p = 0;".
The first case sets "p" to NULL, the second case sets the integer
pointed-to by (the garbage) pointer "p" to zero.
-- 
  John Bruner (S-1 Project, Lawrence Livermore National Laboratory)
  MILNET: jdb@mordor.ARPA [jdb@s1-c]	(415) 422-0758
  UUCP: ...!ucbvax!dual!mordor!jdb 	...!decvax!decwrl!mordor!jdb