<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Rewriting a Utility</title>
	<atom:link href="http://vanemden.wordpress.com/2008/12/10/rewriting-a-utility/feed/" rel="self" type="application/rss+xml" />
	<link>http://vanemden.wordpress.com/2008/12/10/rewriting-a-utility/</link>
	<description>Observations, Reviews, and Essays</description>
	<lastBuildDate>Thu, 27 Aug 2009 21:34:00 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Michael</title>
		<link>http://vanemden.wordpress.com/2008/12/10/rewriting-a-utility/#comment-58</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Mon, 09 Mar 2009 18:43:05 +0000</pubDate>
		<guid isPermaLink="false">http://vanemden.wordpress.com/?p=33#comment-58</guid>
		<description>We assume that division is slow, but is it? Why not compute the size required directly? (Also, name the function so that the caller is alerted to release the memory):

&lt;code&gt;
char* createStringFrom(int n)
{
       	int neg = n0) ++digits;
       	if(neg)++digits;
        char* result = malloc(sizeof(char)*(digits+1));
	result[digits] = 0;
	int k;
	int e = neg?1:0;
	for(k=digits-1;k&gt;=e;--k)
	{
		char c = &#039;0&#039; + n%10;
		n = n/10;
		result[k] = c;
	}
	if(neg)
	{
		result[0] = &#039;-&#039;;
	}
	return result;
}&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>We assume that division is slow, but is it? Why not compute the size required directly? (Also, name the function so that the caller is alerted to release the memory):</p>
<p><code><br />
char* createStringFrom(int n)<br />
{<br />
       	int neg = n0) ++digits;<br />
       	if(neg)++digits;<br />
        char* result = malloc(sizeof(char)*(digits+1));<br />
	result[digits] = 0;<br />
	int k;<br />
	int e = neg?1:0;<br />
	for(k=digits-1;k&gt;=e;--k)<br />
	{<br />
		char c = '0' + n%10;<br />
		n = n/10;<br />
		result[k] = c;<br />
	}<br />
	if(neg)<br />
	{<br />
		result[0] = '-';<br />
	}<br />
	return result;<br />
}</code></p>
]]></content:encoded>
	</item>
</channel>
</rss>
