ANSI prototypes, the right choice...

Andrew Phillips andrew at teslab.lab.OZ
Tue Feb 19 17:38:05 AEST 1991


In article <1991Feb11.030811.25074 at sugar.hackercorp.com> peter at sugar.hackercorp.com (Peter da Silva) writes:
>You have it backwards. Lattice accepts mixtures. No other Ansi-compatible
>compiler I've used does...

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?) and Microsoft C 4.0 (MSDOS) and many UNIX compilers for a long
time.  So this is definitely a problem to look out for if you are
compiling old code (esp. if the prototype does not appear in the same
source file as the function defn).

OF COURSE, all new code should be written using prototypes and the
new style function definitions.  But mixing old and new is OK if you
avoid float, short and char in prototypes.

Andrew.
-- 
Andrew Phillips (andrew at teslab.lab.oz.au) Phone +61 (Aust) 2 (Sydney) 289 8712



More information about the Comp.std.c mailing list