Prototyping char parameters in ANSI C

Steve Summit scs at adam.pika.mit.edu
Sat Apr 29 13:04:28 AEST 1989


In article <3950014 at eecs.nwu.edu> gore at eecs.nwu.edu (Jacob Gore) writes:
>Is this valid ANSI C (or dpANS or whatever you want to call it):
>	void f(char);
>	void f(c)
>	char c;
>	{}
>
>The version of GNU cc I have complains:
>	t.c:5: argument `c' doesn't match function prototype
>	t.c:5: a formal parameter type that promotes to `int'
>	t.c:5: can match only `int' in the prototype
>Is this rule for real, or is this just a gcc bug?

Poor GNU!  They get asked this ALL THE TIME, they put in a three
line warning/explanation message, and people still don't get the
idea.

To recap, either use

	void f(int);		void f(char);
			or
	void f(c)		void f(char c)
	char c;			{}
	{}

The only difference is that the second form may allow the
argument not to be widened when passed, for those architectures
which support passing sub-word sized arguments.  (In either case,
c will act like a char within function f, being narrowed if
necessary, and having its effective address adjusted so that
something like

	f(c)
	char c;
	{
	write(1, &c, 1);
	}

works correctly on big-endian architectures.  Don't write that,
though; write(,,1) brings a machine to its knees.)

                                            Steve Summit
                                            scs at adam.pika.mit.edu



More information about the Comp.lang.c mailing list