Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!fernwood!portal!cup.portal.com!ts From: ts@cup.portal.com (Tim W Smith) Newsgroups: comp.lang.c Subject: Re: fscanf bug in TC (BC) C++ 2.0 Message-ID: <41392@cup.portal.com> Date: Thu, 18 Apr 91 00:52:34 PDT Organization: The Portal System (TM) References: <1991Apr14.215819.16486@allgfx.agi.oz> <1991Apr16.141117.5065@odin.diku.dk> <26502@hydra.gatech.EDU> <1991Apr18.021515.1481@athena.mit.edu> < that the algorithm is imperfect: if the program isn't using < floating point, %e, %f, and %g can't be needed, but they might < not be needed if the program is using floating point, either. < However, "program uses floating point" is in principle computable < at compile time, while "%e, %f, or %g might get passed to printf" < isn't.) Suppose you have a program that is receiving data a byte at a time over a serial port. Each item consists of a type followed by the data. This program simply wants to print the data. Suppose one of the types is single precision floating point. The programmer "knows" that a float is the same size as a long, and that the data was sent by taking the address of a float on the other side and just sending out the bytes. We might see code like this: long data; data = nextbyte() << 24; data |= nextbyte() << 16; data |= nextbyte() << 8; data |= nextbyte(); printf( "%f", data ); Oops! No floating point at compile time but needed at runtime. Tim Smith ps: of course, I would never do this!