Prototypes with old style definitions

Ken Raeburn raeburn at athena.mit.edu
Wed Feb 14 18:53:49 AEST 1990


In article <1990Feb13.133503.19793 at Jhereg.Minnetech.MN.ORG> mark at Jhereg.Minnetech.MN.ORG (Mark H. Colburn) writes:
>In article <2329 at dataio.Data-IO.COM> bright at Data-IO.COM (Walter Bright) writes:
(basically that
	float foo (float, int);
	float foo (x, n) float x; int n; { /* ... */ }
are incompatible, because the latter implies
	float foo (double arg_to_treat_as_float, int n))

>I was under the impression that the standard allowed parameters to be
>passed between functions without type coersion in this manner as long
>as there was a function prototype in effect.  If no function prototype
>is in effect then the second example would be correct.  However, using
>prototypes, the former should be correct.  If you wanted doubles

I had this argument a while back with a friend of mine from Lotus.  As I
recall, she was claiming that all of the ANSI C compilers she'd worked with
except gcc did what you suggest.  (I don't know which compilers or even which
machines she was working with -- mostly in the PC world, I think -- but I hope
not to have to use them.)

But there is a section of the ANS (which I can't point you to, since I don't
have my draft copy here) which says that the declaration implied by the
old-style definition is compatible only with prototypes with (among other
things) argument types that are compatible with the *promoted* type of the
corresponding argument in the definition.

The arguments I see basically go two ways:

1) Let's make the prototype not modify the behavior of the function.  This
   way, the compiled function doesn't depend on whether the prototype was
   visible (and therefore providing more information) when the definition was
   compiled.  (This is the course X3J11 chose.)

2) Let's make the prototype modify the function's behavior.  This means that
   the definition does not contain all the information about the function that
   is needed to compile it.  (Of course, to make life easier, we'll only
   require the prototype be in scope for the definition when you want to omit
   the default promotions.)  This way, we can get exactly what we want with
   our new fancy ANSI-compliant compilers, and our old crufty compilers can
   still swallow the code (since we're using "#if __STDC__", of course!), even
   though they'll waste extra space in the argument list and so forth.

I can make no claim as to what X3J11's reasoning was, but from at least one
point of view, option 1 above seems sufficiently persuasive.  (Of course,
my friend held the opposite point of view, but....)

-- Ken



More information about the Comp.lang.c mailing list