469,890 Members | 1,432 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Some complex function prototypes like signal()

Hello,

I'm confused by some complex function prototypes. Would you please
explain those to me in detail with C language syntax itself with your
rich knowledge & experiences. Thank you.
1. The prototype of function signal in signal.h:

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

it's some complex to me. Please explain the C language syntax used to
make up this complex prototype.

2. And I saw another function prototype:

void interrupt (*oldhandler)();

-Is it legal?

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

Thanks

---
lovecreatesbeauty

Nov 14 '05 #1
2 1730

lovecreatesbeauty wrote:
I'm confused by some complex function prototypes.
"The C Programming Language" has a good section on this subject. They
provide source for a program that translates these type definitions
into english.
void (*signal(int sig, void (*func)(int)))(int);
You can simplify this:

/* Pointer to a function that takes an int and returns nothing. */
typedef void (*SIGNAL_HANDLER)(int);

/* Simplified signal prototype. */
SIGNAL_HANDLER signal( int signal, SIGNAL_HANDLER handler );
void interrupt (*oldhandler)();

This is a pointer to a function which returns nothing.

Nov 14 '05 #2
al.h:

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

it's some complex to me. Please explain the C language syntax used to
make up this complex prototype.


The return type for signal is a function pointer that, when called takes
one int argument.

func is a function pointer that takes one int argument.

For more about function pointers, see http://www.newty.de/fpt/index.html

Jon
----
Learn to program using Linux assembly language
http://www.cafeshops.com/bartlettpublish.8640017
Nov 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by shan_rish | last post: by
9 posts views Thread by Grumble | last post: by
73 posts views Thread by Steph Barklay | last post: by
6 posts views Thread by Syren Baran | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.