ANSI prototypes, the right choice...

Rahul Dhesi dhesi%cirrusl at oliveb.ATC.olivetti.com
Tue Feb 12 10:58:34 AEST 1991


My experience is that if you want to keep your code reasonably
portable to non-ANSI-C environments but also take advantage of
the additional compile-time checking provided by function
prototypes, then the best way to do this is mix the old and
new styles like this:

     int myfunc PARAMS((int i, char *p));
     ...

     int myfunc (i, p)
     int i;
     char *p;
     {...}

What's good about this style is:  (a) It is compatible with both ANSI
and non-ANSI C environments;  (b) In an ANSI C environment, most
reasonable compilers will give you all of the intra-file checking that
you get with new-style definitions; (c) In a UNIX environment lint is
still fully usable and will do cross-file checking (which ANSI C
compilers can't do).

The only disadvantage of the above strategy is that it does not take
advantage of the slight increase in efficiency that you get if you have
char or float parameters and they are declared in the new style so that
runtime widening is not needed.  I don't think this advantage is enough
to sacrifice portability by using new-style definitions.
--
Rahul Dhesi <dhesi%cirrusl at oliveb.ATC.olivetti.com>
UUCP:  oliveb!cirrusl!dhesi



More information about the Comp.std.c mailing list