<?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/"
	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>English Butterflies in the garden</title>
	<atom:link href="http://ebitg.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ebitg.wordpress.com</link>
	<description></description>
	<lastBuildDate>Mon, 09 Jan 2012 22:45:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ebitg.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>English Butterflies in the garden</title>
		<link>http://ebitg.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ebitg.wordpress.com/osd.xml" title="English Butterflies in the garden" />
	<atom:link rel='hub' href='http://ebitg.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Resource Management and Game Engines</title>
		<link>http://ebitg.wordpress.com/2012/01/10/resource-management-and-game-engines/</link>
		<comments>http://ebitg.wordpress.com/2012/01/10/resource-management-and-game-engines/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 22:43:37 +0000</pubDate>
		<dc:creator>Cristi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ebitg.wordpress.com/?p=358</guid>
		<description><![CDATA[I worked with C++ professionally for more than four years and I think that the memory management issues are most often found in C++ projects. There is no way in hell that you&#8217;ll not look for memory leaks and after that fix them, or look for buffer overrun bugs, or resolve a weird bug by <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=358&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I worked with C++ professionally for more than four years and I think that the memory management issues are most often found in C++ projects. There is no way in hell that you&#8217;ll not look for memory leaks and after that fix them, or look for buffer overrun bugs, or resolve a weird bug by finding a buffer overrun bug, or fix some other memory corruption bugs when writing C++. This is actually a big part of the C++ programmers time. </p>
<p>I watched some time ago a <a href="http://www.youtube.com/watch?v=9ei-rbULWoA">presentation</a> by James Gosling and one of the things he said was that he created Java because he spent so much time debugging memory bugs that he wanted to make sure he will not do that again. I programmed in Java, maybe more than I programmed in C++ and for a moment I really felt that. In that moment I remembered how it is to write code and not think about freeing things and not think about who destroys who, and what to delete in your destructor and all that: it&#8217;s so much fun. Sure it&#8217;s fun when I want control and I get that and I do a really good trick to save memory but most of the time I don&#8217;t care about memory. Most of that code seems so repetitive. So boring!</p>
<p>But the problem remains. It needs to be done when writing C++ and I think about ways to do this well a lot. Recently something obvious occurred to me. In all these years I programmed in C++ doing games and in games there is not a single framework for doing things. Everybody has his own engine or framework and it occurred to me that nobody uses this to their advantage. I mean if I write a framework then I can provide some useful stuff to the end-user but at the same time I get to impose some rules on that user. I get to say how my engine is used and if I get to say that, then maybe there is a way to simplify the memory management, at least in the context of my engine. And there is! Apple does this already in <a href="http://developer.apple.com/library/ios/#documentation/general/conceptual/devpedia-cocoacore/MemoryManagement.html">Objective-C with Cocoa</a>. I don&#8217;t understand why these things are not more common. Because of the nature of game engines I would expect to see this kind of memory management in every engine. It&#8217;s like a kind of bait: if you want to use this wonderful engine then abide by these rules and voilà your management for the memory is so much simple.</p>
<p>And also in a game engine you could have a lot of fun stuff especially for games. For example tagged allocations. I mean if I allocate everything with the tag &#8220;Level1&#8243; attached, then when I want to free Level1 I can just say something like ResMgr-&gt;Free(&#8220;Level1&#8243;) and not care about all the things I&#8217;ve created for &#8220;Level1&#8243; because my resource manager knows that. What I mean is that it&#8217;s not helping anyone if the code in a game engine is generic. It should be specific, it should take into account the domain.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ebitg.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ebitg.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ebitg.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ebitg.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ebitg.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ebitg.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ebitg.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ebitg.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ebitg.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ebitg.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ebitg.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ebitg.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ebitg.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ebitg.wordpress.com/358/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=358&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ebitg.wordpress.com/2012/01/10/resource-management-and-game-engines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deac5b5b0c8bdf85bd8345c8ef1a39e4?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">phocus1234</media:title>
		</media:content>
	</item>
		<item>
		<title>Compiling OS code with CMake</title>
		<link>http://ebitg.wordpress.com/2011/12/29/compiling-os-code-with-cmake/</link>
		<comments>http://ebitg.wordpress.com/2011/12/29/compiling-os-code-with-cmake/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 20:55:59 +0000</pubDate>
		<dc:creator>Cristi</dc:creator>
				<category><![CDATA[CMake]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ebitg.wordpress.com/?p=338</guid>
		<description><![CDATA[I was thinking for some time to switch from GNU Make to CMake for an OS project of mine. Sadly the project is just a barebones of an OS but it proved a good playground for testing things related to compiling and linking projects: the tutorial about GNU Make that I wrote a while ago <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=338&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was thinking for some time to switch from GNU Make to CMake for an <a href="https://github.com/phaser/phOS">OS project</a> of mine. Sadly the project is just a barebones of an OS but it proved a good playground for testing things related to compiling and linking projects: <a href="http://ebitg.wordpress.com/2011/09/09/gnu-make-a-tutorial/">the tutorial about GNU Make</a> that I wrote a while ago came out as a consequence of this project.</p>
<p>Anyway, for some time, I just thought that it wouldn&#8217;t be possible to do this so I didn&#8217;t bothered but in the past month I did a build system at work using CMake and I learned a lot of things. CMake is truly an incredible tool! So today I gave it a shot. It was easy but I learned a couple of things in the process.</p>
<p><pre class="brush: cpp;">
cmake_minimum_required (VERSION 2.8)
PROJECT (kernel)

INCLUDE_DIRECTORIES (include)

SET (CMAKE_CXX_FLAGS &quot;-m32 -ffreestanding -fno-rtti -fno-exceptions -nostdlib -nostdinc -fno-stack-protector&quot;)
SET (CMAKE_C_FLAGS &quot;-m32 -ffreestanding -fno-exceptions -nostdlib -nostdinc -fno-stack-protector&quot;)
SET (CMAKE_EXE_LINKER_FLAGS &quot;-m elf_i386 -T${CMAKE_CURRENT_LIST_DIR}/link.ld&quot;)
SET (CMAKE_ASM_NASM_OBJECT_FORMAT &quot;elf&quot;)

ENABLE_LANGUAGE (ASM_NASM)

FILE (GLOB_RECURSE kernel_C_SOURCES &quot;kernel/*.c&quot;)
FILE (GLOB_RECURSE kernel_CPP_SOURCES &quot;kernel/*.cpp&quot;)
FILE (GLOB_RECURSE kernel_ASM_SOURCES &quot;arch/x86/asm/*.nasm&quot;)
FILE (GLOB_RECURSE kernel_ARCH_C_SOURCES &quot;arch/x86/*.c&quot;)
FILE (GLOB_RECURSE kernel_ARCH_CPP_SOURCES &quot;arch/x86/*cpp&quot;)

ADD_LIBRARY (kernel.img STATIC
			${kernel_C_SOURCES} 
			${kernel_CPP_SOURCES} 
			${kernel_ARCH_C_SOURCES} 
			${kernel_ARCH_CPP_SOURCES} 
			${kernel_ASM_SOURCES})

ADD_CUSTOM_COMMAND (TARGET kernel.img
	POST_BUILD
	COMMAND &quot;/usr/bin/ld -m elf_i386 -T${CMAKE_CURRENT_LIST_DIR}/link.ld -o phOS.img ${CMAKE_BINARY_DIR}/libkernel.img.a&quot;)
</pre></p>
<p>As you can see the file came out pretty small. The first thing that I&#8217;ve learned was about <a href="http://www.vtk.org/Wiki/CMake/Assembler">compiling asm files</a>. CMake has now support for that. All you have to do is <strong>ENABLE_LANGUAGE (ASM_NASM)</strong> and when you feed it *.nasm and *.asm files it will do the job. The thing that I was stuck with was the format of the outputed binary. By default CMake gave nasm a <strong>-f elf64</strong> option (considering that I&#8217;m on a x86_64 platform). It took me a while to discover that you can change that by setting <strong>CMAKE_ASM_NASM_OBJECT_FORMAT</strong> variable.</p>
<p>The second major problem was with linking. I want to issue the link command myself and I tried to influence CMake but it came out wrong. As far as I understand CMake generates a link script and on linux it uses the compiler to link object files instead of LD (in the end LD is used probably but trough the compiler). In the end I solved this by making a static library and then adding a POST_BUILD command that relinked that library in something that I wanted. After the build finishes the custom command is executed and I obtain the binary that I want.</p>
<p>Now I get all the good things that come with CMake, IDE support being the most wanted feature on my list. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ebitg.wordpress.com/338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ebitg.wordpress.com/338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ebitg.wordpress.com/338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ebitg.wordpress.com/338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ebitg.wordpress.com/338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ebitg.wordpress.com/338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ebitg.wordpress.com/338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ebitg.wordpress.com/338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ebitg.wordpress.com/338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ebitg.wordpress.com/338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ebitg.wordpress.com/338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ebitg.wordpress.com/338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ebitg.wordpress.com/338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ebitg.wordpress.com/338/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=338&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ebitg.wordpress.com/2011/12/29/compiling-os-code-with-cmake/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deac5b5b0c8bdf85bd8345c8ef1a39e4?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">phocus1234</media:title>
		</media:content>
	</item>
		<item>
		<title>C++ Forward Declarations</title>
		<link>http://ebitg.wordpress.com/2011/12/20/c-forward-declarations/</link>
		<comments>http://ebitg.wordpress.com/2011/12/20/c-forward-declarations/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 21:10:43 +0000</pubDate>
		<dc:creator>Cristi</dc:creator>
				<category><![CDATA[Best common practice]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://ebitg.wordpress.com/?p=289</guid>
		<description><![CDATA[I wrote in an earlier post about forward declarations. There I gave a real world example and argued that is a very good idea to forward declare everything and I said that usually the main argument for forward declaration (at least from my experience) is speed of compilation. After I thought a little more on this <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=289&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I wrote in an <a title="Why coding style matter?" href="http://ebitg.wordpress.com/2011/12/04/why-conding-style-matter/">earlier post</a> about forward declarations. There I gave a real world example and argued that is a very good idea to forward declare everything and I said that usually the main argument for forward declaration (at least from my experience) is speed of compilation. After I thought a little more on this subject I&#8217;ve realized that this topic is not covered in detail in the literature. Sure you can find out how to forward declare &#8220;stuff&#8221; but to actually find something that resembles a best common practice guide is hard: it&#8217;s hard to find reasons to actually do this. So, in this post, I will try to give some real life examples and show the many forms of forward declaring as best as I can.</p>
<p>Let&#8217;s say you&#8217;re developing a 2D game engine. Your game engine will be a library that you and possibly other users will use. The engine provides many abstractions and one of them is loading and drawing an image on screen. Now your engine supports many image formats by using several libraries like libpng, libjpeg etc. To abstract the various image formats you have a class called Image with the interface declared in Image.h.</p>
<p><pre class="brush: cpp;">
#include &lt;png.h&gt;
#include &lt;jpeg.h&gt;

class Image
{
...
}
</pre></p>
<p>Your API interface has a sprite class that you can use to draw images on the screen in Engine/Sprite.h that looks something like this.<br />
<pre class="brush: cpp;">
#include &lt;Image.h&gt;

class Sprite
{
public:
    Sprite(std::string&amp; filename);
    Render();
private:
    Image* img;
}
</pre></p>
<p>What is wrong with the code above? The Sprite class should abstract away all the details concerning third party image libraries. But because Image is included in the header and in Image.h I include png.h and jpeg.h, it&#8217;s probable that some structures or symbols will be included in my code. This means that the client of the API must have access to the include files of libpng nd/or libjpeg. This is useless because the user of the library should not be concerned with other dependencies, because that&#8217;s the purpose of the engine: to hide complexity and to provide a nice interface that does things in a friendlier way. Even if it is not a problem including some more include paths in the build, it&#8217;s still wrong because you actually signal to the client of your API that is ok to directly use libpng and libjpeg and this defeats the entire purpose of the API.</p>
<p>The solution to this problem is called forward declaration. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<pre class="brush: cpp;">
class Image;  // forward declaration

class Sprite
{
...
}
</pre></p>
<p>Now you&#8217;ll have to include the header file in the corresponding Sprite.cpp file but everything from Image.h will be included only in the engine and not in the clients code.</p>
<p>So what are good rules of thumb of forward declaration? </p>
<ol>
<li>You can&#8217;t forward declare the classes that you inherit from and if you think a little about this, it&#8217;ll make sense.
<li>Things that come from the standard library can be ignored. Don&#8217;t bother to forward declare those because they are already available to every unit that is compiled.
<li>You can forward declare everything except for things mentioned at 1 and 2 (optional): classes, structs, typedefs.
</ol>
<p>Number 3 can bring some problems especially if you use a C library. C libraries tend to have a lot of defined types. One such example is the FreeType library. FT_Face is a defined type. So if you declare one in your *.h file as a member, how can you forward declare this? You have to forward declare everything starting from the struct, and typedefs.</p>
<p><pre class="brush: cpp;">
struct FT_FaceRec_;  // first forward declare the struct
typedef struct FT_FaceRec_*  FT_Face;  // then forward declare the typedef because the typedef depends on the struct
</pre></p>
<p>So in order to forward declare FT_Face you have to search for the definition of the type and then forward declare the initial type (struct FT_FaceRec_) and then the new type (FT_Face) because the typedef declaration depends on the declaration of the struct.</p>
<p>This pretty much covers everything one needs to forward declare efficiently and I hope that the reasons to do this are compelling enough and are actually more important than compilation speed. It&#8217;s still good when something is done for the wrong reasons but the bad thing is that is easy to be inconsistent if those reasons are not strong enough to go all the way.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ebitg.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ebitg.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ebitg.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ebitg.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ebitg.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ebitg.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ebitg.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ebitg.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ebitg.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ebitg.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ebitg.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ebitg.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ebitg.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ebitg.wordpress.com/289/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=289&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ebitg.wordpress.com/2011/12/20/c-forward-declarations/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deac5b5b0c8bdf85bd8345c8ef1a39e4?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">phocus1234</media:title>
		</media:content>
	</item>
		<item>
		<title>Why coding style matter?</title>
		<link>http://ebitg.wordpress.com/2011/12/04/why-conding-style-matter/</link>
		<comments>http://ebitg.wordpress.com/2011/12/04/why-conding-style-matter/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 15:02:27 +0000</pubDate>
		<dc:creator>Cristi</dc:creator>
				<category><![CDATA[Best common practice]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ebitg.wordpress.com/?p=275</guid>
		<description><![CDATA[This is a lesson I&#8217;ve learned recently and is somewhat related with another thing that happened to me in the past. So, several months ago I was working on a piece of code and suddenly the code crashed in a function call in EASTL. Not giving any thought to the problem I said to myself <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=275&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is a lesson I&#8217;ve learned recently and is somewhat related with another thing that happened to me in the past. So, several months ago I was working on a piece of code and suddenly the code crashed in a function call in EASTL. Not giving any thought to the problem I said to myself that the problem must be in EASTL. Even if I had the sources I wasn&#8217;t familiar with the details so I just send an error report to the original author.</p>
<p>The author just told me that if I can replicate that problem in an unit test case then he would take a look at it. So I was stuck because the problem was in the implementation of a hash_map and I was using several instances of hash_map in my application but only this one crashed. This was a hash_map holding textures so I was assuming that maybe something was wrong with the implementation of the texture class. To make the matters worse when a colleague of mine moved some lines up and down or commented them the problem suddenly vanished. Because we were pressured by time we let this one go, thinking that if it has something to do with the implementation of the hash_map somebody else will bump into it and we&#8217;ll try to solve it then.</p>
<p>Then after a couple of months another colleague found something unusual in the implementation of the same texture module, a class for loading a picture format. Some struct was guarded by a <strong>#pragma pack(push, 1)</strong> but there was no <strong>#pragma pack(pop)</strong> at the end of the struct. As you probably know this directive is telling the compiler to let the struct unaligned (the default behavior is to align the struct at say 4 bytes &#8211; platform dependent &#8211; because of the faster access). This is useful if you want to read a struct from a file in one go just mapping the bytes on the structure. Is especially useful when reading headers of files and things like that so it is no surprise that it was used for texture loading.</p>
<blockquote><p>Read more about pragmas at <a href="http://msdn.microsoft.com/en-us/library/d9x1s805.aspx">http://msdn.microsoft.com/en-us/library/d9x1s805.aspx</a></p></blockquote>
<p>Anyway we figured that this was the original cause for the hash_map crash. Probably the implementation of the hash_map did some assumptions about the alignment of structures.</p>
<p>The thing that stuck with me from all this situation is that at the moment I was trying to figure out a way to prevent this. What do I or anyone else could have done to prevent these kind of problems or to, at least, minimize the effects?</p>
<p>Last week I had a discussion at work about the usefulness of forward declaring classes in C++ and in the discussion we kept enumerating good reasons for doing this. Everybody will tell you about compilation speed but I jumped ahead and said something like &#8220;well it&#8217;s good to do this because you only include what you really need and in this way you can prevent all sorts of bad things&#8221;. And everybody kept waiting looking at me: &#8220;like what?&#8221;. And I start thinking at things and then the initial story pops into my head. If we have kept the includes at a minimum that problem couldn&#8217;t have manifested itself because probably the problem was that the header file was included in other header files and the pragma option applied to several other structures that we were using or even structures in EASTL.</p>
<p>So this was my answer. We could have kept the effects at a minimum if we respected a simple coding style rule: <strong>Forward declare everything you can!</strong></p>
<p>BTW we&#8217;ve started doing this after we&#8217;ve committed ourselves to use <a title="Google C++ Coding Style" href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml">Google C++ Coding Style</a>.</p>
<p>The other solution to these kinds of problems is to have a static analyzer checking your code periodically but you don&#8217;t know if the static analyzer will check for these kinds of issues, so respecting strong coding guidelines is better. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ebitg.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ebitg.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ebitg.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ebitg.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ebitg.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ebitg.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ebitg.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ebitg.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ebitg.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ebitg.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ebitg.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ebitg.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ebitg.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ebitg.wordpress.com/275/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=275&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ebitg.wordpress.com/2011/12/04/why-conding-style-matter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deac5b5b0c8bdf85bd8345c8ef1a39e4?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">phocus1234</media:title>
		</media:content>
	</item>
		<item>
		<title>GNU make: A tutorial</title>
		<link>http://ebitg.wordpress.com/2011/09/09/gnu-make-a-tutorial/</link>
		<comments>http://ebitg.wordpress.com/2011/09/09/gnu-make-a-tutorial/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 13:06:29 +0000</pubDate>
		<dc:creator>Cristi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://ebitg.wordpress.com/?p=226</guid>
		<description><![CDATA[I&#8217;m using GNU Make in one of my projects and I&#8217;m always struggling to get everything right. This is because the nature of the project, because of Make&#8217;s cryptic way of doing things and because of a lack of good tutorials. I said tutorials because most of the time I don&#8217;t care about my build system, my <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=226&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using <a title="GNU Make" href="http://www.gnu.org/software/make/">GNU Make</a> in <a title="phOS" href="https://github.com/phaser/phOS">one</a> of <a href="https://github.com/phaser">my projects</a> and I&#8217;m always struggling to get everything right. This is because the nature of the project, because of Make&#8217;s cryptic way of doing things and because of a lack of good tutorials. I said tutorials because most of the time I don&#8217;t care about my build system, my project being at the beginning, and I just want to apply a recipe and just get my project compiled.</p>
<p>It looks that I&#8217;m out of luck with Make in this regard because all the tutorials are either basic or advanced discussing how to use Make in large projects for example. Let&#8217;s see why the basic tutorials are useless and which parts should be covered in order to remedy their shortcomings. The basic tutorials tell you that Make, when invoked, looks for a <strong>Makefile</strong> file in the current directory. This Makefile contains rules that tell Make what commands to issue. The rules in the Makefile have the following form:</p>
<p><code>target: dependencies<br />
[tab] system command<br />
</code></p>
<p>You have a special target called <strong>all</strong> that can be used as a default target. When you invoke make, if you don&#8217;t specify the target, this target and the corresponding rules will be executed.</p>
<p>Knowing this the tutorial shows how to compile a file (or two):</p>
<p><pre class="brush: python;">
all: test

test: test.o sort.o
	gcc test.o sort.o -o test

test.o: test.c
	gcc -c test.c

sort.o: sort.c
	gcc -c sort.c
</pre></p>
<p>The <strong>all</strong> target is dependent on <strong>test</strong> and the <strong>test</strong> target is dependent on <strong>test.o</strong> and <strong>test.o</strong> target is dependent on <strong>test.c</strong> and <strong>test.c</strong> isn&#8217;t a target, so the command associated with this rule is executed producing <strong>test.o</strong> object, and going back we see that <strong>test</strong> is also dependent on <strong>sort.o</strong> and <strong>sort.o</strong> is dependent on <strong>sort.c</strong>, so <strong>sort.c</strong> is compiled and then the command for <strong>test</strong> is executed now that all its dependencies are satisfied and we end up with the compiled and linked program named <strong>test</strong>.</p>
<p>What I&#8217;m trying to say is that all the dependencies are organized into a tree of dependencies and the rules executed from leafs to root like in the figure below.</p>
<div id="attachment_242" class="wp-caption aligncenter" style="width: 425px"><a href="http://ebitg.files.wordpress.com/2011/09/make_depend2.png"><img class="size-full wp-image-242" title="make_depend" src="http://ebitg.files.wordpress.com/2011/09/make_depend2.png?w=510" alt="Make script dependency tree"   /></a><p class="wp-caption-text">Make script dependency tree</p></div>
<p>Now you can write a Makefile to compile some source files but usually you want to use a build system to compile a small project and you want to use it to simplify your life. What you learned so far doesn&#8217;t simplify shit because you can do the same, involving the same amount of work, with bash scripts. Let me elaborate!</p>
<p>Let&#8217;s say that you will add 10 more files to the project. For each file you add 3 lines (2 lines of code and a empty line) of repetitive commands and you modify the test target to contain the new dependencies. That means 30 lines more of text adding to a total of 40 lines. I bet you can do better using a Bash script! Imagine what happens when you delete a file or when you rename a file. Every time you modify something you have to edit the Makefile. This is the reason I think many basic Make tutorials are not so good. Because they teach you some basic stuff about the system but those things are not enough to use the system in such a way that simplifies things for you.</p>
<h3>Letting make Deduce the Recipes</h3>
<p>&nbsp;<br />
Let&#8217;s see what info is missing that we can use to have a simple, more generic Makefile that adapts more easily to simple modifications. The first important bit of info that will help us a lot can be found in the <a title="2.5 Letting make Deduce the Recipes" href="http://www.gnu.org/software/make/manual/make.html#make-Deduces">GNU Make manual</a> and it concerns a special feature of make that lets make deduce predefined recipes for you. For example make knows that a .o file is produced from a .c or .cpp file. So if you don&#8217;t specify an explicit recipe for a target like this, make will execute a predefined one for you if it finds a corresponding .c or .cpp file for the intended target.</p>
<p><pre class="brush: python;">
all: test

test: test.o sort.o
	gcc test.o sort.o -o test
</pre></p>
<p>Using this info we can modify the Makefile to look like above. When a new file is added we just add it in two places. And even for 30 more files we can keep the build file at only 4 lines. But still can we do better? Of course!</p>
<h3>Special make variables</h3>
<p>&nbsp;<br />
First, what do better in our example means? When we add a file, modify a file or delete a file we must modify the same information in two places. We can avoid this by placing the list of files in a variable but it pays to learn about several special variables that can come in handy at times even if for this example they are not the only answer.</p>
<ul>
<li>$^ &#8211; will expand to the list of prerequisites (dependencies)
<li>$&lt; &#8211; will expand to the first prerequisite (dependency)
<li>$@ &#8211; will expand to the target
</ul>
<p>The explanations above are very simple and you can use the variables like this for simple examples but watch out for unexpected behaviour and if something unusual happens, go read the manual. Also in the manual you&#8217;ll find several others useful special make variables. Using these we can transform our Makefile:</p>
<p><pre class="brush: python;">
SOURCES=test.o sort.o
all: test

test: $(SOURCES)
	gcc $^ -o $@
</pre></p>
<p>So now if something in our project changes we have to make the change to a single line and not worry about the rest.</p>
<h3>Configuring the compiler</h3>
<p>&nbsp;<br />
Previously when we discussed the automatic recipes I&#8217;ve left out an important bit of info. When the compiler is invoked you&#8217;ll probably see a simple command like <strong>cc -c -o file.o file.c</strong> but usually we want to pass configuration options to both gcc or g++. We can do that by putting those configure options in the environment variables CFLAGS (for gcc), CXXFLAGS (for g++) or CPPFLAGS (for the preprocessor) or setting them in our Makefile like in the example below:</p>
<p><pre class="brush: python;">
SOURCES=test.o sort.o
CFLAGS=-O3
CXXFLAGS=-O3
all: test

test: $(SOURCES)
	gcc $^ -o $@
</pre></p>
<p>These variables can be configured when you issue the make command:<br />
<code>CFLAGS=-O3 make</code></p>
<h3>Conclusions</h3>
<p>&nbsp;<br />
This is, in my opinion, everything one needs to start out with make and use it to save time. And for simple projects we just move one Makefile around modify the SOURCES line and we&#8217;re compiling things. But by using a final tip we can have a generic Makefile that compiles all .c or .cpp files in the current directory. This is achieved by using two make functions: <strong>wildcard</strong> and <strong>patsubst</strong>.</p>
<p><pre class="brush: python;">
SOURCES=$(patsubst %.c,%.o,$(wildcard *.c))
CFLAGS=-O3
CXXFLAGS=-O3
all: test

test: $(SOURCES)
	gcc $^ -o $@
</pre></p>
<p>Wildcard makes a list of all .c files in the current directory and then patsubst replaces the extension from .c to .o. </p>
<p>You now have a generic file that can be used as a starting point for any small project. For bigger projects I strongly recommend reading the GNU make manual. It&#8217;s up to you to add a clean target or any other targets that your project may need but you&#8217;ll find this info elsewhere.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ebitg.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ebitg.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ebitg.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ebitg.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ebitg.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ebitg.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ebitg.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ebitg.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ebitg.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ebitg.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ebitg.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ebitg.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ebitg.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ebitg.wordpress.com/226/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=226&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ebitg.wordpress.com/2011/09/09/gnu-make-a-tutorial/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deac5b5b0c8bdf85bd8345c8ef1a39e4?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">phocus1234</media:title>
		</media:content>

		<media:content url="http://ebitg.files.wordpress.com/2011/09/make_depend2.png" medium="image">
			<media:title type="html">make_depend</media:title>
		</media:content>
	</item>
		<item>
		<title>Poker and curing ignorance a little bit at a time</title>
		<link>http://ebitg.wordpress.com/2011/08/30/poker-and-curing-ignorance-a-little-bit-at-a-time/</link>
		<comments>http://ebitg.wordpress.com/2011/08/30/poker-and-curing-ignorance-a-little-bit-at-a-time/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 12:47:56 +0000</pubDate>
		<dc:creator>Cristi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ebitg.wordpress.com/?p=214</guid>
		<description><![CDATA[I started developing some utilities related to Poker. Practically I wrote code in Java to help me compute all kinds of things related to the game of poker. For example you hold two cards, you know the flop and you want to see how you stand against an opponent. In order to do this you <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=214&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I started developing some utilities related to Poker. Practically I wrote code in Java to help me compute all kinds of things related to the game of poker. </p>
<p>For example you hold two cards, you know the flop and you want to see how you stand against an opponent. In order to do this you must list all the other possible hands and all the combinations of 2 cards that represents the turn and the river cards. You compare all the possible hands and see in what percent of the cases you win and in what percent you lose and you know what are your chances. This is only an example but in order to achieve this you must write code to generate all combinations.</p>
<p>When I have to generate all possible solutions, the first (and only) algorithm that comes to mind is <a href="http://en.wikipedia.org/wiki/Backtracking" title="Backtracking Wikipedia Entry">Backtracking</a>. Recursive backtracking is really easy to implement so I&#8217;ve implemented one and it worked OK for combinations of 2 but for 3 i got heap overflow exceptions. The solution now is to implement an iterative backtracking algorithm. I could&#8217;ve modified the recursive one and transform it into an &#8220;ugly&#8221; iterative version but I said to myself that first I should check out some books or papers about backtracking. If I need it and I&#8217;m not remembering it so well, at least I got to try to understand it right this time.</p>
<p>So I opened <a href="http://en.wikipedia.org/wiki/The_Art_of_Computer_Programming">Knuth &#8211; The art of computer programming</a> &#8211; Volume 4A and I started with generating n-tuples and on the second page it struck me. In several lines of pseudocode it was this simple algorithm to generate all n-tuples, that you can use to generate all permutations and with some modifications you can also use it to generate all combinations. And above all it is not backtracking.</p>
<p>The idea is super simple. You start with a number expressed in n digits and you always add one to it and print the solutions. So you start with 00 and you add 1 and the number becomes 01 and you print the solution. Then you add 1 and the number becomes 02 and so on. When the number is 09 and you add one to it, it will become 10 and so on until 99.</p>
<p>When you want to generate combinations you must impose the condition that the digits are always in ascending or descending order. Also if you have more than 10 symbols to combine, you just use a different radix for each digit: in my case radix 52 because in a pack of cards you have 52 different cards. And if for each digit you have a different set of symbols you can use an array with different radices for each digit.</p>
<p>So simple and elegant!</p>
<p>Edit: An implementation of the idea above can be found at <a href="https://github.com/phaser/jpokerlib/blob/master/src/main/java/ro/qui/poker/mechanics/CardListGenerator.java">CardListGenerator.java</a> from the jpokerlib project. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ebitg.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ebitg.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ebitg.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ebitg.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ebitg.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ebitg.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ebitg.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ebitg.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ebitg.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ebitg.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ebitg.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ebitg.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ebitg.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ebitg.wordpress.com/214/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=214&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ebitg.wordpress.com/2011/08/30/poker-and-curing-ignorance-a-little-bit-at-a-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deac5b5b0c8bdf85bd8345c8ef1a39e4?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">phocus1234</media:title>
		</media:content>
	</item>
		<item>
		<title>GCC output 32 bit binary on 64 bit platform</title>
		<link>http://ebitg.wordpress.com/2011/07/18/gcc-output-32-bit-binary-on-64-bit-platform/</link>
		<comments>http://ebitg.wordpress.com/2011/07/18/gcc-output-32-bit-binary-on-64-bit-platform/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 20:23:30 +0000</pubDate>
		<dc:creator>Cristi</dc:creator>
				<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://ebitg.wordpress.com/?p=208</guid>
		<description><![CDATA[I tried recently to compile a 32 bit older program that I wrote on a 64 bit Ubuntu Linux. The project compiles several assembly files with NASM, some other files with GCC and in the end linking everything together with GNU LD. On the first try I got the following error message: ld: i386 architecture <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=208&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I tried recently to compile a 32 bit older program that I wrote on a 64 bit Ubuntu Linux. The project compiles several assembly files with <a href="http://www.nasm.us/" title="The Netwide Assembler">NASM</a>, some other files with <a href="http://gcc.gnu.org/" title="GNU Compiler Collection">GCC</a> and in the end linking everything together with GNU LD. On the first try I got the following error message:</p>
<p><code>ld: i386 architecture of input file `arch/monitor.o' is incompatible with i386:x86-64 output</code></p>
<p>After some goggling I found out how to force LD into linking the binaries for an i386 architecture by giving it the <strong>-m elf_i386</strong> argument but after that it started complaining about the binaries outputted by GCC not being compatible with the i386 output. </p>
<p><code>ld: i386:x86-64 architecture of input file `kernel/main.o' is incompatible with i386 output</code></p>
<p>That is because on x86-64 GCC outputs 64 bit binaries. In order to tell GCC to output x86-32 binaries you have to use <strong>-m 32</strong> flag. After this it worked perfectly! </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ebitg.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ebitg.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ebitg.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ebitg.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ebitg.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ebitg.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ebitg.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ebitg.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ebitg.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ebitg.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ebitg.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ebitg.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ebitg.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ebitg.wordpress.com/208/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=208&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ebitg.wordpress.com/2011/07/18/gcc-output-32-bit-binary-on-64-bit-platform/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deac5b5b0c8bdf85bd8345c8ef1a39e4?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">phocus1234</media:title>
		</media:content>
	</item>
		<item>
		<title>Peter Seibel &#8211; Coders at work</title>
		<link>http://ebitg.wordpress.com/2011/03/03/peter-seibel-coders-at-work/</link>
		<comments>http://ebitg.wordpress.com/2011/03/03/peter-seibel-coders-at-work/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 20:44:07 +0000</pubDate>
		<dc:creator>Cristi</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[books]]></category>

		<guid isPermaLink="false">http://ebitg.wordpress.com/?p=161</guid>
		<description><![CDATA[I&#8217;ve just finished reading Coders at work by Peter Seibel and I&#8217;ll do a little review here to note some things that for sure I&#8217;ll want to remember and maybe these things are interesting for others too. The book is an interview collection with several prominent figures from the field of &#8220;computer science&#8221; and if <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=161&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://codersatwork.com/"><div class="wp-caption alignleft" style="width: 177px"><img title="Coders at work cover" src="http://codersatwork.com/cover.jpg" alt="Coders at work cover" width="167" height="246" /><p class="wp-caption-text">Coders at work cover</p></div></a></p>
<p>I&#8217;ve just finished reading <a href="http://codersatwork.com">Coders at work by Peter Seibel</a> and I&#8217;ll do a little review here to note some things that for sure I&#8217;ll want to remember and maybe these things are interesting for others too. The book is an interview collection with several prominent figures from the field of &#8220;computer science&#8221; and if one thinks that you have things to learn from interviews then this book is a must read. Personally I&#8217;m interested in the context that other professionals work and the way that that context influenced them and the book does a pretty good job at answering this. Sure it could be better but you can&#8217;t find so many books with the same profile so I&#8217;m happy with less than nothing at all.</p>
<p>One interesting point that I found in the book is that all the interviewees said that the qualities needed to become a good programmer/craftsman/coder/engineer (the term is not agreed upon <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) remained pretty much unchanged but right now we have some people doing something that looks like programming but is not really programming according to some of the people interviewed in the book. I&#8217;m referring here to people that are just using APIs and are fitting pieces of code together all day long without being interested in the art of programming or the history of this field.</p>
<p>There are a lot of lessons in the book for technical leaders and project managers that I found very interesting.</p>
<blockquote><p>One of the things I’ve been pushing is code reading. I think that is the most useful thing that a community of programmers can do for each other—spend time on a regular basis reading each other’s code. There’s a tendency in project management just to let the programmers go off independently and then we have the big merge and if it builds then we ship it and we’re done and we forget about it. One of the consequences of that is that if you have weak or confused programmers you’re not aware of their actual situation until much too late. And so the risks to the project, that you’re going to have to build with stuff that’s bad and the delays that that causes, that’s unacceptable. The other thing is that you may have brilliant programmers on the project who are not adequately mentoring the other people on the team. Code reading solves both of those problems. &#8212; Douglas Crockford</p></blockquote>
<p>Douglas Crockford talks a lot about how he hires people and what are the things you should look for when managing people. The advices from him are very good and all the people that have a management job usually touch this subject some way or another. Of course there are others in the book that touch these kinds of problems. Frances Allen makes some very interesting remarks about the appearance of the <a href="http://en.wikipedia.org/wiki/Waterfall_model">waterfall method</a> of managing software projects. It clearly shows that in this respect the domain was in a pioneering state and nobody knew exactly what was the right way to do things. It&#8217;s interesting that even today the processes are not so well established and at an instinctual level we are still looking for Brooks silver bullet.</p>
<blockquote><p>Then there’s—I don’t know if I read it somewhere or if I invented it myself—Joe’s Law of Debugging, which is that all errors will be plus/minus three statements of the place you last changed the program. &#8212; Joe Armstrong
</p></blockquote>
<p>The book contains some interesting things about debugging like the quote from Joe Armstrong. Also Bernie Cosell discusses some interesting stories about the bugs although he admits that his weapon of choice for squashing bugs is to rewrite the code that seems fishy.</p>
<p>At the end there is the cherry on the cake: Donald Knuth. His interview is the most interesting for me. I think he really shows that programming is an art, a science and a craft all at the same time and this is the real beauty of it. It really shows that he sees this from a lot of perspectives and that makes his point of view so rich and complete.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ebitg.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ebitg.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ebitg.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ebitg.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ebitg.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ebitg.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ebitg.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ebitg.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ebitg.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ebitg.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ebitg.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ebitg.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ebitg.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ebitg.wordpress.com/161/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=161&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ebitg.wordpress.com/2011/03/03/peter-seibel-coders-at-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deac5b5b0c8bdf85bd8345c8ef1a39e4?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">phocus1234</media:title>
		</media:content>

		<media:content url="http://codersatwork.com/cover.jpg" medium="image">
			<media:title type="html">Coders at work cover</media:title>
		</media:content>
	</item>
		<item>
		<title>Three stacks in the same vector interview problem</title>
		<link>http://ebitg.wordpress.com/2011/02/01/three-stacks-in-the-same-vector-interview-problem/</link>
		<comments>http://ebitg.wordpress.com/2011/02/01/three-stacks-in-the-same-vector-interview-problem/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 18:52:57 +0000</pubDate>
		<dc:creator>Cristi</dc:creator>
				<category><![CDATA[Interview questions]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ebitg.wordpress.com/?p=148</guid>
		<description><![CDATA[I was talking some time ago with a couple of colleagues about interview questions. The discussion started after I told them about Gayle Laakmanns book Cracking the coding interview. We started throwing various classic interview questions at each other that we found on the Internet and discussing solutions. Following this fun road we arrived at <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=148&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was talking some time ago with a couple of colleagues about interview questions. The discussion started after I told them about Gayle Laakmanns book <a href="http://www.amazon.com/Cracking-Coding-Interview-Fourth-Programming/dp/145157827X">Cracking the coding interview</a>. We started throwing various classic interview questions at each other that we found on the Internet and discussing solutions. Following this fun road we arrived at the problem concerning three stacks into the same vector.</p>
<p>So one has to give a good implementation for three stacks into a single array.</p>
<p>Well I thought about an esoteric solution that involved some bit operations. The idea was to divide each element in three. So if the vector was of type integer you would divide the integer into [10 10 12] bits = [32] bits. But in this stack you can hold numbers between  <img src='http://s0.wp.com/latex.php?latex=%5B-2%5E9%2C+2%5E9-1%5D&amp;bg=ffffff&amp;fg=666666&amp;s=0' alt='[-2^9, 2^9-1]' title='[-2^9, 2^9-1]' class='latex' /> ([512, 511]) big if you consider the sign. You can argue that since nothing is specified about what numbers you have to hold in the stacks this is a good solution. But anyway this is not very good because the counter argument can be that the size of an element is given by the type of elements that the array can hold.</p>
<p>So a better solution is needed. I saw on some blog that somebody else considered to divide the vector intro three equal parts putting the first stack at the beginning the second stack at the end of the array growing downward and the third stack at one third of the array growing upward. This is still a bad solution because the second and the third stack can have at most two thirds of the vector in the eventuality that one of them is not used but the first stack only has one third of the vector.</p>
<p>I thought that you can start a stack somewhere in the vector but somehow be fair to the other stacks and following this train of thought I found the solution. You just start in the middle with the third stack and grow it in both directions alternatively. You hold the stack pointer and when you do a pop on the third stack you have to find the previous element in the stack to update the stack pointer. If the index of the element being popped is smaller than the middle of the vector then the next element is situated at 2*m-idx, m being the index of the middle element and idx being the index of the element being popped and 2*m-idx+1 if the index is bigger. And for the push the formula for finding the next index is somewhat similar.</p>
<p>Anyway this is just reinventing the wheel because the solution to this particular problem is all over the Internet but is fun in spite of this.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ebitg.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ebitg.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ebitg.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ebitg.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ebitg.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ebitg.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ebitg.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ebitg.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ebitg.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ebitg.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ebitg.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ebitg.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ebitg.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ebitg.wordpress.com/148/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=148&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ebitg.wordpress.com/2011/02/01/three-stacks-in-the-same-vector-interview-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deac5b5b0c8bdf85bd8345c8ef1a39e4?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">phocus1234</media:title>
		</media:content>
	</item>
		<item>
		<title>Linux Device Drivers Notes #2</title>
		<link>http://ebitg.wordpress.com/2010/12/07/linux-device-drivers-notes-2/</link>
		<comments>http://ebitg.wordpress.com/2010/12/07/linux-device-drivers-notes-2/#comments</comments>
		<pubDate>Tue, 07 Dec 2010 14:12:32 +0000</pubDate>
		<dc:creator>Cristi</dc:creator>
				<category><![CDATA[Kernel]]></category>
		<category><![CDATA[LDD Notes]]></category>

		<guid isPermaLink="false">http://ebitg.wordpress.com/?p=139</guid>
		<description><![CDATA[There are a number of options that one can enable in the kernel that can help debugging. These are useful when hacking on the kernel or when developing a new device driver (LDD Chapter 4). CONFIG_DEBUG_INFO CONFIG_DEBUG_SLAB CONFIG_DEBUG_PAGE_ALLOC CONFIG_DEBUG_SPINLOCK CONFIG_DEBUG_SPINLOCK_SLEEP CONFIG_INIT_DEBUG CONFIG_DEBUG_INFO CONFIG_MAGIC_SYSRQ CONFIG_DEBUG_STACKOVERFLOW CONFIG_DEBUG_STACK_USAGE CONFIG_KALLSYMS CONFIG_IKCONFIG CONFIG_IKCONFIG_PROC CONFIG_ACPI_DEBUG CONFIG_DEBUG_DRIVER CONFIG_SCSI_CONSTANTS CONFIG_INPUT_EVDEBUG CONFIG_PROFILING I just <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=139&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There are a number of options that one can enable in the kernel that can help debugging. These are useful when hacking on the kernel or when developing a new device driver (LDD Chapter 4).</p>
<p><code><br />
CONFIG_DEBUG_INFO<br />
CONFIG_DEBUG_SLAB<br />
CONFIG_DEBUG_PAGE_ALLOC<br />
CONFIG_DEBUG_SPINLOCK<br />
CONFIG_DEBUG_SPINLOCK_SLEEP<br />
CONFIG_INIT_DEBUG<br />
CONFIG_DEBUG_INFO<br />
CONFIG_MAGIC_SYSRQ<br />
CONFIG_DEBUG_STACKOVERFLOW<br />
CONFIG_DEBUG_STACK_USAGE<br />
CONFIG_KALLSYMS<br />
CONFIG_IKCONFIG<br />
CONFIG_IKCONFIG_PROC<br />
CONFIG_ACPI_DEBUG<br />
CONFIG_DEBUG_DRIVER<br />
CONFIG_SCSI_CONSTANTS<br />
CONFIG_INPUT_EVDEBUG<br />
CONFIG_PROFILING<br />
</code> </p>
<p>I just compiled linux 2.6.37-rc4 and tried to compile a test driver. The compilation failed because it didn&#8217;t found ioctl while initializing struct file_operations and after a little searching on the net and in the sources I&#8217;ve found that ioctl was replaced by a version that is not protected by BKL and another version protected (?) by the BKL to keep compatibility (unlocked_ioctl, compat_ioctl in linux/fs.h).</p>
<p>The second thing that is missing is the init_MUTEX macro that was removed from linux/semaphore.h. The macro just did a sema_init (&amp;sem, 1), so a simple replace did the job.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ebitg.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ebitg.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ebitg.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ebitg.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ebitg.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ebitg.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ebitg.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ebitg.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ebitg.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ebitg.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ebitg.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ebitg.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ebitg.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ebitg.wordpress.com/139/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ebitg.wordpress.com&amp;blog=8366423&amp;post=139&amp;subd=ebitg&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ebitg.wordpress.com/2010/12/07/linux-device-drivers-notes-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/deac5b5b0c8bdf85bd8345c8ef1a39e4?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">phocus1234</media:title>
		</media:content>
	</item>
	</channel>
</rss>
