ANSI prototypes, the right choice...

Mike My Watch Has Windows Meyer mwm at pa.dec.com
Wed Feb 20 10:10:37 AEST 1991


In article <1205 at teslab.lab.OZ> andrew at teslab.lab.OZ (Andrew Phillips) writes:
   It depends on what you mean by "mixtures".  If you mean using float,
   short or char in prototypes and old style function definitions, ie:

   double f(float x);

   double f(x) float(x); { ... }

   then this would be a big problem and I would expect any ANSI compiler
   which found these in the same source file to generate an error.  If
   Lattice 5.10 does this then this is very bad, since the caller is
   going to pass a float and the callee expects a double.

   HOWEVER, I know that a lot of ANSI draft compilers, which had
   prototypes but came out before the ANSI new style function
   definitions were invented allowed this (but the caller would pass x
   as a double so it was OK).  Examples are older Lattice compilers
   (4.0?)

Lattice (SAS) 5.10 accepts this. Note that it's billed as a "pre-ANSI"
compiler; the 5.1 release was an upgrade to add AmigaDOS 2.0 support,
not ANSI.

What this compiler does when it sees an old style definition that has
a prototype in scope is to see if the types were "compatable" (all of
them being identical before implicit promotions was), and if so
compile the function as if it were defined with the prototype style.
After all, the compiler had a prototype, and the function definition
agreed with it. Turns out this causes problems when you try and write
code that needs to port across multiple ANSI compilers and non-ansi
compilers.

	<mike
--
Cats will be cats and cats will be cool			Mike Meyer
Cats can be callous and cats can be cruel		mwm at pa.dec.com
Cats will be cats, remember this words!			decwrl!mwm
Cats will be cats and cats eat birds.



More information about the Comp.std.c mailing list