Kenneth Brody
2/9/2011 8:02:00 PM
On 2/9/2011 12:49 PM, Gand Alf wrote:
> Hello
>
> Imagine the following code occurring at Function Scope:
>
> {
> f();
> }
>
> Now there might be two valid programmer intentions here.
>
> Either he is declaring f to be a function returning int and taking an
> unspecified number of arguments.
>
> Or, he is calling a function f with no arguments and discarding it's
> return value.
>
> Most compilers seem to prefer the second interpretation. However, as it
> would be possible to call the function unambiguously by dereferencing:
> (*f)();
> wouldn't it be preferable for the first interpretation to be made?
One could also unambiguously declare the function using "int f();".
Which do you think is more likely the intended use? The function-scope
declaration, or a call to the function?
I would have to agree that I would be very surprised if this were meant to
declare the function, rather than call it. In fact, I would be very
surprised if my compiler treated it as such. (You say "most compilers", but
I would venture that it's quite possibly "all compilers".)
By the same argument, some compilers (and, I believe, the C99 standard
itself) allow declarations to occur within a code block, not just at the
top. If that were the case, how would one call a function which takes no
parameters, without having to jump through hoops with "(f)()"?
void foo()
{
bar();
printf("Hello, world.\n");
baz();
}
--
Kenneth Brody