C and C++ Problem with "Floating point exception"
I am having problem with an error "Floating point exception"
I think I understand all of it but I am not sure if I am missing something, I know the code works as a while as I have tested it the benchmark routine before and it works. From where it came: This is a benchmark to test the number of data coming from the USB port. What am I trying to do: I am breaking the code and testing the bit which suppose to measure the number of data coming from the USB, I did test it initially in C++ with g++, and I get "make: *** [run] Floating point exception" I though was something to do with g++ so I did test it on gcc and I get the same error. I think I know the reason nbytes/ncalls which is 0, I think It cannot be divided by zero, but I am not sure, maybe ncalls never is 0 as should make n number the call to usb buss? that is my guess. Now the code: Code:
#include <stdio.h> Also there is something I still dont know why I needed to do the code work well if you do "timeval start_tv,end_tv;" but for this test I had the word "struct" as in here to make the compile error go away. Do you know why? |
integer division will never give a floating point exception.
Most likely it is a problem in the division in: nbytes/seconds3/1024/1024 |
Quote:
Note: you can run the program under a debugger to see exactly which line causes the crash. You'll want to move the divisions into separate statements: otherwise it just tells you it comes from the printf() line. Quote:
|
I would use assert to make sure denominators are not zero before any division.
|
Quote:
|
Quote:
I search on internet and I found it gdb so I read a bit and give it a goal and it works nice the output comes as: Test_bench Program received signal SIGFPE, Arithmetic exception. 0x08049111 in main () at Buffer.cpp:202 202 ncalls,nbytes/ncalls); is this one you meant? Also It said to compile with -ggdb as a flag but I test with and without and it seen to be working. Does this really need it? |
Quote:
Code:
Program received signal SIGFPE, Arithmetic exception. Quote:
Quote:
|
Quote:
If that was not your intent, then I would suggest that you insert a semi-colon at the end of the for-loop statement. Also, as others have already deduced, division with a denominator of zero will produce the floating point exception. Code:
int main(void) |
Quote:
|
Quote:
|
Quote:
Code:
gcc -g -o bench bench.c Code:
gcc (Debian 4.7.3-4) 4.7.3 |
All times are GMT -5. The time now is 01:20 PM. |