HAS ANYONE SEEN THIS BUG?
Ron Van Schyndel
ron at monu6.cc.monash.edu.au
Tue Apr 16 19:13:20 AEST 1991
cn at 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 at monu6.cc.monash.edu.au
Physics Department, Monash University ron%monu6.cc.monash.edu.au at 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
More information about the Comp.lang.c
mailing list