🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac
Article #6921

Re: Possible new bug in Think C 4.0 sprintf

#6921
From: Joseph N. Hall
Date: Mon, 23 Oct 1989 18:34
53 lines
2441 bytes
In article <13068@boulder.Colorado.EDU> jdm@boulder.Colorado.EDU (James D. Meiss) writes:
>
>	After much hair pulling, I localized a problem
>in a program that worked fine under Think C 3, but was
>giving difficulties in the new version, using the ANSI
>library.
>
>	The problem seems to be the following: Call
>sprintf with an unitialized double:
>
>main()
>{
>	double z;
>	char aStr[80];
>
>	/* z = 0.0   <==== include this to prevent crash*/
>....
>	sprintf(aStr, ".13lf",z);
>....
>}

From p.329, "C: A Reference Manual," by Harbison and Steele:

	... Draft Proposed ANSI C uses the L (uppercase letter l)
	prefix with e, E, f, F, g, and G to indicate that the
	argument has type long double ...

From p.334:

f	Signed decimal floating-point conversion is performed.  One
	argument is consumed, which should be of type double.  (Note
	that if an argument of type float is given, it is converted to
	type double by the usual function argument conversions before
	printf ever sees it, so it does work to use %f to print a
	number of type float.)
	...
	...The l (long size) specification is not relevant to the f
	conversion operation.

You are using the specifier "%lf," which is nonstandard.  The correct
specifier for BOTH float and double is "%f".  Last I heard there was no
portable use for "%lf" and it is NOT standard "C."

I don't remember whether "%lf" is a compatibility hack for 80- or
96-bit extended types; it might be.  On the other hand, the %lf specifier
might just be totally ignored ... in any event what you're doing is
incorrect and should result in some kind of an error.


v   v sssss|| joseph hall                      || 4116 Brewster Drive
 v v s   s || jnh@ecemwl.ncsu.edu (Internet)   || Raleigh, NC  27606
  v   sss  || SP Software/CAD Tool Developer, Mac Hacker and Keyboardist
-----------|| Disclaimer: NCSU may not share my views, but is welcome to.
Technical Details
Message-ID: <4282@ncsuvx.ncsu.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!gatech!ncsuvx!ecemwl!jnh
References: <13068@boulder.Colorado.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!gatech!ncsuvx!ecemwl!jnh
From: jnh@ecemwl.ncsu.edu (Joseph N. Hall)
Newsgroups: comp.sys.mac
Subject: Re: Possible new bug in Think C 4.0 sprintf
Keywords: Think C, sprintf
Message-ID: <4282@ncsuvx.ncsu.edu>
Date: 23 Oct 89 18:34:20 GMT
References: <13068@boulder.Colorado.EDU>
Sender: news@ncsuvx.ncsu.edu
Reply-To: jnh@ecemwl.UUCP (Joseph N. Hall)
Distribution: na
Organization: North Carolina State University
Lines: 53