473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 5986
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jing You | last post by:
hi every one, I have got some confused problem when I try to write some custom object by javascript. Look at the example code here: <BODY> <script language="jscript">
2
by: lovecreatesbeauty | last post by:
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....
9
by: | last post by:
void show( char *s, ...) is a function seemd like prinf code -------------- #include <stdio.h> #include <stdarg.h> void show( char *s, ...) { va_list stage;
2
by: Harshankumar | last post by:
Hello, I have the following questions 1) can we pass the parameters to interrupt? 2)can we return the parameters from interrupt Regards harshan
5
by: rashmi | last post by:
Hello All, tp.c:107: error: syntax error before '*' token tp.c:108: warning: function declaration isn't a prototype tp.c:121: error: syntax error before '*' token tp.c:122: warning: function...
9
by: cmk128 | last post by:
Hi Why put * in front of the function name in the declaration? int (*write)(struct inode *, struct file *, const char *, int); thanks from Peter (cmk128@hotmail.com)
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
3
by: yawnmoth | last post by:
Based on my understanding of the apply function, the following code snippet should, at the very least, not yield any errors. Unfortunately, it does, suggesting my understanding is... limited. Any...
20
by: David Mathog | last post by:
For this small test program: #include <stdio.h> void main(void){ char buffer="ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; int size, count; size = 27; /* always a small number which will fit in an int */...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.