469,964 Members | 1,563 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

How to understand function prototype signal()

Hello,

1.
The prototype of function signal in signal.h:

void (*signal(int sig, void (*func)(int)))(int);
is some complex to me. Would you please explain it to me in detail with
the C language syntax itself. Thank you!

2.
And I saw another function prototype:

void interrupt ( *oldhandler)();
-Is it legal?

-If it's a right prototype, what does identifier "interrupt" mean? Will
it be a type qualifier.

---
Thanks
lovecreatesbeauty

Nov 14 '05 #1
2 5633
None <lo***************@gmail.com> wrote:

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

type pointer to (function with one int parameter returning void)

*signal()

signal is a function returning pointer
(Note:
(*signal)()
would mean: signal is a pointer to function)

void (*signal())(int);

signal is a function returning pointer to (function with one int
param returning void)

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

signal is a function with two parameters, returning pointer etc...
The first parameter is type int, the second parameter is type:

void (*)(int)

ie. pointer to function with one int parameter returning void.
The original declaration is equivalent to:
void (*signal(int, void (*)(int)))(int);
ie. the parameters of `signal' don't have to be named, similarly
parameter to `func' was not named.

Note that the type of the second parameter of `signal' is the same
as the type that `signal' returns, ie. "pointer to (fn with one int
param, returning void)".

It's easier to understand if you declare a type:

typedef void (*ptr_void_fn_int)(int);
ptr_void_fn_int signal(int, ptr_void_fn_int);

(ptr_void_fn_int is type "pointer to (fn with one etc...)").

`signal' function for a given signal number sets the new signal
handler you supply (which is type ptr_void_fn_int) and returns
you the previous handler (which naturally has to be the same type).
(For exact `signal' semantics see N869 7.14.1.1.)

void interrupt ( *oldhandler)(); -Is it legal? -If it's a right prototype, what does identifier "interrupt" mean? Will
it be a type qualifier.


`interrupt' is not an ISO C keyword. It probably denotes function
call convention, and means that the function `oldhandler' points to
will be called from outside as an interrupt handler (but I might be
very wrong here). You have to consult your compiler manual.

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #2
Stan Tobias,

Thank you

S.Tobias wrote:
None <lo***************@gmail.com> wrote:

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


void (*)(int)

type pointer to (function with one int parameter returning void)

*signal()

signal is a function returning pointer
(Note:
(*signal)()
would mean: signal is a pointer to function)

void (*signal())(int);

signal is a function returning pointer to (function with one int
param returning void)

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

signal is a function with two parameters, returning pointer etc...
The first parameter is type int, the second parameter is type:

void (*)(int)

ie. pointer to function with one int parameter returning void.
The original declaration is equivalent to:
void (*signal(int, void (*)(int)))(int);
ie. the parameters of `signal' don't have to be named, similarly
parameter to `func' was not named.

Note that the type of the second parameter of `signal' is the same
as the type that `signal' returns, ie. "pointer to (fn with one int
param, returning void)".

It's easier to understand if you declare a type:

typedef void (*ptr_void_fn_int)(int);
ptr_void_fn_int signal(int, ptr_void_fn_int);

(ptr_void_fn_int is type "pointer to (fn with one etc...)").

`signal' function for a given signal number sets the new signal
handler you supply (which is type ptr_void_fn_int) and returns
you the previous handler (which naturally has to be the same type).
(For exact `signal' semantics see N869 7.14.1.1.)

void interrupt ( *oldhandler)();

-Is it legal?

-If it's a right prototype, what does identifier "interrupt" mean? Will it be a type qualifier.


`interrupt' is not an ISO C keyword. It probably denotes function
call convention, and means that the function `oldhandler' points to
will be called from outside as an interrupt handler (but I might be
very wrong here). You have to consult your compiler manual.

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`


Nov 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jing You | last post: by
2 posts views Thread by lovecreatesbeauty | last post: by
2 posts views Thread by Harshankumar | last post: by
5 posts views Thread by rashmi | last post: by
9 posts views Thread by cmk128 | last post: by
3 posts views Thread by yawnmoth | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.