new style declarations OK for old style definitions?

Brian Bliss bliss at sp64.csrd.uiuc.edu
Fri Apr 5 06:34:18 AEST 1991


In article <14590 at life.ai.mit.edu>, 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?
|> 
|> 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? It would certainly be desirable, since new-style
|> declarations seem to allow for significant optimizations that aren't
|> possible with old-style declarations.
|> 

K&RII says (I'm reciting from memory, my book's at home):

If a function which is declared new-style is called, and
no prototype for it exists in the current scope, the 
promoted type of the actual argument must agree exactly
with the unpromoted type of the formal argument.

Since the compiler could not know whether the function
was declared new-style or old-style (burp :-), it must
use the same calling conventions for both.

you are asking the converse, ig you can call an old-style function
with a (new-style) prototype existing for it in the current scope, but I
believe it is implicitly specified that using a prototype
with promoted arguments is O.K.

My question is why?  just eliminate the prototype, or if
you need the parameter type checking, change the definition
of your function to be new-style, and change all of the formal
arguments to their promoted types.  Then you are following
the ANSI standard to the letter.

bb



More information about the Comp.lang.c mailing list