<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mikhail panchenko / blog &#187; c</title>
	<atom:link href="http://mihasya.com/blog/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://mihasya.com/blog</link>
	<description>good things now come in packages of three</description>
	<lastBuildDate>Thu, 22 Mar 2012 21:08:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>My C is more better now!</title>
		<link>http://mihasya.com/blog/my-c-is-more-better-now/</link>
		<comments>http://mihasya.com/blog/my-c-is-more-better-now/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 00:10:30 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[c]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=158</guid>
		<description><![CDATA[I have pushed an update for my silly php extension to github for anyone that wants to have a looksie. I&#8217;ve optimized the human_interval_precise function to only declare two variables (the long to hold the number of seconds passed in from userspace and the char array that gets passed back). Still need to figure out [...]]]></description>
			<content:encoded><![CDATA[<p>I have pushed an update for my silly php extension to github for anyone that wants to have a <a title="human.c on github" href="http://github.com/mihasya/human/tree/master/human.c">looksie</a>. I&#8217;ve optimized the human_interval_precise function to only declare two variables (the long to hold the number of seconds passed in from userspace and the char array that gets passed back). Still need to figure out a sensible max length for the return value and replace the arbitrary char[60] I have in there now.</p>

<p>I&#8217;ve also added a human_interval (not precise) function for approximating in the largest possible units. However, I just realized as I was writing this that I forgot to make it round in any way, so it probably comes up with fairly bogus results right now. Fail. Good thing this is just an exercise, and I&#8217;ll have another 3 hours on a shuttle to kill on Monday&#8230; and on Tuesday&#8230; and on Wednesday&#8230;</p>

<p>As I said before, I&#8217;m also working on a redo of the WordPress theme, as well as another more &#8220;grown up&#8221; C project.</p>

<p>Also, did not get laid off. Best of luck to all that did. Crazy times we live in.</p>

<p>PS: just saw on my nifty little wordpress toolbar that 2.7 is available. FUCKING ROCK! New design coming with the quickness.</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/my-c-is-more-better-now/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning to walk after running for 4 years: from PHP to C</title>
		<link>http://mihasya.com/blog/learning-to-walk-after-running-for-4-years-from-php-to-c/</link>
		<comments>http://mihasya.com/blog/learning-to-walk-after-running-for-4-years-from-php-to-c/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 20:05:48 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[c]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[c php extension]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=147</guid>
		<description><![CDATA[In an effort to stop being such a fucking noob, I&#8217;ve seriously taken up C. As a natural transition/crutch, I have started with PHP extensions. The PHP API basically picks your droppings up after you with a plastic bag, so it&#8217;s pretty easy. Using ext_skel gave me pretty much everything I needed, since I&#8217;ve only [...]]]></description>
			<content:encoded><![CDATA[<p>In an effort to stop being such a fucking noob, I&#8217;ve seriously taken up C. As a natural transition/crutch, I have started with PHP extensions. The PHP API basically picks your droppings up after you with a plastic bag, so it&#8217;s pretty easy. Using ext_skel gave me pretty much everything I needed, since I&#8217;ve only written one function so far and have not done anything fancy.</p>

<p>The extension is called &#8220;human,&#8221; short for &#8220;human readable.&#8221; The first function, human_interval_precise, simply represents a number of seconds in the largest &#8220;precise&#8221; time units possible. That is, thousands of seconds are converted to weeks, days, hours, minutes, and seconds as needed. The source is <a title="human git tree" href="http://github.com/mihasya/human/tree/master">here</a>.</p>

<h3>Lessons</h3>

<p>I&#8217;m obviously still a giant noob, but there are some things that I have picked up along the way (mostly via <a title="crowley's blog" href="http://rcrowley.org/">Crowley</a>) that made things a lot clearer. Hopefully my posting this will help other noobs following in my footsteps.</p>

<h4>&#8220;Pointers are just numbers&#8221;</h4>

<p>Yup. Just the number of memory blocks from the start of the segment of memory you&#8217;re dealing with. &#8220;Pointer math&#8221; is really just math: p+5 really is just the position in memory 5 blocks away from the start of p. The size of the blocks is determined by the pointer type, so if you have a char pointer, the blocks are 1 byte.</p>

<h4>an array is just a pointer to a set of consecutive memory blocks</h4>

<p>The name of the array is just the pointer to the first element. This is particularly important with char arrays. When I do the following in my code, I am just adding output to the end of an already existing &#8220;string.&#8221;
<pre><span class="n">sprintf</span><span class="p">(</span><span class="n">retstr</span><span class="o">+</span><span class="n">strlen</span><span class="p">(</span><span class="n">retstr</span><span class="p">),</span> <span class="s">"%dd "</span><span class="p">,</span> <span class="n">days</span>);</pre>
The K&amp;R section on the relationship between arrays and pointers is incredibly useful.</p>

<h4>Always remember to initialize your strings</h4>

<p>Nothing says &#8220;FAIL&#8221; like running your PHP function more than once in the same script and seeing it return its result appended to the end of the result from the previous call. A simple
<pre>*retstr = 0;</pre>
at the top of the function takes care of the problem. Otherwise, your char pointer ends up pointing to memory that isn&#8217;t claimed by anything else, but isn&#8217;t cleared either. In the case of consecutive PHP function runs, it just happens to be the previous output. It could end up being any sort of useless garbage.</p>

<p>I started writing this entry a few weeks ago and got sidetracked by a bigger and more interesting project/thanksgiving. As a result, I don&#8217;t remember what else I was going to write, so I&#8217;ll just wrap it up. More C learnings coming soon. It has been a humbling experience to say the least.</p>

<address></address>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/learning-to-walk-after-running-for-4-years-from-php-to-c/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

