scanf() problem in Turbo C++ 1.00 but NOT in Turbo C 2.01

J.D. Baldwin. baldwin at usna.NAVY.MIL
Thu Oct 11 03:16:25 AEST 1990


OK, I don't want to jump the gun and call this a "compiler bug" just yet,
but I'm mighty stumped by the following code (this is as simple as I can
make the example without the bug disappearing):

-------Cut here---------
#include <stdio.h>
#include <stdlib.h>

   double * ar_1;
   double x;

void main(void)
{
    ar_1 = (double *) calloc(1, sizeof(double));

    fflush(stdin);
/*    scanf("%lf", &x);  */
    scanf("%lf", &(ar_1[0]));

    printf("%lf\n", ar_1[0]);
}
-------Cut here---------

Here's the problem:  when I compile and run this code under Turbo C 2.01, it 
works fine--accepts a floating-point number and prints it out.  When I
compile and run the SAME code under Turbo C++ 1.00, I hit the (uncommented)
scanf and get the following message:

          scanf : floating point formats not linked
          Abnormal program termination

It does not pause to get input before delivering this message.

Now it gets weird:  I uncomment the first "scanf" call.  Still works as
advertised under Turbo C 2.01--this time gets two doubles, and throws the
first one away.  Now it works the same way under Turbo C++ 1.00 also!

If, instead of calloc-ating ar_1, I declare it as double ar_1[10], and get
rid of the calloc() line, it works the way it's supposed to in both compilers
(whether or not the extraneous scanf() is present).

I've tried setting and unsetting every possible compiler option--especially
the ones about making use of a 80287 co-processor (I have one) or FP
emulation, 8086 or 80286 code, etc., etc.  I am running a Zenith Z-248
(AT compatible) and Zenith DOS 3.3 "plus."  Of course I can get around
this problem by scanning in a temporary variable and re-assigning it, 
but I'd rather understand what the heck's going on here!

I'd appreciate any help.  If posted, I'll see it (I check all these groups--
and please note the followup redirection); if e-mailed, I'll echo it back to
the net.  Thanks in advance.
--
 From the catapult of:              |+| "If anyone disagrees with anything I
   _, J. D. Baldwin, Comp Sci Dept  |+| say, I am quite prepared not only to
 __||____:::)=}-  U.S. Naval Academy|+| retract it, but also to deny under
 \      / baldwin at cad.usna.navy.mil |+| oath that I ever said it." --T. Lehrer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the Comp.lang.c mailing list