The following code won't compile:
int function() foo(int i);
int* p;
void main() {
foo(*p)();
}
because foo(*p)() looks like a C-style declaration of p being a pointer to a function that returns type foo. Too work around, add parentheses:
(foo(*p)());
I can't see any way to fix this without dispensing with C style function pointer declarations.
Comment #1 by tomas — 2008-10-04T17:41:17Z
> I can't see any way to fix this without dispensing with C style function pointer declarations.
Seems very reasonable to remove these to me
Comment #2 by dfj1esp02 — 2008-10-09T06:17:48Z
(In reply to comment #0)
> C-style declaration of p being a pointer to a
> function that returns type foo.
foo doesn't look like type to me, it's rather a forward declaration of a function. So compiler just needs to distinguish functions from types.
Comment #3 by smjg — 2008-11-24T10:17:14Z
That would be a dependency of parsing on semantic analysis, which is something D by design doesn't have.
I agree that C-style function pointer declarations should be thrown out, just as C-style cast syntax has been already.
Comment #4 by ellery-newcomer — 2010-03-17T13:11:43Z
*** Issue 3980 has been marked as a duplicate of this issue. ***
Comment #5 by bugzilla — 2010-11-09T19:46:40Z
The disambiguation rule for "is it a declaration or a statement" is resolved by the rule "if it looks like a declaration, it is a declaration". The behavior you're seeing is as designed.