new style declarations OK for old style definitions?

Stephen Clamage steve at taumet.com
Fri Apr 5 02:40:04 AEST 1991


tmb at ai.mit.edu (Thomas M. Breuel) writes:

>K&R/2 is a little vague on the following question: under what
>circumstances is it legal to declare using new-style syntax a
>separately compiled function that was compiled with an old-style
>definition. 

>Is it sufficient to use only promoted arguments in the new-style
>declaration?

You must not use char, short or float arguments in any of the
declarations (nor in the ultimate function header).  The function
must not accept a variable number of parameters, and the prototype
must not include the ellipsis (...).  These rules will allow
portability of the code.

>Conceivably, the whole calling sequence for old style and new style
>definitions could differ. Is it legal for the compiler to choose
>completely incompatible calling sequences for old-style and new-style
>declarations?

Not when the above rules are followed.  If you violate any of these rules,
a conforming compiler is allowed to use different calling sequences.

>It would certainly be desirable, since new-style
>declarations seem to allow for significant optimizations that aren't
>possible with old-style declarations.

Yes.  Prototyped functions may use different parameter passing for
chars, shorts, and floats, and would do so if they are more efficient.
In particular, when a function is declared with an ellipsis, the compiler
may use a different method of passing the extra parameters than if you
call a non-prototyped function.

>This is a frequent problem if you have old library binaries and
>sources but want the extra type checking from an ANSI compiler.

>				Thanks, Thomas.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list