🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.powerpc
Article #3232

Re: Debate: PowerMac "trounces" Pentium....???

#3232
From: Bernd Meyer
Date: Thu, 15 Feb 1996 22:56
37 lines
1968 bytes
Nevin ":-]" Liber (nevin@CS.Arizona.EDU) wrote:
: In article <danpop.824303108@rscernix>, danpop@mail.cern.ch (Dan Pop) wrote:
: 
: > Why do you want to do it in a non-trivial way?  What's wrong with the
: > trivial method: sprintf(buff, "%d", intval)?
: 
: It's not portable yet.

OK, so how about:

char*	printme(int x)
{
	int digits=0;
	int y=x;
	char* buff;
	
	if (x<0) {digits++;y=(-x);}
	while (y) {
		digits++;
		y/=10;
	}
	if (!digits) digits++;
	buff=malloc(digits+1);
	sprintf(buff,"%d",x);
	return buff;
}	

: What is the minimum size that the buffer that buff
: points to should be in order to store an int for any possible (not
: necessarily just existing today, but anything that conforms to the current
: standard) ANSI C implementation?

The only assumption the above code makes is that the numbers of digits
needed to print an int can be stored in an int. Which, I think, can
be pretty much guaranteed ;-)

Bernie
Technical Details
Message-ID: <4g0dm3$o3g@harbinger.cc.monash.edu.au>
Path: arc1-ca.pugleaf.net!bruce.cs.monash.edu.au!not-for-mail
References: <nevin-0602962253080001@150.135.1.79> <4fdi45$gu7@eken.hv.se> <4fea7g$eio@nyx.cs.du.edu> <9602092127.AA24456@ues5.cern.ch> <nevin-1202960529130001@150.135.1.79> <9602121654.AA02634@ues5.cern.ch> <4fqdta$rhh@meaddata.lexis-nexis.com> <danpop.824303108@rscernix> <nevin-1502960049080001@150.135.1.79>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!bruce.cs.monash.edu.au!not-for-mail
From: bmeyer@bruce.cs.monash.edu.au (Bernd Meyer)
Newsgroups: comp.sys.powerpc,comp.os.linux.advocacy,comp.sys.mac.advocacy,comp.os.os2.advocacy,comp.sys.amiga.advocacy,comp.sys.intel
Subject: Re: Debate: PowerMac "trounces" Pentium....???
Followup-To: comp.sys.powerpc,comp.os.linux.advocacy,comp.sys.mac.advocacy,comp.os.os2.advocacy,comp.sys.amiga.advocacy,comp.sys.intel
Date: 15 Feb 1996 22:56:03 GMT
Organization: Computer Science, Monash University, Australia
Message-ID: <4g0dm3$o3g@harbinger.cc.monash.edu.au>
References: <nevin-0602962253080001@150.135.1.79> <4fdi45$gu7@eken.hv.se> <4fea7g$eio@nyx.cs.du.edu> <9602092127.AA24456@ues5.cern.ch> <nevin-1202960529130001@150.135.1.79> <9602121654.AA02634@ues5.cern.ch> <4fqdta$rhh@meaddata.lexis-nexis.com> <danpop.824303108@rscernix> <nevin-1502960049080001@150.135.1.79>
NNTP-Posting-Host: molly.cs.monash.edu.au
X-NNTP-Posting-User: bmeyer
X-Newsreader: TIN [UNIX 1.3 950823BETA PL0]