Re: malloc problem
Keith Thompson wrote:[color=blue]
>
> Mark McIntyre <markmcintyre@s pamcop.net> writes:[color=green]
> > On 31 Mar 2005 18:04:52 GMT, in comp.lang.c , mwojcik@newsguy .com
> > (Michael Wojcik) wrote:
> >[color=darkred]
> >>That's not how I read 9899-1990 5.1.2.2.1:
> >>
> >> int main(void) { /*...*/ }[/color]
> >
> > this is totally equivalent to
> > int main() {/*...*/}
> >
> > in a function definition.[/color]
>
> I think you're right. C99 6.7.5.3p14 says:
>
> [...] An empty list in a function declarator that is part of a
> definition of that function specifies that the function has no
> parameters. The empty list in a function declarator that is not
> part of a definition of that function specifies that no
> information about the number or types of the parameters is
> supplied.
>
> I had been thinking that int main() would allow mismatched arguments
> on a recursive call to main, but the above shows that I was mistaken.
> I just tried a test case on several compilers, and most of them appear
> to get this wrong as well, issuing no diagnostics for the following:
>
> #include <stdio.h>
>
> void foo()
> {
> printf("In foo\n");
> }
>
> int main()
> {
> foo();
> foo(42);
> return 0;
> }[/color]
Old style function types don't include the parameter types.
int main() is old style.
int main(void) is more better.
--
pete
Keith Thompson wrote:[color=blue]
>
> Mark McIntyre <markmcintyre@s pamcop.net> writes:[color=green]
> > On 31 Mar 2005 18:04:52 GMT, in comp.lang.c , mwojcik@newsguy .com
> > (Michael Wojcik) wrote:
> >[color=darkred]
> >>That's not how I read 9899-1990 5.1.2.2.1:
> >>
> >> int main(void) { /*...*/ }[/color]
> >
> > this is totally equivalent to
> > int main() {/*...*/}
> >
> > in a function definition.[/color]
>
> I think you're right. C99 6.7.5.3p14 says:
>
> [...] An empty list in a function declarator that is part of a
> definition of that function specifies that the function has no
> parameters. The empty list in a function declarator that is not
> part of a definition of that function specifies that no
> information about the number or types of the parameters is
> supplied.
>
> I had been thinking that int main() would allow mismatched arguments
> on a recursive call to main, but the above shows that I was mistaken.
> I just tried a test case on several compilers, and most of them appear
> to get this wrong as well, issuing no diagnostics for the following:
>
> #include <stdio.h>
>
> void foo()
> {
> printf("In foo\n");
> }
>
> int main()
> {
> foo();
> foo(42);
> return 0;
> }[/color]
Old style function types don't include the parameter types.
int main() is old style.
int main(void) is more better.
--
pete
Comment