Thread View: gnu.gcc.bug
2 messages
2 total messages
Started by Gene Spafford
Wed, 05 Oct 1988 18:13
Bug with functions as parameters?
Author: Gene Spafford
Date: Wed, 05 Oct 1988 18:13
Date: Wed, 05 Oct 1988 18:13
44 lines
1372 bytes
1372 bytes
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
Re: Bug with functions as parameters?
Author: Dave Hanson
Date: Wed, 05 Oct 1988 22:22
Date: Wed, 05 Oct 1988 22:22
22 lines
1293 bytes
1293 bytes
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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads