Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!uunet!tut.cis.ohio-state.edu!harpsichord.cis.ohio-state.edu!lwh From: lwh@harpsichord.cis.ohio-state.edu (Loyde W. Hales II) Newsgroups: comp.lang.c Subject: Re: Yet another bug in TURBO C 2.0 Keywords: bug Message-ID: <79017@tut.cis.ohio-state.edu> Date: 9 Apr 90 15:10:45 GMT References: <1316@taurus.BITNET> <4851@helios.TAMU.EDU> Sender: usenet_news@tut.cis.ohio-state.edu Reply-To: Loyde W. Hales II Organization: Ohio State University Computer and Information Science Lines: 55 >In article <1316@taurus.BITNET> >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@cis.ohio-state.edu 2036 Neil Avenue Mall, Columbus, Ohio 43201