<?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>stephendeken.net &#187; uncategorized</title>
	<atom:link href="http://stephendeken.net/blog/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://stephendeken.net/blog</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 31 Jul 2009 17:29:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>You&#8217;d think I&#8217;d know this stuff by now.</title>
		<link>http://stephendeken.net/blog/2009/02/12/youd-think-id-know-this-stuff-by-now/</link>
		<comments>http://stephendeken.net/blog/2009/02/12/youd-think-id-know-this-stuff-by-now/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 15:46:30 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[uncategorized]]></category>

		<guid isPermaLink="false">http://stephendeken.net/blog/?p=20</guid>
		<description><![CDATA[I&#8217;ve been using C and C++ for about ten years now, both personally and professionally.  And yet, I&#8217;ve never encountered a specific bit of syntax that I really should already know about: bit fields.  You can specify the specific number of bits required for integer members of C structs, allowing the compiler to take care [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using C and C++ for about ten years now, both personally and professionally.  And yet, I&#8217;ve never encountered a specific bit of syntax that I really should already know about: <a href="http://en.wikipedia.org/wiki/C_syntax#Bit_fields">bit fields</a>.  You can specify the specific number of bits required for integer members of C structs, allowing the compiler to take care of the bit masking and marshalling for you:</p>
<pre style="PADDING-LEFT: 30px">typedef struct foo {
    unsigned int flag_0 : 1, // one-bit variable (0..1)
    unsigned int small_enum : 4, // four-bit variable (0..15)
    unsigned int other_index : 3,  // three-bit variable (0..7)
} foo;</pre>
<p>This struct will be packed into a single byte (actually probably a single int), which can potentially save quite a bit of space.  You could do the same thing manually by specifiying one &#8220;flags&#8221; field and doing the bit-twiddling on your own, but the bit fields make the meaning and the code a lot cleaner.</p>
<p>I&#8217;m embarrassed to admit that I didn&#8217;t know this even existed until yesterday, when I had to open up the NSWindow sources to look something up.</p>
]]></content:encoded>
			<wfw:commentRss>http://stephendeken.net/blog/2009/02/12/youd-think-id-know-this-stuff-by-now/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
