Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!munnari.oz.au!bruce!monu0.cc.monash.edu.au!monu6!ron From: ron@monu6.cc.monash.edu.au (Ron Van Schyndel) Newsgroups: comp.lang.c Subject: Re: HAS ANYONE SEEN THIS BUG? Keywords: turbo C++ Message-ID: <1991Apr16.091320.29937@monu6.cc.monash.edu.au> Date: 16 Apr 91 09:13:20 GMT References: <1991Apr14.215819.16486@allgfx.agi.oz> Organization: Caulfield Campus, Monash University, Melb., Australia. Lines: 50 cn@allgfx.agi.oz (Con Neri) writes: >Hi netters, > I havec been working with a friend developing some code using >Turbo C++ V1.5 but only writing in standard C. We have been getting an error >with a particular piece of code, namely > fscanf(fp,"%f", &f); > The runtime error is > scanf: floating point formats not linked. > Abnormal Program termination. > Can some one shed some light on what this means? I can compile some > other code with the same statement and yet have no errors. I am > quite confused!! Congratulations! You have found the famous MATH bug, present in most C compilers (at least, *I* think its a bug). When TC compiles your program, it keeps track of whether floating point instructions were actually GENERATED. In your code above, a MEMORY ADRESS is passed to some unknown (TC doesn't know what FSCANF is - it's linked in later) function. That doesn't cause floating point code to be generated. Thus, the compiler does not cause the floating point library to be linked in, and it is only at runtime that this is detected. Be happy for the error message, MS C version 4 and earlier would simply hang in this situation. I think this is a bug, since even if you include the -f or -f87 option, telling the compiler EXPLICITLY that you want floating point included, it will still NOT include it in the above situation. The fix? Include the following before the FSCANF. f = 3.0 * i; /* where i is ANY variable whose value cannot */ fscanf(fp,"%f", &f); /* be anticipated by the compiler */ The f will get immediately overwritten by the FSCANF, but the compiler will now be forced to include the floating point library code. Hope this helps, RON -- Ron van Schyndel ron@monu6.cc.monash.edu.au Physics Department, Monash University ron%monu6.cc.monash.edu.au@uunet.UU.NET CAULFIELD EAST, Victoria, AUSTRALIA {hplabs,mcvax,uunet,ukc}!munnari!monu6.. Location: 37 52 38.8S 145 02 42.0E Phone: +613-573-2567 Fax: +613-573-2358