By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,827 Members | 2,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,827 IT Pros & Developers. It's quick & easy.

How to understand function prototype signal()

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.