[net.lang.c] Declaring argument types

gnu@sun.UUCP (John Gilmore) (09/13/83)

Now if only one could use the same syntax to declare a function
as to define it...eg, if you can say

int foo(int, struct bar *);

then can you say

int foo(int x, struct bar *p) {
	return x + p->foo;
}

Also, I assume that if you define the function in the same source file,
the compiler will default to checking and coercing the types of the
arguments in subsequent calls.  What do you do if you don't want that?
Perhaps declare it the old way first?  eg:

int foo();
int foo(x, y, p)
	int x, y;
	char *p;
{
	mess around with variable numbers of args
}

I know it's silly to comment on a proposal before it's been made, but
that's often the only time the designers are willing to consider changes...

alan@allegra.UUCP (09/13/83)

Well, if we want the declaration to be given in the same format as
the definition, wouldn't it be better to say

	extern char *foo(x, p)
		int x;
		struct bar *p;

than to change the way functions are defined?  This would be more
difficult to parse, though.  You could always say

	extern char *foo(x, p)
		int x;
		struct bar *p;
	{}

to make life easier for yacc.


	Alan Driscoll
	Bell Labs, Murray Hill

marks@grkermit.UUCP (Mark A. Swanson) (09/14/83)

One of the C compilers we use for PDP-11 work supports the suggested
alternate function format, e.g.
 int printf(char *msg, int arg1, arg2, arg3)
   {
   ...
   }

It also allows function declerations to cooerce arguments: e.g.
  extern int ftn(float a,b);

 foo()
   {
   int k, l;

   ftn(k,l);
   }

will automatically cast k & l appropriately.  However, we have gone
through and removed all such usages, since no other C compiler has them,
they cause LINT to barf, etc.
   The compiler in question is a much modified version of the one
Bill Plauger did for Yourdon before he started Whitesmiths, Inc and
is not available.
    Having used both formats, I do think the revisions are an improvement,
producing more readable code and fewer mismatched argument bugs.  But they're
not valuable enough to justify an incompatible compiler, alas.

  Mark Swanson
  ...decvax!genrad!grkermit!marks

richl@tektronix.UUCP (Rick Lindsley) (09/21/83)

<Flame up>
I'm afraid I must take issue with any proposal to make C look like
Pascal, which is where this discussion is leading. Pascal is a
marvelous language to learn as a first language, it's got structure
and picky syntax and all that good stuff. Unfortunately, for any
practical purposes it is very unwieldy. I can see it now; we start
by allowing the arguments to functions to be declared within
the function header and in a little while, people will want to be
able to declare their arrays like foo[6..20] instead of foo[14].

I have written a small scheduler in modula (a pascal look-alike),
and I speak from experience. It has been said many times, but I'll
say it again: the beauty of C is that it is simple in its concepts.
Don't go cluttering it up with remnants of other languages.
<flame down>

Rick Lindsley
richl@tektronix
...!tektronix!richl