473,405 Members | 2,344 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,405 software developers and data experts.

Signal handler declaration confusion - help!

I have existing code in which the signal() and signal
handler functions appear (for example) like this:

----------------------
#include <signal.h>
void my_handler(int signo);
signal(SIGALRM, my_handler);
---------------------

It appears to work on all Unix-like platforms reported on
(including Linux, various BSDs, Mac OSX, SYSV, AT&TSysVr4).
However on AT&TSysVr4 there are compiler warnings for the
signal() statements:
"warning: argument is incompatible with prototype: arg #2"

According to the signal man page (which I received from a
user of this OS):

------------------
#include <signal.h>
void (*signal(int sig, void (*disp)(int)))(int);
-----------------

I thought I would just change the declaration of the
signal handler to match the OS (ATTSYSVR4 is defined at
configuration) like this:

-------------------
#include <signal.h>

#ifdef ATTSYSVR4
typedef void (*disp)(int) SIGHANDLER;
#else
typedef void SIGHANDLER;
#endif

SIGHANDLER my_handler(int signo);
------------------

Does that look correct? I don't have access to a
computer running this OS and can't try it myself.

Thanks for your help.

Regards,
Charles Sullivan


Sep 5 '06 #1
1 2241
On Tue, 05 Sep 2006 20:32:02 GMT, Charles Sullivan
<cw******@triad.rr.comwrote:

<snip: using signal() but warning on AT&TSysVr4>
According to the signal man page (which I received from a
user of this OS):

------------------
#include <signal.h>
void (*signal(int sig, void (*disp)(int)))(int);
-----------------

I thought I would just change the declaration of the
signal handler to match the OS (ATTSYSVR4 is defined at
configuration) like this:

-------------------
#include <signal.h>

#ifdef ATTSYSVR4
typedef void (*disp)(int) SIGHANDLER;
#else
typedef void SIGHANDLER;
#endif

SIGHANDLER my_handler(int signo);
------------------

Does that look correct? I don't have access to a
computer running this OS and can't try it myself.
No. Your first new typedef is illegal syntax (any OS).

To create a typedef for the same type as the second parameter to
signal shown would be:
typedef void (*SIGHANDLER) (int);

But that is not the type your handler should have; you want the actual
function type which _decays_ to that pointer type:
typedef void SIGHANDLER (int);
...
SIGHANDLER my_handler;
and that is equivalent to what you already have, which is also the
type defined by the C standard; so this isn't the error, or the fix.

Perhaps your user can get you a copy of the (relevant parts of) their
<signal.h(and anything else it uses), or someone else who uses this
system can do so, or someone who knows about it can tell you, since
clearly it is looking for something different than your user has
gotten from the man page and the standard specifies. Especially watch
out for any possibility that their implementation of the standard
conditionally compiles different declarations depending on the
environment settings, as many do, that you look at the one in use --
or conversely, you find an environment that can be selected that
provides the standard and preferred type.

Or perhaps just possibly the compiler in use on that system is so old
it doesn't automatically decay functions as required by C89. If so,
you could use
signal (SIGALRM, &my_handler) /* note & */
and that will also work fine on any standard system.

- David.Thompson1 at worldnet.att.net
Sep 21 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ahmed Ossman | last post by:
hi, I want to save the return value from the signal() function, what is the type of the variable. i.e. I want to do the following: <variable type?> ret_sig = signal(......); I need it soo...
3
by: Martin McCormick | last post by:
A C program contains several signal statements to remove a lock file if the program gets killed: /*Set up interrupt handler to catch ctrl-C so that lock file can be removed.*/...
3
by: LeTubs | last post by:
Hi I'm not sure if this is correct ...place to post but here goes This is what i'm trying to do, I want to write a signal / alarm handler ( I don't know which hence the posting here, as once I...
11
by: Jackie | last post by:
Hi everyone, I'd like to know when and how signals are used (e.g. SIGFPE, SIGABRT, SIGTERM, SIGSEGV, SIGINT)? Thank you so much.
2
by: None | last post by:
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...
10
by: subramanian | last post by:
Consider the following code: segment violation is deliberately generated to catch the SIGSEGV signal. The handler for this signal, namely SIGSEGV_handler, is called. However after the handler is...
2
by: Marco | last post by:
Hi, In C, a signal handler function has only one parameter, that is signal number. But in Python(import signal), a signal handler function has two parameters, the first is signal number, the...
10
by: Udai Kiran | last post by:
Hi all Iam having trouble with signal handler. Where will the execution return after invoking a signal handler when that particular signal is recieved? will return to the point where we register...
5
by: david | last post by:
I'm developing a program that runs using an asyncore loop. Right now I can adequately terminate it using Control-C, but as things get refined I need a better way to stop it. I've developed...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...

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.