473,396 Members | 2,089 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.

return from signal

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 much.
Thanks,
Ahmed Ossman
Jul 19 '05 #1
4 3882
On Tue, 22 Jul 2003 14:11:48 +0300, "Ahmed Ossman" <ah**********@mentor.com> wrote:
I want to save the return value from the signal() function,
At your current level, absolutely don't use signal(). It's
incompatible with many C++ features.
what is the type of the variable.
i.e. I want to do the following:
<variable type?> ret_sig = signal(......);
The result type is specified in the function declaration.
I need it soo much.


You don't. If you can explain what you're trying to _achieve_
by using signal(), perhaps we can help you.
Jul 19 '05 #2
The function is as following

***********************
const char *dump_float(
const float &real // reference to float to be output
)
// PUBLIC FUNCTION: dump_float() - format a float for dump.
// This function returns a pointer to a 0-terminated character
// vector containing the value of the float "real" formatted for
// use in an object dump. It handles the case(s) in which the data
// does not have a valid floating point representation. Such a
// situation can arise when a union field of more than one data type
// is interpreted as a float.
{
// save the float in a global so that the signal handler can output
// the value if signal occurs.
u_val.p_val = *((void**)(&real));
// GNU strstream ctor does not take a mode
#ifdef __GNUC__
strstream out(ptr_buf, buf_size);
#else
strstream out(ptr_buf, buf_size, ios::out);
#endif
out_p = &out;
// set up the handler for the SIGFPE signal (if appropriate)
sig_handle_func_p prev_sigfpe_val = (sig_handle_func_p) signal(SIGFPE,
SIG_IGN);
if (prev_sigfpe_val != (sig_handle_func_p)SIG_IGN) {
// install own signal handler
signal(SIGFPE, sigfpe_handler);
}
// dump the floating point representation of the scalar value
if (setjmp(sjbuf) == 0) {
sprintf(pbuf, "%-15g", (double)real);
out << pbuf;
}
if (prev_sigfpe_val != (sig_handle_func_p)SIG_IGN) {
// restore the original action in the event of the SIGFPE signal.
signal(SIGFPE, prev_sigfpe_val);
}
return ptr_buf;
}
*********************************************
It is compiled with the forte 6 Solaries compiler, and the error is: Error:
Could not find a macth for std::signal(int, void(*)(int))
Could anyone help???
Ahmed Ossman

"Alf P. Steinbach" <al***@start.no> wrote in message
news:3f****************@News.CIS.DFN.DE...
On Tue, 22 Jul 2003 14:11:48 +0300, "Ahmed Ossman" <ah**********@mentor.com> wrote:
I want to save the return value from the signal() function,


At your current level, absolutely don't use signal(). It's
incompatible with many C++ features.
what is the type of the variable.
i.e. I want to do the following:
<variable type?> ret_sig = signal(......);


The result type is specified in the function declaration.
I need it soo much.


You don't. If you can explain what you're trying to _achieve_
by using signal(), perhaps we can help you.

Jul 19 '05 #3
Don't top post, that's rude.

On Tue, 22 Jul 2003 14:50:20 +0300, "Ahmed Ossman" <ah**********@mentor.com> wrote:
The function is as following
OK, I'll first discuss the particulars of that function, then
show how you can achieve a dump of a float value.
***********************
const char *dump_float(
const float &real // reference to float to be output
)
Make the return value a std::string.

You're returning a pointer to a global or perhaps a member
character array.

It's very evil.
// PUBLIC FUNCTION: dump_float() - format a float for dump.
// This function returns a pointer to a 0-terminated character
// vector containing the value of the float "real" formatted for
// use in an object dump. It handles the case(s) in which the data
// does not have a valid floating point representation. Such a
// situation can arise when a union field of more than one data type
// is interpreted as a float.
Don't use unions, they're evil.

Instead, use C++ virtual functions and inheritance.

See the C++ FAQ.

