473,666 Members | 2,578 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3896
On Tue, 22 Jul 2003 14:11:48 +0300, "Ahmed Ossman" <ah**********@m entor.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**)(&rea l));
// 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_fun c_p) signal(SIGFPE,
SIG_IGN);
if (prev_sigfpe_va l != (sig_handle_fun c_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_va l != (sig_handle_fun c_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.C IS.DFN.DE...
On Tue, 22 Jul 2003 14:11:48 +0300, "Ahmed Ossman" <ah**********@m entor.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**********@m entor.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**)(&rea l));
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::stringstre am.

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_fun c_p prev_sigfpe_val = (sig_handle_fun c_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_va l != (sig_handle_fun c_p)SIG_IGN) {
// install own signal handler
signal(SIGFP E, 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_va l != (sig_handle_fun c_p)SIG_IGN) {
// restore the original action in the event of the SIGFPE signal.
signal(SIGFP E, 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_li mits.
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::stringstre am.

Jul 19 '05 #5

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

Similar topics

5
2293
by: Klaus Neuner | last post by:
Hello, consider the following two programs: # (1) import sys, signal def alarm_handler(signum, frame): raise
6
2415
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
6007
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 language syntax itself. Thank you!
11
3471
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 interactive terminal, it is probably nice to push EOF back (because to user doesn't want to provide an EOF twice). How is it getc can send EOF down it's pipe, but we can't send EOF down ungetc's pipe (especially when this pipe is the same)? ...
3
1681
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
5871
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 Employee. This I can do. The problem comes if the EmpID is not found in the collection. The only way to achieve this I can think of is to throw an invalid argument exception:
6
8836
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 other applications in my dept, which simply call this Csd.exe app and passing a list of files. I want to ask how can I return a value from this Csd.exe application as an indicator or a signal to the calling app that Csd.exe has finished working....
7
2209
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 similiar to the concept of try-catch to me.) It seems to relate more to nix OS. Are signals handling part of Windows too?
5
6639
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 another program that executes it as a child process using popen2.Popen4(). I was attempting to use signals to stop it (using os.kill()) but I keep running into a problem where sending the signal causes an infinite loop of printing the message...
0
8454
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8363
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8883
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8561
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8645
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6203
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.