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
| 1 | 1 | /* | |
| 2 | 2 | * C++ SIGFPE handling demo | |
| 3 | 3 | * | |
| 4 | 4 | * Compile with: | |
| 5 | 5 | * $ g++ -std=gnu++17 -Wall lam1.cpp # | |
| 6 | 6 | * $ clang++ -std=gnu++17 -Wall lam1.cpp # | |
| 7 | 7 | * | |
| 8 | 8 | * Written by Roland Mainz <roland.mainz@nrubsig.org> | |
| 9 | 9 | */ | |
| 10 | 10 | ||
| 11 | 11 | #include <stdlib.h> | |
| 12 | 12 | #include <string.h> | |
| 13 | 13 | #include <stdio.h> | |
| 14 | 14 | #include <setjmp.h> | |
| 15 | 15 | #include <signal.h> | |
| 16 | 16 | #include <math.h> | |
| 17 | 17 | #include <fenv.h> | |
| 18 | 18 | #include <limits.h> | |
| 19 | 19 | ||
| 20 | 20 | #include <stdexcept> | |
| 21 | 21 | #include <iostream> | |
| 22 | 22 | #include <cfloat> | |
| 23 | 23 | #include <functional> | |
| 24 | 24 | ||
| 25 | 25 | /* Number of elements in a C99/C++ array */ | |
| 26 | 26 | #define numelementsinarray(ar) (sizeof(ar)/sizeof((ar)[0])) | |
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | 29 | static sigjmp_buf jmp_env; | |
| 30 | 30 | static volatile siginfo_t saved_siginfo; | |
| 31 | 31 | ||
| 32 | + | extern "C" | |
| 34 | 33 | { | |
| 34 | + | static void sigfpe_handler(int num, siginfo_t *info, void *ucontext) | |
| 35 | 36 | (void)num; | |
| 36 | 37 | (void)ucontext; | |
| 37 | 38 | ||
| 38 | 39 | (void)feclearexcept(FE_ALL_EXCEPT); | |
| 39 | 40 | (void)memcpy((void *)&saved_siginfo, info, sizeof(saved_siginfo)); | |
| 40 | 41 | ||
| 41 | - | #if 1 | |
| 42 | 42 | siglongjmp(jmp_env, 1); | |
| 43 | - | #else | |
| 44 | - | throw std::invalid_argument( "you violated the fp math rules" ); | |
| 45 | - | #endif | |
| 46 | 43 | } | |
| 44 | + | } | |
| 47 | 45 | ||
| 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.
rovema.kpaste.net RSS