[gnu.gcc.bug] Bug in gcc 1.26: ansi prototypes

raeburn@ATHENA.MIT.EDU (Ken Raeburn) (10/20/88)

No, this is not a bug.  As the documentation should describe, the
dpANS specifies that a function definition of the form:

	int foo (x)
		char x;
	{
		/* ... */
	}

means that an argument of type int is passed, and is treated as a char
within the function.  Similar promotions occur if the argument is
declared as type "short".  This means that you are defining a function
which would only be compatible with the "int" prototype (or no
prototype at all).

The type is not being converted in the prototype, as you suspected,
but in the function definition, because it is using an "old-style"
(non-prototype) format.  Since the definition comes after the
prototype declaration, this is where the error is reported.  It could
be argued that the error should be reported on the line containing the
prototype; it could also be argued that it's good enough as it is.

t35124p%puukko.hut.fi@MITVMA.MIT.EDU (Tatu Yl|nen) (10/20/88)

/*

Bug in Gnu C compiler version 1.26: type checking in prototypes

Compiling the following code with gcc version 1.26 gives incorrect error
messages.  Type checking in prototypes is not done correctly.  It looks
like gcc converts the type given in the prototype to int (or whatever
the argument type is usually converted to in function arguments).
This converted type is then compared against the actual function
arguments in the function definition.  The error is reported in the
function definition.  The fix must prevent converting argument types
in prototypes.

The program generates the error when compiled with the command
  gcc -c foo.c

The computer is a 386-based AT with 10MB of ram and a 350MB scsi disk.
It is running Microport System V/386 (System V release 3.0).

   Tatu Yl|nen     ylo@hupu.hut.fi     ..!mcvax!santra!hupu!ylo

*/
/*---------------------- cut here --------------------------*/
int a(char x);                    /* gives an error - this is wrong   */
/* int a(char);                      /* gives an error - this is wrong   */
/* int a(int);                       /* gives no error - this is wrong   */
/* int a();                          /* gives no error - this is correct */

int a(x) char x;
{
  return x == 'b';
}
/*----------------------- cut here -------------------------*/