[gnu.gcc.bug] Procedure prototypes defined before structures

andrewt@watsnew.waterloo.edu (Andrew Thomas) (10/11/89)

I am not sure where this should go, so I'm sending it to gcc and ghostscript:

I recently tried to compile ghostscript 1.3 using the gnu gcc 1.36
compiler on a uVax II running Ultrix 2.0.   The most prevalent bug
found in the compilation was a complaint:

In file included from gsfont.c:29:
gxfont.h:29: warning: `struct gs_show_enum_s' declared inside parameter list
gxfont.h:29: warning: its scope is only this definition or declaration,
gxfont.h:29: warning: which is probably not what you want.

or stuff just like it.

The code for this contains the following:

int gs_no_build_char_proc
     (struct gs_show_enum_s *, gs_state *, gs_font *, int, char * );

 
int
gs_no_build_char_proc(struct gs_show_enum_s *penum, gs_state *pgs,
		      gs_font *pfont, int chr, char *data)
{	return 1;			 
}

There is no type definition for struct gs_show_enum_s.  I have also
noted that this behaviour occurs if the typedef struct
gs_show_enum_s comes _after_ the function prototype.  Consider the
following trivial example:

------------ tst.c ---- compile with gcc -o tst tst.c -Wall -------
#include <stdio.h>

int bob (struct _blimp*, int);

typedef struct _blimp
{
  int   i;
} blimp;

int main ()
{
  blimp*	x = 0;
  bob (x, 8);
  return (0);
}

int bob (blimp* b, int i)
{
  printf ("%x, %d\n", b, i);
  return (i);
}

--------------------------------

For the gcc folks, is this a bug, or intentional.  It seems reasonable
to me to insist that the prototypes follow the type declarations, so I
would not be inclined to call it a bug,  but why the crazy warning?
As an afterthought, why is it possible to declare a pointer to a
structure that has not been created in another structure, but not in a
function prototype?

For the ghostscript folks, GCC 1.36 currently insists that types be
declared before they appear in function prototypes.  This breaks
ghostscript compilations miserably.  It seems like poor programming
practice to reverse these declarations anyway.  Perhaps this could be
a fix in 1.4?  Also, gcc notes a couple of other errors in the
ghostscript code, including a wrong number of parameters in one
prototype.  I can send the complete compilation log to anybody who is
interested.

--

Andrew Thomas
andrewt@watsnew.waterloo.edu	Systems Design Eng.	University of Waterloo
"If a million people do a stupid thing, it's still a stupid thing." - Opus