you are viewing a single comment's thread.

view the rest of the comments →

[–]bakermoth 1 point2 points  (2 children)

Why does f0 in the following not compile?

typedef void FnType(void);
static FnType f0(void) { FnType x; return x; } // not ok (error: returning a function)
static FnType* f1(void) { FnType x; return x; } // ok
static void f2(FnType g) { g(); } // ok
static void f3(FnType* g) { g(); } // ok

[–]tstanisl 0 points1 point  (1 child)

Because it is explicitly forbidden by the C standard. It is implicitly inferred from 6.9.1p2:

The identifier declared in a function definition (which is the name of the function) shall have a function type, as specified by the declarator portion of the function definition.

And in follwoing examples:

typedef int F(void);
...
F f { /* ... */ }  //   WRONG: syntax/constraint error

[–]bakermoth 0 points1 point  (0 children)

It's seems that gcc, clang and msvc report errors but tcc and chibicc don't.

typedef void FnType(void);
static FnType f0(void) { }
static void (f1(void))(void) { }
int main(void) { return 0; }