mike@BRL.MIL (Mike Muuss) (01/12/91)
The following C program generates this error message on an SGI 4D/280 running IRIX 3.3.1: 80 wolf> cc -c goo.c ccom: Error: goo.c, line 20: redeclaration of formal parameter, stp int (*ft_shot)(struct soltab *stp); ---------------------------------------^ ccom: Error: goo.c, line 21: unknown size }; ^ ccom: Error: goo.c, line 21: unknown size }; ^ This program fragment represents valid ANSI C code. struct soltab { int a; int b; }; int (*prep)(struct soltab *stp); int (*grep)(struct soltab *stp); int j; /* This way does work */ struct rt_gunktab { int (*ft_prep)(struct soltab *); int (*ft_shot)(struct soltab *); }; /* This way does not work */ struct rt_functab { int (*ft_prep)(struct soltab *stp); int (*ft_shot)(struct soltab *stp); }; It would seem that using variable names inside prototypes is causing the compiler difficulties with a symbol table of some sort. Quoting from K&R (2nd ed), pg 218: "If the declarators in the parameter declarations contain identifiers and the function declarator does not head a function definition, the identifiers go out of scope immediately." and "In the new-style declaration int strcpy(char *dest, const char *source), rand(void); .... The parameter names are effectively comments." While this style of declaration seems to work in simple cases on the SGI, structures containing multiple function pointers with prototypes that have repeated parameter names seem to make the compiler choke. Just for reference, this is not a problem on the Cray ANSI C compiler. Could this please be filed as a Software Problem Report? Best, -Mike
davea@quasar.wpd.sgi.com (David B.Anderson) (01/15/91)
In article <9101120521.aa04946@WOLF.BRL.MIL> mike@BRL.MIL (Mike Muuss) writes: >The following C program generates this error message on an SGI >4D/280 running IRIX 3.3.1: > >80 wolf> cc -c goo.c >ccom: Error: goo.c, line 20: redeclaration of formal parameter, stp > int (*ft_shot)(struct soltab *stp); > ---------------------------------------^ >/* This way does not work */ >struct rt_functab { > int (*ft_prep)(struct soltab *stp); > int (*ft_shot)(struct soltab *stp); >}; This is a compiler botch fixed in ANSI C (released Jan 8) and in the 4.0 release of Traditional C. As Mike discovered, the workaround is to leave off the prototype argument names: struct rt_functab { int (*ft_prep)(struct soltab *); int (*ft_shot)(struct soltab *); }; Bug reports like this are of great value! Thanks for taking the time to make a small and complete example. [ David B. Anderson Silicon Graphics (415)335-1548 davea@sgi.com ] [``What can go wrong?'' --Calvin to Hobbes]