From owner-freebsd-hackers Fri Aug 28 09:16:21 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id JAA09277 for freebsd-hackers-outgoing; Fri, 28 Aug 1998 09:16:21 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from dirc.bris.ac.uk (dirc.bris.ac.uk [137.222.10.51]) by hub.freebsd.org (8.8.8/8.8.8) with SMTP id JAA09188 for ; Fri, 28 Aug 1998 09:16:11 -0700 (PDT) (envelope-from Tim.Borgeaud@bristol.ac.uk) Received: from zeus.bris.ac.uk by dirc.bris.ac.uk with SMTP-PRIV (PP) with ESMTP; Fri, 28 Aug 1998 17:15:02 +0100 Received: (from phtlb@localhost) by zeus.bris.ac.uk (8.8.8/8.8.7) id RAA27907 for freebsd-hackers@FreeBSD.ORG; Fri, 28 Aug 1998 17:14:45 +0100 (BST) From: Tim Borgeaud Message-Id: <199808281614.RAA27907@zeus.bris.ac.uk> Subject: RE: Why is my code failing with SIGFPE? To: freebsd-hackers@FreeBSD.ORG Date: Fri, 28 Aug 1998 17:14:45 +0100 (BST) X-Mailer: ELM [version 2.4 PL21] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Apologies to all. I have managed to find the problem in my code. I had missed out one of my include files. This had lead to a function being implicitly declared rather than declared as a function returning a double. After browsing the mail archives and some careful attention to compiling I found the error. I forget who wrote the message that described this function misdeclaration as a cause of SIGFPE. Thanks to whoever it was. Is this kind of behaviour from the compiler unavoidable? It took me ages to track down the bloody problem. As a novice programmer I was confused by the floating point exception and spent a long time wondering how my variables could have gone out of range. > > Sorry if this is bit off topic but I think someone reading the list can > probably help me. > > I have some C-code which fails with floating point exceptions (SIGFPE errors). > Code compiles cleanly, although I am not using any additional options to gcc. > > I am stumped as to the cause of these errors. Depending on where I put > print statements in the code (for debugging purposes) it fails at different > points. > > The code makes fairly heavy use of the CPU and is recursive. On the fourth call > of the recursive function the code fails with SIGFPE, sometimes in my code > without any reason that I can find, but also commonly in __dtoa (called during > printf of a floating point number). > > I have carefully gone through my code, sections of which seemed to be working > perfectly on their own. I cannot seem to find anything wrong. I can supply all or > parts of the code that I am trying to run if anyone is interested. I was hoping > that someone may have come across this kind of thing before. > > The code has also been compiled using djgpp under msdos and has the same > problem. Two machines (Pentium and Pentium MMX) produce the same results. > > I have tried to use gdb, but because I have never used it before it didn't help > very much. All I found was that some of the floating point variable were > scrambled after the failure (eg some ridculous number x10^230 or something). > > > Many thanks > > Tim > > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message