🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.os.linux.programowanie
4 messages
4 total messages Started by Borneq Sun, 09 Dec 2012 21:14
Przejmowanie sygnały dzielenia przez zero
#72580
Author: Borneq
Date: Sun, 09 Dec 2012 21:14
26 lines
1406 bytes
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

int handle (int signo)
{
 printf ("z handle, signo=%d\n",signo);
}

int inv(int n)//float,int 1/0 SIGFPE = 8
{
    return 1/n;
}

int main()
{
    void (*SIGFPE_saved) ();

    SIGFPE_saved = signal (SIGFPE, handle);
    inv(abs(0));
    printf ("po inv\n");
    signal (SIGFPE, SIGFPE_saved);
    return 0;
}

Co zrobić aby w kólko nie wywoływał handle() ? 
Re: Przejmowanie sygnały dzielenia przez zero
#72581
Author: Kamil Jońca
Date: Sun, 09 Dec 2012 21:43
38 lines
1593 bytes
"Borneq" <borneq@antyspam.hidden.pl> writes:

> #include <stdio.h>
> #include <stdlib.h>
> #include <signal.h>
>
> int handle (int signo)
> {
> printf ("z handle, signo=%d\n",signo);
> }
>
> int inv(int n)//float,int 1/0 SIGFPE = 8
> {
>    return 1/n;
> }
>
> int main()
> {
>    void (*SIGFPE_saved) ();
>
>    SIGFPE_saved = signal (SIGFPE, handle);
>    inv(abs(0));
>    printf ("po inv\n");
>    signal (SIGFPE, SIGFPE_saved);
>    return 0;
> }
>
> Co zrobić aby w kólko nie wywoływał handle() ? 

Jak to "w kółko"?
KJ


-- 
http://blogdebart.pl/2012/06/24/hiena/
I hate mankind, for I think myself one of the best of them, and I know
how bad I am.
		-- Samuel Johnson
Re: Przejmowanie sygnały dzielenia przez zero
#72582
Author: Borneq
Date: Mon, 10 Dec 2012 11:20
7 lines
1367 bytes
Użytkownik "Kamil "Jońca"" <kjonca@poczta.onet.pl> napisał w wiadomości 
news:87lid6lx4o.fsf@alfa.kjonca...
> Jak to "w kółko"?

Gdy uruchamiam wyrzuca mi masę linii: z handle, signo=8", czy jest jakaś 
flaga, czy pole do ustawiania aby szedł dalej, bo chyba po handle() próbuje 
znowu tę samą instrukcje. 
Re: Przejmowanie sygnały dzielenia przez zero
#72583
Author: Aleksander Nabagło
Date: Thu, 13 Dec 2012 07:37
45 lines
2010 bytes
Borneq pisze:
> #include <stdio.h>
> #include <stdlib.h>
> #include <signal.h>
> 
> int handle (int signo)
> {
> printf ("z handle, signo=%d\n",signo);
> }
The routine handler must be very careful,
since	 processing  elsewhere
was interrupted at some arbitrary point.
POSIX has the concept of "safe function".
If a signal interrupts  an  unsafe  function,
and  handler calls  an  unsafe  function,
then the behavior is undefined. Safe func-
tions are listed explicitly in the various standards.

> int inv(int n)//float,int 1/0 SIGFPE = 8
> {
>    return 1/n;
> }
> 
> int main()
> {
>    void (*SIGFPE_saved) ();
> 
>    SIGFPE_saved = signal (SIGFPE, handle);
>    inv(abs(0));
>    printf ("po inv\n");
>    signal (SIGFPE, SIGFPE_saved);
>    return 0;
> }
> 
> Co zrobić aby w kólko nie wywoływał handle() ?
Jakiego typu musi byc 'handle'?

Ponadto, funkcja 'printf' nie znajduje sie
na liscie POSIX bezpiecznych funkcji (czyli dzialanie
programu jest nieokreslone, jesli zostanie uzyta
w handlerze).

-- 
A
.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads