fscanf bug in TC (BC) C++ 2.0

Don CORBITT donc at microsoft.UUCP
Tue Apr 30 08:37:30 AEST 1991


In article <41392 at cup.portal.com> ts at cup.portal.com (Tim W Smith) writes:
>< 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.)

[deleted text with justification for following code]

>We might see code like this:
>
>	long data;

	[...]

>	printf( "%f", data );
>Oops!  No floating point at compile time but needed at runtime.

This is incorrect, since printf() is varargs, a float value passed would
be expanded to double.  I would use a union here, if I wanted to do such
a thing.  Of course, someone will come up with such a program.  The fix
is simple, do some floating point math somewhere else in the program, 
even in a func that's never called.  

--
Don Corbitt
Microsoft Windows Development



More information about the Comp.lang.c mailing list