Declarations

Hi Guys,

I would like your opinion on this;
are the following two declarations equivalent ?
If not, why ?

1)
 
void (*f(struct t *p, long int n))(void);

and

2)
 
void *f(struct t *p, long int n)(void);


I need to declare a function with two parameters: a pointer to a struct tagged t, and a long int n. The function takes no parameters and has no return value.
My solution was 1), but in a C coursebook I found 2), which I don't like as it seems more confusing to me.
Your view would be appreciated. Cheers

Osor77
I need to declare a function with two parameters: a pointer to a struct tagged t, and a long int n. The function takes no parameters and has no return value.


Erm, huh?
Osor77 wrote:
I need to declare a function with two parameters: a pointer to a struct tagged t, and a long int n. The function takes no parameters and has no return value.
My solution was 1), but in a C coursebook I found 2), which I don't like as it seems more confusing to me.


I think you have read the book wrong. Like Zhuge implied, this makes no sense.

Number 2 is not legal as far as I can tell.

You need to explain what you want a bit better I think.
void (*f(struct t *p, long int n))(void);

I think that would be a function taking two parameters returning a "pointer to a function taking no parameters and returning void".
That's right.
The second one is incorrect to C/C++ - bacuse it is trying to return a function and you don't have objects of type function.
thanks for the answers.
Yes, it was late at night and the description I wrote was wrong. I needed the function with those two parameters to return a pointer to a function with no parameters and no return value.

It looks like the solution in the book is wrong
thanks again
Topic archived. No new replies allowed.