ANSI prototypes, the right choice...

Eric Giguere giguere at csg.uwaterloo.ca
Wed Feb 6 02:59:53 AEST 1991


In article <7708 at sugar.hackercorp.com> peter at sugar.hackercorp.com (Peter da Silva) writes:
>For all you Lattice-C programmers, I have a little hint for writing more
>portable programs:
>
>	int foo(int a, int b);
>
>This is *not* compatible with a function declared:
>
>	int foo(a, b)
>	int a, b;
>	{
>		...
>	}

Strictly speaking, this is not true.  What you are describing must be
a Lattice-specific warning.  Problems WOULD arise if you had the
following declarations:

    int foo( char a, char b );

    int foo( a, b )
      char a, b;
      {
        ...
      }

The prototype won't agree because the "char a, b" in the second declaration
will get promoted to "int a, b" using the old-style default promotion rules.
(I.e., char & short --> int, float --> double). 

If you're not going to be using prototypes all the time, then you should
make sure that any functions you declare in the new style, such as:

	int fubar( char a, float b, int c )
      {
      }

should actually look like:

	int fubar( int a, double b, int c )
      {
      }

If you take a look at the ANSI standard library you'll see they made all
the library functions look like this so that lack of prototypes won't
bite you...

--
Eric Giguere                                       giguere at csg.UWaterloo.CA
           Quoth the raven: "Eat my shorts!" --- Poe & Groening



More information about the Comp.std.c mailing list