<?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>ejohansson.se &#187; programming</title>
	<atom:link href="http://ejohansson.se/categories/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://ejohansson.se</link>
	<description>Random bits about Linux, programming, computers and occasionally other stuff.</description>
	<lastBuildDate>Tue, 06 Mar 2012 09:02:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Transparent HTTP proxy in&#160;python</title>
		<link>http://ejohansson.se/archives/2012/03/06/transparent-http-proxy-in-python/</link>
		<comments>http://ejohansson.se/archives/2012/03/06/transparent-http-proxy-in-python/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 09:02:05 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ejohansson.se/?p=460</guid>
		<description><![CDATA[I recently wanted to modify a web resource that a device on my local network loads when starting. To avoid having a static local modified copy of the resource I wrote a simple transparent HTTP proxy in python using the Twisted networking engine (which btw was a joy to use) which does the modification when [...]]]></description>
			<content:encoded><![CDATA[<p>I recently wanted to modify a web resource that a device on my local network loads when starting. To avoid having a static local modified copy of the resource I wrote a simple transparent HTTP proxy in python using the <a href="http://twistedmatrix.com/">Twisted networking engine</a> (which btw was a joy to use) which does the modification when the resource is loaded. The code is not modular (e.g. the resource modification is hard coded in the processResponse() function) and the logging is very verbose, but if anyone is interested the code is available on github: <a href="https://github.com/erijo/transparent-proxy">transparent-proxy.git</a>.</p>
<p>The proxy is now running on my local server which sits behind the real gateway. Besides making the device use the server as gateway and enable NAT on the server this single iptables rule is all that is needed:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iptables <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> PREROUTING <span style="color: #660033;">-s</span> <span style="color: #007800;">$CLIENT_IP</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> REDIRECT <span style="color: #660033;">--to-port</span> <span style="color: #000000;">8080</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2012/03/06/transparent-http-proxy-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compiler&#160;bug</title>
		<link>http://ejohansson.se/archives/2010/03/14/compiler-bug/</link>
		<comments>http://ejohansson.se/archives/2010/03/14/compiler-bug/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 17:49:05 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[licq]]></category>

		<guid isPermaLink="false">http://ejohansson.se/?p=327</guid>
		<description><![CDATA[To see if Licq would build without warnings with gcc 4.5 I tried to build Licq trunk with the latest gcc-snapshot in Debian today. Three warnings were quickly fixed but a bigger problem was that the unit test hung; something which doesn&#8217;t happen with earlier gcc. After some digging it turned out to be a [...]]]></description>
			<content:encoded><![CDATA[<p>To see if Licq would build without warnings with gcc 4.5 I tried to build <a href="http://licq.org/browser/trunk">Licq trunk</a> with the latest gcc-snapshot in Debian today. Three warnings were quickly fixed but a bigger problem was that the unit test hung; something which doesn&#8217;t happen with earlier gcc.</p>
<p>After some digging it turned out to be a problem with locking. A mutex was never unlocked when returning in the <a href="http://licq.org/browser/trunk/licq/src/plugins/pluginthread.cpp?rev=7096#L89">exception handler</a>. This was very strange as the unlocking should be done by the MutexLocker destructor.</p>
<p>I was able to reproduce the problem with a simple test program so I concluded that it was indeed a compiler bug and reported it: <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43365">Destructor not called when returning in exception handler</a>.</p>
<p>Not every day you get to find a compiler bug&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2010/03/14/compiler-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Printing all the pre defined gcc&#160;macros</title>
		<link>http://ejohansson.se/archives/2010/01/07/printing-all-the-pre-defined-gcc-macros/</link>
		<comments>http://ejohansson.se/archives/2010/01/07/printing-all-the-pre-defined-gcc-macros/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 08:14:12 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[c]]></category>

		<guid isPermaLink="false">http://ejohansson.se/?p=317</guid>
		<description><![CDATA[Found this useful command on brain-dump.org. Posting it here for my own reference: gcc -dM -E - &#60; /dev/null]]></description>
			<content:encoded><![CDATA[<p>Found this useful command on <a href="http://www.brain-dump.org/blog/entry/107">brain-dump.org</a>. Posting it here for my own reference:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-dM</span> <span style="color: #660033;">-E</span> - <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2010/01/07/printing-all-the-pre-defined-gcc-macros/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++Next</title>
		<link>http://ejohansson.se/archives/2009/10/30/cpp-next/</link>
		<comments>http://ejohansson.se/archives/2009/10/30/cpp-next/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 19:41:46 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[c++]]></category>

		<guid isPermaLink="false">http://ejohansson.se/?p=290</guid>
		<description><![CDATA[Found a very interesting C++ site the other day: C++Next. I highly recommend it if you&#8217;re interested in &#8220;the next generation of C++&#8221;.]]></description>
			<content:encoded><![CDATA[<p>Found a very interesting C++ site the other day: <a href="http://cpp-next.com/">C++Next</a>. I highly recommend it if you&#8217;re interested in &#8220;the next generation of C++&#8221;. </p>
]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2009/10/30/cpp-next/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Strip trailing whitespace in&#160;emacs</title>
		<link>http://ejohansson.se/archives/2008/08/26/strip-trailing-whitespace-in-emacs/</link>
		<comments>http://ejohansson.se/archives/2008/08/26/strip-trailing-whitespace-in-emacs/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 22:13:48 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[emacs]]></category>

		<guid isPermaLink="false">http://ejohansson.se/?p=195</guid>
		<description><![CDATA[Just installed WP-Syntax, a WordPress plugin for highlighting code. The first test will be this short elisp code I wrote to strip trailing whitespace from all lines in a file. &#40;defun strip-trailing-ws &#40;&#41; &#34;Strip trailing whitespace from all lines&#34; &#40;interactive&#41; &#40;let &#40;&#40;cur &#40;point-marker&#41;&#41;&#41; &#40;goto-char &#40;point-min&#41;&#41; &#40;while &#40;re-search-forward &#34;[ \t]+$&#34; nil t&#41; &#40;replace-match &#34;&#34; nil nil&#41;&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>Just installed <a title="WP-Syntax" href="http://wordpress.org/extend/plugins/wp-syntax/">WP-Syntax</a>, a WordPress plugin for highlighting code. The first test will be this short elisp code I wrote to strip trailing whitespace from all lines in a file.</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> strip-trailing-ws <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;Strip trailing whitespace from all lines&quot;</span>
  <span style="color: #66cc66;">&#40;</span>interactive<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>cur <span style="color: #66cc66;">&#40;</span>point-marker<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>goto-char <span style="color: #66cc66;">&#40;</span>point-<span style="color: #b1b100;">min</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>while <span style="color: #66cc66;">&#40;</span>re-search-forward <span style="color: #ff0000;">&quot;[ <span style="color: #000099; font-weight: bold;">\t</span>]+$&quot;</span> <span style="color: #b1b100;">nil</span> t<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>replace-match <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #b1b100;">nil</span> <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>goto-char <span style="color: #66cc66;">&#40;</span>marker-position cur<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2008/08/26/strip-trailing-whitespace-in-emacs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>++git;</title>
		<link>http://ejohansson.se/archives/2007/12/31/git/</link>
		<comments>http://ejohansson.se/archives/2007/12/31/git/#comments</comments>
		<pubDate>Mon, 31 Dec 2007 12:07:41 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://ejohansson.se/archives/2007/12/31/git/</guid>
		<description><![CDATA[As all the other cool kids, I&#8217;ve also started experimenting with git, the version control system used by many, most notably the Linux kernel developers. As a test I converted my program that enables the volume knob on Dell USB keyboards. You can find it on my gitweb site. Also there is the selinux policy [...]]]></description>
			<content:encoded><![CDATA[<p>As all the other cool kids, I&#8217;ve also started experimenting with <a href="http://git.or.cz/">git</a>, the version control system used by many, most notably the Linux kernel developers.</p>
<p>As a test I converted my program that <a href="http://ejohansson.se/archives/2006/05/23/enable-dells-volume-knob-under-linux/">enables the volume knob</a> on Dell USB keyboards. You can find it on <a href="http://git.ejohansson.se/">my gitweb</a> site.</p>
<p>Also there is the selinux policy module I blogged about in my <a href="http://ejohansson.se/archives/2007/11/04/selinux-subversion-and-mod_svn/">previous post</a>, and a new one that I had to do to get gitweb to work. Getting gitweb to work also required the git repositories to be properly labelled:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">semanage fcontext <span style="color: #660033;">-a</span> <span style="color: #660033;">-t</span> httpd_sys_script_ro_t <span style="color: #ff0000;">'/home/git(/.*)?'</span>
restorecon <span style="color: #660033;">-Rv</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">git</span></pre></div></div>

<p>Some day I need to figure out the correct syntax for putting file contexts in the policy module.</p>
]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2007/12/31/git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Qt programming in&#160;Lisp</title>
		<link>http://ejohansson.se/archives/2006/04/18/qt-programming-in-lisp/</link>
		<comments>http://ejohansson.se/archives/2006/04/18/qt-programming-in-lisp/#comments</comments>
		<pubDate>Tue, 18 Apr 2006 17:11:29 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[qt]]></category>

		<guid isPermaLink="false">http://ejohansson.se/archives/2006/04/18/qt-programming-in-lisp/</guid>
		<description><![CDATA[We all know the following facts: Qt is good; Lisp is good. So when I found the Lisp Qt4 bindings I knew it had to be good. I have &#8211; of course &#8211; not tried it (yet), but I like the concept. And there&#8217;s nothing like judging by appearance. Plus, good + good must equal [...]]]></description>
			<content:encoded><![CDATA[<p>We all know the following facts: Qt is good; Lisp is good. So when I found the <a href="http://members.aon.at/lispolos/">Lisp Qt4 bindings</a> I knew it had to be good. I have &#8211; of course &#8211; not tried it (yet), but I like the concept. And there&#8217;s nothing like judging by appearance. Plus, good + good must equal good. Just look at milk and beer&#8230; or umm&#8230; *cough*</p>
<p>While on the subject, I have to remember to try <a href="http://developer.kde.org/language-bindings/ruby/index.html">Korundum</a> when I get back to Linköping.</p>
]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2006/04/18/qt-programming-in-lisp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using booleans to document&#160;code</title>
		<link>http://ejohansson.se/archives/2006/04/09/using-booleans-to-document-code/</link>
		<comments>http://ejohansson.se/archives/2006/04/09/using-booleans-to-document-code/#comments</comments>
		<pubDate>Sun, 09 Apr 2006 16:12:09 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[qt]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://ejohansson.se/archives/2006/04/09/using-booleans-to-document-code/</guid>
		<description><![CDATA[Today I want to share a tip on how to write self-documenting code that I picked up from the book Code Complete 2 by Steve McConnell. I will do this be showing you some code I just wrote, but let us start with the actual tip. Instead of merely testing a boolean expression, you can [...]]]></description>
			<content:encoded><![CDATA[<p>Today I want to share a tip on how to write self-documenting code that I picked up from the book <a href="http://www.amazon.com/gp/product/0735619670/">Code Complete 2</a> by Steve McConnell. I will do this be showing you some code I just wrote, but let us start with the actual tip.</p>
<blockquote cite="http://www.cc2e.com/" title="Steve McConnell"><p>
Instead of merely testing a boolean expression, you can assign the expression to a variable that makes the implication of the test unmistakable.
</p></blockquote>
<p>The following code was my first try, not employing the tip.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp-qt" style="font-family:monospace;"><span style="color: #0057AE;">void</span> CETabWidget<span style="color: #006E28;">::</span><span style="color: #2B74C7;">wheelEvent</span><span style="color: #006E28;">&#40;</span><span style="color: #22aadd;">QWheelEvent</span> <span style="color: #006E28;">*</span>e<span style="color: #006E28;">&#41;</span>
<span style="color: #006E28;">&#123;</span>
  <span style="color: #22aadd;">QTabBar</span> <span style="color: #006E28;">*</span>tabs <span style="color: #006E28;">=</span> tabBar<span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span>
  <span style="color: #000000; font-weight:bold;">if</span> <span style="color: #006E28;">&#40;</span>e<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&lt;</span> tabs<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">||</span> e<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&gt;</span> <span style="color: #006E28;">&#40;</span>tabs<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">+</span> tabs.<span style="color: #2B74C7;">height</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&#123;</span>
    e<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">ignore</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span>
    return<span style="color: #006E28;">;</span>
  <span style="color: #006E28;">&#125;</span>
&nbsp;
  <span style="color: #888888;">// handle wheel event</span>
<span style="color: #006E28;">&#125;</span></pre></div></div>

<p>Even though I wrote the code myself, I have problems understanding it. And making sure it&#8217;s correct takes more than a quick glance. If you want to understand this code in six months, you have to add a comment. So let us take a look at the same code rewritten to use two extra booleans.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp-qt" style="font-family:monospace;"><span style="color: #0057AE;">void</span> CETabWidget<span style="color: #006E28;">::</span><span style="color: #2B74C7;">wheelEvent</span><span style="color: #006E28;">&#40;</span><span style="color: #22aadd;">QWheelEvent</span> <span style="color: #006E28;">*</span>e<span style="color: #006E28;">&#41;</span>
<span style="color: #006E28;">&#123;</span>
  <span style="color: #22aadd;">QTabBar</span> <span style="color: #006E28;">*</span>tabs <span style="color: #006E28;">=</span> tabBar<span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span>
  <span style="color: #0057AE;">const</span> <span style="color: #0057AE;">bool</span> cursorAboveTabBar <span style="color: #006E28;">=</span> <span style="color: #006E28;">&#40;</span>e<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&lt;</span> tabs<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span>
  <span style="color: #0057AE;">const</span> <span style="color: #0057AE;">bool</span> cursorBelowTabBar <span style="color: #006E28;">=</span> <span style="color: #006E28;">&#40;</span>e<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&gt;</span> <span style="color: #006E28;">&#40;</span>tabs<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">y</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">+</span> tabs<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">height</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span>
  <span style="color: #000000; font-weight:bold;">if</span> <span style="color: #006E28;">&#40;</span>cursorAboveTabBar <span style="color: #006E28;">||</span> cursorBelowTabBar<span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&#123;</span>
    e<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">ignore</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span>
    return<span style="color: #006E28;">;</span>
  <span style="color: #006E28;">&#125;</span>
&nbsp;
  <span style="color: #888888;">// handle wheel event</span>
<span style="color: #006E28;">&#125;</span></pre></div></div>

<p>Now you can quickly figure out that the wheel event is only handled if the cursor is inside the tabBar. And it&#8217;s actually possible to take a quick look and be sure that the code is doing what it&#8217;s supposed to.</p>
<p>Of course, for this to be of any good, you need to give the boolean variables meaningful names. Naming them a and b wouldn&#8217;t help a bit.</p>
<p>The best thing with this approach? You don&#8217;t have to write comments and still get code that people can understand. Ah, the joy!</p>
]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2006/04/09/using-booleans-to-document-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Language&#160;protagonist</title>
		<link>http://ejohansson.se/archives/2006/04/07/language-protagonist/</link>
		<comments>http://ejohansson.se/archives/2006/04/07/language-protagonist/#comments</comments>
		<pubDate>Fri, 07 Apr 2006 15:33:37 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://ejohansson.se/archives/2006/04/07/language-protagonist/</guid>
		<description><![CDATA[The use of &#8216;protagonist&#8217; in place of &#8216;proponent&#8217; has become common in the 20th century and may have been influenced by a misconception that the first syllable of the word represents the prefix pro- (ie. &#8216;favoring&#8217;) rather than proto-, meaning first (as opposed to deuter-, second, in deuteragonist, or tri-, third, in tritagonist). For example, [...]]]></description>
			<content:encoded><![CDATA[<blockquote cite="http://en.wikipedia.org/wiki/Protagonist" title="Wikipedia"><p>
The use of &#8216;protagonist&#8217; in place of &#8216;proponent&#8217; has become common in the 20th century and may have been influenced by a misconception that the first syllable of the word represents the prefix pro- (ie. &#8216;favoring&#8217;) rather than proto-, meaning first (as opposed to deuter-, second, in deuteragonist, or tri-, third, in tritagonist). For example, usage such as &#8220;He was an early protagonist of nuclear power&#8221; can be replaced by &#8216;advocate&#8217; or &#8216;proponent&#8217;.
</p></blockquote>
<p>So, now that you know that, go read this post about <a href="http://blogs.qtdeveloper.net/archives/2006/04/07/would-you-implement-java-in-java/">language protagonist</a>. Great read.</p>
]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2006/04/07/language-protagonist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Odd (and deprecated) g++&#160;extensions</title>
		<link>http://ejohansson.se/archives/2006/03/28/odd-and-deprecated-g-extensions/</link>
		<comments>http://ejohansson.se/archives/2006/03/28/odd-and-deprecated-g-extensions/#comments</comments>
		<pubDate>Tue, 28 Mar 2006 22:23:27 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[c++]]></category>

		<guid isPermaLink="false">http://ejohansson.se/archives/2006/03/28/odd-and-deprecated-g-extensions/</guid>
		<description><![CDATA[I&#8217;ve been spending the evening reading about libstdc++ (mostly the documentation) and how to do stuff The Right Way (the documentation is actually interesting, you should at least take a look at it). Now I feel the need to share some stuff that&#8217;s a bit more odd then what you see in the documentation. First: [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been spending the evening reading about <a href="http://gcc.gnu.org/libstdc++/">libstdc++</a> (mostly the <a href="http://gcc.gnu.org/onlinedocs/libstdc++/documentation.html">documentation</a>) and how to do stuff The Right Way (the documentation is actually interesting, you should at least take a look at it). Now I feel the need to share some stuff that&#8217;s a bit more odd then what you see in the documentation.</p>
<p>First: <a href="http://docs.freebsd.org/info/gcc/gcc.info.Naming_Results.html">&#8220;the named return value extension&#8221;</a>. The idea is to avoid creating a temporary variable that&#8217;s assigned a value and then returned by value, thus creating an unnecessary copy. A small example:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">std<span style="color: #008080;">::</span><span style="color: #007788;">list</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> foo<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> j<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span> l<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#123;</span>
  l.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span>j<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>This example will create just one list and append j to that. Without this extension a local list needs to be created, j appended to that and the copy constructor invoked when returning. This extension is deprecated in g++ 3.3 and removed in g++ 4.0.</p>
<p>My other example is the <a href="http://docs.freebsd.org/info/gcc/gcc.info.Min_and_Max.html">&#8220;min and max operators&#8221;</a>. No, this is not about min and max macros nor the std::min and std::max functions. This is the min and max <strong>operators</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> min <span style="color: #339933;">=</span> x <span style="color: #339933;">&lt;?</span> y<span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> max <span style="color: #339933;">=</span> x <span style="color: #339933;">&gt;?</span> y<span style="color: #339933;">;</span></pre></div></div>

<p>There is of course also a short-hand version for assigning one of the variables the smallest (or biggest) value of the two.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">x <span style="color: #339933;">&lt;?=</span> y<span style="color: #339933;">;</span>
x <span style="color: #339933;">&gt;?=</span> y<span style="color: #339933;">;</span></pre></div></div>

<p>They are all deprecated in g++ 4.0.</p>
]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2006/03/28/odd-and-deprecated-g-extensions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

