On Mar 20, 11:44 am, Sanchit wrote:

> On Mar 20, 7:57 pm, Ben Bacarisse wrote:

>

>

>

> > Sanchit writes:

> > > #include

>

> > > void (*signal(int signo, void (*func)(int)))(int);

>

> > > I am unable to understand that what is the last (int) representing.

> > > What this function is returning (of what type).

>

> > A function returning a pointer to a function has the type of that

> > returned function pointer "wrapped round" it: the type on the left is

> > the return type of the returned function pointer (not of the function

> > we are defining) and the bracketed parameters on the right are the

> > parameters of this returned function pointer type:

>

> > (*f( )) ( )

>

> > So, ignoring the parameters of f for now, we see that f returns a

> > pointer to a function taking parameters P and returning R.

>

> > so, writing signal in this form:

>

> > void (*signal( int signo, void (*func)(int) )) (int);

>

> > we see it should be read as:

>

> > void (*signal( )) (int);

>

> > i.e. that signal returns a pointer to a function that takes a single

> > int and which return void.

>

> > > And how above function can be redefined as this:

>

> > > typedef void Sigfunc(int);

> > > Sigfunc *signal(int, Sigfunc *);

>

> > After the typedef, Sigfunc is simply a name for the type "function

> > which takes an int and returns void". Hence a function that returns a

> > "Sigfunc *" is one that returns a pointer to such a function. That is

> > exactly what signal does.

>

> > Finally, note that the second parameter is a pointer to exactly the

> > same kind of function, so the second parameter can also be a "Sigfunc *".

>

> > --

> > Ben.

>

> You said that P is the parameter then what are here?

Read this:

http://www.ericgiguere.com/articles/...l?noprint=true

Following the rules there, including the ANSI additions:

void (*signal(int signo, void (*func)(int))) (int);

Gives: declare signal as function (with first parameter of type int

and second parameter of type pointer to function (with first parameter

of type int) returning void) returning pointer to function (with first

parameter of type int) returning void.

In other words, signal is a function with:

* 1st parameter of type int

* 2nd parameter of type pointer to function (a function with param

of type int, returning void)

And signal returns a pointer to a function, which also has parameter

of type int, and returns void.

Jason

P.S. Sorry if this is a double post, Google Groups is getting a little

strange on me.