Yet another bug in TURBO C 2.0

Loyde W. Hales II lwh at harpsichord.cis.ohio-state.edu
Tue Apr 10 01:10:45 AEST 1990


>In article <1316 at taurus.BITNET> <dorfman%math.tau.ac.il at CUNYVM.CUNY.EDU>
>writes:
>Here is a strange bug I discovered while porting a C source from MSC 4.0
>to the TURBO C 2.0 compiler. After "minimizing" the source, I ended up with
>the following:
>main()
> {
>  static float matrix[3][3];
>  int i=0;
>  scanf ("%f",&matrix[i][0]);
>  scanf ("%f",&matrix[0][0]);  /* delte this line and the program crashes */
> }
>The program works fine with both scanf's intact, but crashes when the
>second one is deleted (???).  After experimenting with it, I came to the
>conclusion, that TURBO doesn't like something about the first scanf.
>The message I get during run-time is:
> scanf : floating point formats not linked
>Abnormal program termination
>It's interesting, how the floating point formats become (suddenly)
>linked after the program is modified :-)
>Does anyone know,
>  a) What's wrong with the 1st scanf (form TURBO's point of view) ?
>  b) What's causing the strange bug?
>  c) How can I use the 1st scanf without having to "invent" the second?

The problem is, in a sense, with Turbo C; but it is documented.

Turbo C, as with many C compilers, provides a Floating Point Emulator for
those without a math co-processor (or wanting code portable to such
machines).  To make your executable smaller and compile/load sequences
quicker, Turbo C checks tries to determine if you _really_use_floats_ before
it will load the emulator.

Well, they want to be a little brighter than just looking to see if the
keyword ``float'' or ``double'' appear anywhere.  (To be honest, I'm not
certain why.  I can come up with cases where I might use (float *) without
wanting a float, but not ones that aren't bloody contrived.)

Simply, it is not catching that this is a float, not a pointer to a float.

Fixes:

	1. Put any direct operation on a simple float anywhere in the code.
	   E.g., float a = 0.0;

	2. Check you manual.  There is a fix suggested in Turbo C 2.0.
	   I can't remember what it is, but there is an environment variable
	   you can set to make floating-point libraries always load.  I think
	   there is also a compiler option for this.

-=-

                                Department of Computer and Information Science
Loyde W. Hales, II                      The Ohio State University
lwh at cis.ohio-state.edu          2036 Neil Avenue Mall, Columbus, Ohio  43201



More information about the Comp.lang.c mailing list