Undeclared function arguments

Paul S. R. Chisholm psrc at poseidon.ATT.COM
Tue Oct 18 02:51:07 AEST 1988


<"He seemed like such a nice man . . . and then he turned out to be a writer!">

In article <13168 at dhw68k.cts.com>, Rick 'Transputer' Stein at dhw68k.cts.com
(Rick 'Transputer' Stein) asks why the following compiles cleanly:

yyback(p,m)
int *p;
{
	if (p==0)return(0);
	while(*p)
	{
	  if ( *p++ == 0 )return(1);
	}
	return(0);
}

> I've compiled this fragment along with the body of lex.yy.c on many
> machines and compilers (SGI/4D, HP9000, SUN/4, Inmos transputers with
> 3L,MSC 4.0, etc) and no errors have been generated.  Are undeclared
> function arguments auto casted to pointers?
>Rick 'Transputer' Stein, {felix, zardoz}!dhw68k!stein

According to K&R 1st ed. (p. 205), "Any [parameter-list] identifiers
whose type is not given are taken to be int."  p is declared and used
as a pointer.  m is implicitly declared an int, and not used at all!
(But lint should have complained about m as an unused argument.)

Paul S. R. Chisholm, psrc at poseidon.att.com (formerly psc at lznv.att.com)
AT&T Bell Laboratories, att!poseidon!psrc, AT&T Mail !psrchisholm
I'm not speaking for the company, I'm just speaking my mind.



More information about the Comp.lang.c mailing list