cn@allgfx.agi.oz (Con Neri) (04/15/91)
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!! Hope someone out there can help. Regards CON NERI All Graphic R+D e-mail: cn@allgfx.agi.oz.au 49-53 Barry ST tele: +61-3-3471722 Carlton fax : +61-3-3472175 Vic 3053 AUSTRALIA
ron@monu6.cc.monash.edu.au (Ron Van Schyndel) (04/16/91)
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
juul@diku.dk (Anders Juul Munch) (04/16/91)
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!! >Hope someone out there can help. [stuff deleted] I experienced the same problem once, using Turbo C 2.0 and trying to link "by hand" instead of having the integrated environment make facility handle all that. The solution was simple: I went back to linking from the integrated environment. Somehow TC/TC++ is trying to be smart, and exclude all the code to handle floating point (by having a scanf version with and one without fp-handling), when the program doesn't use fp arithmetic. The trouble is, as [vsf]scanf and [vsf]printf functions are interpreters of the format string, this may be difficult to detect. Somehow you need to make TC aware that you are dealing with fp. I don't know how TC detects fp use. Perhaps by looking for fp-variable declarations in that module? Or fp math? -- Anders Munch