Parameter Types in Old-Style Function Definitions

D. Hugh Redelmeier hugh at dgp.toronto.edu
Sat Sep 15 15:11:26 AEST 1990


In article <2700 at dataio.Data-IO.COM> bright at Data-IO.COM (Walter Bright) writes:
>In article <1990Sep8.053408.2005 at alphalpha.com> nazgul at alphalpha.com (Kee Hinckley) writes:
><Consider the following function, defined in K&R:
><
><	foo(c, i)
><	char	c;
><	int	i;
><	{}
><Clearly the function expects to pick two ints up off of the stack.
><
><Now consider the same function, declared and used from ANSI C (or C++).
><	extern foo(char c, int i);
><
><So I guess the question is.  Does the ANSI spec mandate that the above be
><compatible, mandate that they aren't, or not say?
>
>They are *NOT* compatible. The prototype for the first one is:
>	int foo(int,int);
>which is not the same as:
>	int foo(char,int);
>even though some compilers allow this.


Actually, Walter is slightly wrong: the default argument promotions
on certain implementations may promote char to unsigned int.  But he
is right in that they cannot leave char as char, so the two
declarations are not compatible.

The fact that the default argument promotions are implementation
dependant is quite unfortunate.  This will even cause problems with
library functions.  For this reason, I think X3J11 should have
required that all char values be representable in "int"; if
sizeof(char)==sizeof(int), then char should be signed.  I said so in
a formal comment, but to no avail.

Hugh Redelmeier
{utcsri, yunexus, uunet!attcan, utzoo, scocan}!redvax!hugh
When all else fails: hugh at csri.toronto.edu
+1 416 482-8253



More information about the Comp.std.c mailing list