{
// save the float in a global so that the signal handler can output
// the value if signal occurs.
u_val.p_val = *((void**)(&real));
Now _that_ is unbelievably evil. How does the signal handler
(note that a signal handler is also evil in C++) know that this
void* pointer is a float*? And if it must always be, why not
use a float*?

Btw., globals like u_val are evil.

// GNU strstream ctor does not take a mode
#ifdef __GNUC__
strstream out(ptr_buf, buf_size);
#else
strstream out(ptr_buf, buf_size, ios::out);
#endif
Use std::stringstream.

out_p = &out;
Globals like out_p are evil.

Use local variables, not globals.
// set up the handler for the SIGFPE signal (if appropriate)
sig_handle_func_p prev_sigfpe_val = (sig_handle_func_p) signal(SIGFPE,
SIG_IGN);
You do not show the definition of sig_handle_func_p, but the cast
indicates that it's an incorrect definition.
if (prev_sigfpe_val != (sig_handle_func_p)SIG_IGN) {
// install own signal handler
signal(SIGFPE, sigfpe_handler);
This is probably where the compiler says "enough". You do not show
your definition of sigfpe_handler. But judging from the compiler's
error message it's something like
void f( int x ) { ... }
which is incorrect.
}
// dump the floating point representation of the scalar value
if (setjmp(sjbuf) == 0) {
sprintf(pbuf, "%-15g", (double)real);
The use of sprintf is inconsistent with the use of strstream.

At your current level, use std::stringstr.

out << pbuf;
}

Here you simply ignore the case of a signal occurring, and
proceed to return a pointer to an uninitialized buffer. That
is a bug.
if (prev_sigfpe_val != (sig_handle_func_p)SIG_IGN) {
// restore the original action in the event of the SIGFPE signal.
signal(SIGFPE, prev_sigfpe_val);
}
return ptr_buf;
}
*********************************************
It is compiled with the forte 6 Solaries compiler, and the error is: Error:
Could not find a macth for std::signal(int, void(*)(int))


Okay, what you're trying to achieve seems to be to convert a
float value to decimal representation, if and only if it is a
valid float value.

The conversion part is easily accomplished in C++, and I suggest
you write that as a simple function that _assumes_ (has as
precondition) that the float value is valid. std::stringstr
handles the cases of IEEE Inf and so on. The function declaration
would be something like
std::string toString( float aFloat )
{
// stuff here using std::strstream
}
The if and only if valid part is not easily accomplished in C++,
since C++ allows the compiler to choose the representation of
float and double. Here I suggest that you restrict your program
to compilers that support IEEE standard format. You can check
whether a particular compiler does via std::numeric_limits.
Hth.,

- Alf

Jul 19 '05 #4
On Tue, 22 Jul 2003 12:46:14 GMT, al***@start.no (Alf P. Steinbach) wrote:
// stuff here using std::strstream


Typo: that should be std::stringstream.

Jul 19 '05 #5

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

Similar topics

5
by: Klaus Neuner | last post by:
Hello, consider the following two programs: # (1) import sys, signal def alarm_handler(signum, frame): raise
6
by: mhenry1384 | last post by:
On WinXP, I am doing this nant.exe | python MyFilter.py This command always returns 0 (success) because MyFilter.py always succeeds. MyFilter.py looks like this while 1:
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...
11
by: TTroy | last post by:
Hello C programmers, Can someone tell me why ungetc can't sent back EOF, but it's sister function getc has no trouble sending it to us? For a file, this might not make a difference, but for an...
3
by: Felix Kater | last post by:
Hi, normally I use a local variable assigned to different return values inside the function and return it like this: int f(){ int my_err_code; my_err_code=1;
3
by: Eric the half a Bee | last post by:
Hello I am trying to implement a search function within a collection of Employees. I am searching for a specific EmpID number in the collection, and if it is found, I want to return the...
6
by: Sunny | last post by:
Hi, I have a very serious issue at hand. I have created a small C# Console App (Csd.exe) that collects a list of files as its argument and generates their Md5 sets. This application is used by...
7
by: Stanley S | last post by:
Hi, Are Signal Handling part of ANSI C? I am not able to find any reference of Sig Handling in Stephen Prata's "C Primer Plus". The usage of signals is to trap errors I guess. (It looks...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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
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.