"BartC" <> writes:
> I have a C code generator that likes to insert lots of parentheses in type
> declarations (rather than truly understand how they work).
>
> But when declaring a function returning a pointer:
>
> int (*fn) (void);
>
> int (*fn) (void ) {return NULL;}
>
> the prototype works, but not the definition (it's a syntax error). How do I
> have to change the latter to make it compile?
>
> Everywhere else the extra parentheses don't seem to be a problem.
That's not a valid function definition.
Your first line declares an object `fn` of pointer-to-function type,
which is perfectly valid.
The declaration part of the function definition (the part outside
{...}) declares a pointer-to-function type. A function definition
has to declare something of function type, not pointer type.
You could drop the parentheses:
int fn(void) { return 0; }
Note that I've changed the return expression, since NULL is normally
used for pointers.
Or you might have something like this:
int func(void) { return 0; }
int (*fn)(void) = func;
I can't tell which of these would suit your purposes.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"