[comp.os.minix] ACK cc Having but ignoring prototypes can be dangerous

cagney@chook.ua.oz (Andrew Cagney - aka Noid) (09/22/89)

It has been suggested that the minix C compiler accept prototypes but
ignore them. [It may even have been me :-)] Below is an example of a
hazard' of doing this.

One of the effects of having a prototype is to force the
conversion of values before they are passed as parameters. For instance
pass a character to a long parameter (as below) then in ansi c the character
is automatically converted. However in old c no such conversion occures.

Consequently programs that do work under an ansi compiler will break
under a pseudo ANSI, prototype ignoring, compiler :-)

I think that if possible prototypes should be included in the compileras a complete facility but
BUT only if they are going to be used.

Try running the program below (if you have turbo c) with the ansi flag (-A) on
and off.

                                        Andrew Cagney (noid)

#ifdef __STDC__
void p(long a)
#else
void p(a)
  long a;
#endif
{
  printf("Long val is %ld\n",a);
}

main() {
  p('a');
}