Page 1 of 1

floating point exceptions

Posted: Fri Feb 10, 2012 12:29 am
by zaphod
Codelite is great. I love it, use it every day. :)
If one compiles using x86 SSE options then floating point exceptions cause a SIGFPE signal and one's code will terminate without any message. This includes, surprisingly, even divide-by-zero errors cause by modulus arithmetic with integers. Here's a code fragment to illustrate things:

Code: Select all

#define __USE_GNU
#include <fenv.h>		// floating point exceptions that cause a SIGFPE
void fpe_handler(int sig_num)
{
	printf("** error ** a floating point exception occured # %d\n", sig_num);
	printf("press <Enter> to close window ");
	getchar();
	exit(sig_num);
}
int enable_floating_point_exception_tests(void)
{
	feenableexcept(FE_DIVBYZERO);
	signal(SIGFPE, fpe_handler);

	// test code to exercise the floating point exception
	volatile int a,b;
    a = 1;
	b = 1; // set b = 1 for no exception set b = 0 to cause one
    return a % b;
}
Codelite does a great job of stack tracing SIGSEG faults with gdb. I wonder if it might be able to do the same for SIGFPE too?