(***f)(): PCC bug or legal C?
Sam Kendall
kendall at wjh12.UUCP
Tue Apr 17 15:59:02 AEST 1984
> So we take all of the bugs in PCC to be legal C? Try this [it works]:
>
> main()
> {
> int (*f)();
>
> (*f)();
> (**f)();
> f();
> (******f)();
> }
>
> What piffle.
Actually, although the last three calls are not legal according to the
reference manual, it is only `f()' which is illogical. The principle
(not quite in the reference manual) that makes `(***f)()' legal is:
If a subexpression of function type appears in an expression
not as the left operand of (), a pointer to the function
which is the value of the subexpression is generated.
Thus `*f' is of type "function", is converted to "pointer to function",
can then be indirected again: `**f'. And so on. So `(***f)()' works.
Unfortunately this principle is not quite in the ref man. What is
there:
If the name of a function appears in an expression not in the
function-name position of a call, a pointer to the function is
generated.
This language has the unfortunate consequences that (1) a function name
behaves differently than any other expression of function type, and (2)
`f()' is legal but `(f)()' is not, so parentheses interfere with the
semantics of the expression. If we fix up the ref man's language
according to modern ideas of programming language semantics, in
particular those from denotational semantics, we get something like my
language above. The change does not make any practical difference; it
just makes expression semantics simpler. They may not seem simpler, but
they really are; I do not justify this statement, except to note that my
change makes subexpressions of function type behave more like
subexpressions of array type--and I do not justify this last statement
either. Replies by mail, please.
Sam Kendall {allegra,ihnp4,ima,amd70}!wjh12!kendall
Delft Consulting Corp. decvax!genrad!wjh12!kendall
More information about the Comp.unix.wizards
mailing list