Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!WATCSG.BITNET!GIGUERE From: GIGUERE@WATCSG.BITNET (Eric Giguere) Newsgroups: comp.sys.amiga.tech Subject: Prototypes & the default promotions (was about the new RKM stuff.. Message-ID: <8903111954.AA04828@jade.berkeley.edu> Date: 11 Mar 89 19:55:51 GMT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 55 X-Unparsable-Date: Sat, 11 Mar 1989 14:49 LCL In article <15751@oberon.USC.EDU>Marco Papa writes: >Actually things are not as bad as they look, simply because every >implementation of the 'C' langage has to respect the following rule, >excerpted from page 186 of K&R: > >"Any actual argument of type float are converted to double before the call; >any of type char or short are converted to int;" > ^^^^^ ^^^ This is one reason why you shouldn't be using the 1st edition of K&R anymore as the "final" reference document. With Lattice 5.0 out now and Manx 5.0 out in a few months, the ANSI standard will be de rigueur. Let me quote Section 3.3.2.2 of the draft Standard (Dec 7, 1988): "If ... the called function ... does not include a prototype, the integral promotions are performed on each argument and arguments that have type float are promoted to double." but then: "If ... the called function ... includes a prototype, the arguments are implicitly converted, as if by assignment, to the types of the corresponding parameters." So if a prototype is in scope, the default argument promotions are NOT performed. In the following example the first call passes an int and the second a short: extern void f(); /* no parameter information */ short s = 0; f( s ); /* short gets promoted to int */ extern void f( short ); short s = 0; f( s ); /* short stays as short */ One of the major changes the Committee made was to make the Standard Library "invariant" to the default promotions -- i.e., any functions that previously expected a char or short were redefined to expect an int so that the presence or absence of a prototype would make no difference. Prototypes can be nasty at times. However, when Manx 5.0 comes out, proper use of prototypes will solve the 16- vs. 32-bit int problem quite nicely. Eric Giguere Computer Systems Group, University of Waterloo BITNET: GIGUERE@WATCSG Other: giguere@watcsg.UWaterloo.CA UUNET : watcsg!giguere@uunet.UU.NET