🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1713

Re: Parameter Types in Old-Style Function Definitions

#1713
From: D. Hugh Redelmeier
Date: Sat, 15 Sep 1990 05:11
39 lines
2065 bytes
In article <2700@dataio.Data-IO.COM> bright@Data-IO.COM (Walter Bright) writes:
>In article <1990Sep8.053408.2005@alphalpha.com> nazgul@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@csri.toronto.edu
+1 416 482-8253
Technical Details
Message-ID: <1990Sep15.011126.23112@jarvis.csri.toronto.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!sun-barr!cs.utexas.edu!news-server.csri.toronto.edu!dgp.toronto.edu!hugh
References: <10391@pt.cs.cmu.edu> <2689@dataio.Data-IO.COM> <1990Sep8.053408.2005@alphalpha.com> <2700@dataio.Data-IO.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!sun-barr!cs.utexas.edu!news-server.csri.toronto.edu!dgp.toronto.edu!hugh
From: hugh@dgp.toronto.edu (D. Hugh Redelmeier)
Newsgroups: comp.std.c
Subject: Re: Parameter Types in Old-Style Function Definitions
Keywords: parameter, function
Message-ID: <1990Sep15.011126.23112@jarvis.csri.toronto.edu>
Date: 15 Sep 90 05:11:26 GMT
References: <10391@pt.cs.cmu.edu> <2689@dataio.Data-IO.COM> <1990Sep8.053408.2005@alphalpha.com> <2700@dataio.Data-IO.COM>
Organization: CSRI, University of Toronto
Lines: 39