function prototype problem

Sean Fagan seanf at sco.COM
Thu Nov 17 15:59:22 AEST 1988


In article <8889 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
}In article <1704 at scolex> seanf at sco.COM (Sean Fagan) writes:
}-In article <310 at drd.UUCP> mark at drd.UUCP () writes:
}->char *rpeet  ( short, char );
}->char *rpeet ( num, ch )
}->    short num;
}->    char ch;
}-I, however, maintain what what ANSI says is that, if you declare a function
}-using old-style declaration (as you did), then you do not expand the
}-arguments unless a prototype is given; but if you use newstyle declarations
}-(char *rpeet ( short num, char ch) {), everything is as if you had also
}-given a prototype.
}
}I don't have the draft Standard at hand right now, but I'm pretty sure
}Stallman is right to have gcc diagnose this.  Old-style function syntax
}requires widened arguments but the prototype indicates unwidened.  This
}is clearly a type clash.  It is possible that the draft Standard really
}says that a compiler has to straighten things out in cases like this
}example, but I would find it surprising (and dangerous).

Ooops.  Just got a nice new copy of the Draft, and you're right:  Section
3.5.4.3 (Funciton declarators (including prototypes)), page 66, lines 8-12:

	If one type has a parameter type list and the other type is
specified by a function definition that contains a (possibly empty)
identifier list, both shall agree in the number of parameters, and the type
of each prototype parameter shall be compatable with the type that results
from the application of the default argument promotions to the type of the
corresponding identifier.

Ok.  Something I may have to look in for MSC.  I still think that somebody
should fix it so that GCC will accept the mixture, unless -ansi, or
-pendantic, is specified, but that's just me (or appears to be 8-)).

So, the moral of the story:  Don't pass in char's, short's, or float's to
your subroutines unless you want a Real(tm) ANSI C compiler to choke on it
8-).

-- 
Sean Eric Fagan  | "Engineering without management is *ART*"
seanf at sco.UUCP   |     Jeff Johnson (jeffj at sco)
(408) 458-1422   | Any opinions expressed are my own, not my employers'.



More information about the Comp.lang.c mailing list