spaf@PURDUE.EDU (Gene Spafford) (10/06/88)
Index: gcc 1.28 on a Sun 3/50, 3/60, 3/280 all running 3.4 SunOS Source to reproduce problem: #include <stdio.h> int bar () { printf("hi!\n"); } void foo (x) int x (); { x(); } int main() { foo(bar); } As I understand both K&R C and the new draft, this program should not compile because the declaration of "int x ()" should conflict with the parameter "x" provided as an argument. Sun "cc" correctly flags this as an error, but gcc does not. (The correct declaration should be "int (*x) ();" ) Script: Script started on Wed Oct 5 13:06:05 1988 uther(96)> cc bogus.c "bogus.c", line 9: x declared as parameter to non-function "bogus.c", line 9: warning: a function is declared as an argument uther(97)> gcc -traditional bogus.c uther(98)> gcc -ansi bogus.c uther(99)> gcc -pedantic bogus.c uther(100)> ./a.out hi! uther(101)> ^D script done on Wed Oct 5 13:06:53 1988
drh@notecnirp.Princeton.EDU (Dave Hanson) (10/06/88)
In article <8810051813.AA01101@uther.cs.purdue.edu> spaf@PURDUE.EDU (Gene Spafford) writes: >Index: > gcc 1.28 on a Sun 3/50, 3/60, 3/280 all running 3.4 SunOS > >Source to reproduce problem: int bar () { printf("hi!\n"); } void foo (x) int x (); { x(); } int main() { foo(bar);} As I understand both K&R C and the new draft, this program should not compile because the declaration of "int x ()" should conflict with the parameter "x" provided as an argument. not quite. foo is defined in `old-style' and hence there's no argument checking done for calls to foo like the foo(bar). also, the type of argument x is automatically converted from `int function' to `pointer to int function' as stipulated at the top of p. 218 in K&R2. hence, there are no errors.