pastebin - collaborative debugging tool
rovema.kpaste.net RSS

Difference between
modified post bf1c0 by Anonymous on Fri 18th Feb 2022 13:25
original post af73 by Anonymous on Mon 14th Feb 2022 18:15
Download diff
Show old version | new version | both versions

    
11
/*
22
 * C++ SIGFPE handling demo
33
 *
44
 * Compile with:
55
 * $ g++ -std=gnu++17 -Wall lam1.cpp #
66
 * $ clang++ -std=gnu++17 -Wall lam1.cpp #
77
 *
88
 * Written by Roland Mainz <roland.mainz@nrubsig.org>
99
 */
1010
1111
#include <stdlib.h>
1212
#include <string.h>
1313
#include <stdio.h>
1414
#include <setjmp.h>
1515
#include <signal.h>
1616
#include <math.h>
1717
#include <fenv.h>
1818
#include <limits.h>
1919
2020
#include <stdexcept>
2121
#include <iostream>
2222
#include <cfloat>
2323
#include <functional>
2424
2525
/* Number of elements in a C99/C++ array */
2626
#define numelementsinarray(ar) (sizeof(ar)/sizeof((ar)[0]))
2727
2828
2929
static sigjmp_buf jmp_env;
3030
static volatile siginfo_t saved_siginfo;
3131
32+
extern "C"
3433
{
34+
	static void sigfpe_handler(int num, siginfo_t *info, void *ucontext)
3536
	(void)num;
3637
	(void)ucontext;
3738
3839
	(void)feclearexcept(FE_ALL_EXCEPT);
3940
	(void)memcpy((void *)&saved_siginfo, info, sizeof(saved_siginfo));
4041
41-
#if 1
4242
	siglongjmp(jmp_env, 1);
43-
#else
44-
	throw std::invalid_argument( "you violated the fp math rules" );
45-
#endif
4643
}
44+
}
4745
46+
#define DEFINE_SIGFPE_TESTCASE_FUNC(f) .func = f , .funcstr = #f ,

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at