<?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>coding</title>
	<atom:link href="http://www.coding.com.br/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.coding.com.br</link>
	<description>have you coded today?</description>
	<lastBuildDate>Fri, 23 Jul 2010 02:37:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Shortening URL</title>
		<link>http://www.coding.com.br/blog/shortening-url/</link>
		<comments>http://www.coding.com.br/blog/shortening-url/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 16:44:40 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[python web]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1177</guid>
		<description><![CDATA[There are many URL shortening services. I just picked one (u.nu) to use from command line interface and chose something really quick and simple. Here&#8217;s the code:
# -*- coding: utf-8 -*-
from urllib import urlencode
import httplib
import sys

api_url="u.nu"
var = urlencode({'url':sys.argv[1]})
args = "/unu-api-simple?%s" % (var)
conn = httplib.HTTPConnection(api_url)
conn.request("GET",args)
ret = conn.getresponse()
print ret.read()
Download the script here.
Just run passing the URL, for example:
$ [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">There are <a title="List of URL shortening services" href="http://mashable.com/2008/01/08/url-shortening-services/" target="_blank">many</a> URL shortening services. I just picked one (<a href="http://u.nu" target="_blank">u.nu</a>) to use from <em>command line interface </em>and chose something really quick and simple. Here&#8217;s the code:</p>
<pre><span style="color: #444444;"># -*- coding: utf-8 -*-</span>
<strong>from</strong> <span style="color: #2040a0;">urllib</span> <strong>import</strong> <span style="color: #2040a0;">urlencode</span>
<strong>import</strong> <span style="color: #2040a0;">httplib</span>
<strong>import</strong> <span style="color: #2040a0;">sys</span>

<span style="color: #2040a0;">api_url</span><span style="color: #4444ff;">=</span><span style="color: #008000;">"u.nu"</span>
<span style="color: #2040a0;">var</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">urlencode</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;"><strong>{</strong></span><span style="color: #008000;">'url'</span><span style="color: #4444ff;">:</span><span style="color: #2040a0;">sys</span>.<span style="color: #2040a0;">argv</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">]</span><span style="color: #4444ff;"><strong>}</strong></span><span style="color: #4444ff;">)</span>
<span style="color: #2040a0;">args</span> <span style="color: #4444ff;">=</span> <span style="color: #008000;">"/unu-api-simple?%s"</span> <span style="color: #4444ff;">%</span> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">var</span><span style="color: #4444ff;">)</span>
<span style="color: #2040a0;">conn</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">httplib</span>.<span style="color: #2040a0;">HTTPConnection</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">api_url</span><span style="color: #4444ff;">)</span>
<span style="color: #2040a0;">conn</span>.<span style="color: #2040a0;">request</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"GET"</span>,<span style="color: #2040a0;">args</span><span style="color: #4444ff;">)</span>
<span style="color: #2040a0;">ret</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">conn</span>.<span style="color: #2040a0;">getresponse</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
<strong>print</strong> <span style="color: #2040a0;">ret</span>.<span style="color: #2040a0;">read</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span></pre>
<h5 style="text-align: center;">Download the script <a href="http://gist.github.com/486190" target="_blank">here</a>.</h5>
<p>Just run passing the URL, for example:</p>
<p style="padding-left: 30px;">$ python u.py www.coding.com.br</p>
<p style="padding-left: 30px;">http://u.nu/72mpd</p>
<p style="text-align: justify;">Easy your life by putting the script on your $PATH and execution (+x) file mode. Worth check the API from other services:</p>
<ul>
<li><a title="Documentation of bit.ly API" href="http://code.google.com/p/bitly-api/wiki/ApiDocumentation" target="_blank">bit.ly</a></li>
<li><a title="Documentation of migre.me API" href="http://migre.me/api-migreme/" target="_blank">migre.me</a> (brazilian company)</li>
<li><a title="Documentation of is.gd API" href="http://is.gd/api_info.php" target="_blank">is.gd</a></li>
<li><a href="http://tiny.cc/api-docs" target="_blank">tiny.cc</a></li>
<li><a href="http://www.scripting.com/stories/2007/06/27/tinyurlHasAnApi.html" target="_blank">tinyurl</a></li>
</ul>
<p style="padding-left: 30px;">
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/blog/shortening-url/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A brief on &#8220;designated initializers&#8221;</title>
		<link>http://www.coding.com.br/blog/a-brief-on-designated-initializers/</link>
		<comments>http://www.coding.com.br/blog/a-brief-on-designated-initializers/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 06:01:27 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[blog]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1155</guid>
		<description><![CDATA[The GNU Compiler Collection (GCC) for C language doesn&#8217;t initialize variables zeroed. For simple variables types like int or float is just equal to 0 or 0.0 respectively. Now, suppose that you have a &#8220;large&#8221; struct and doesn&#8217;t want to set each member  individually&#8230; you could just type &#8220;={0}&#8221; which means that the first member [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">The GNU Compiler Collection (GCC) for C language doesn&#8217;t initialize variables <em>zeroed.</em> For simple variables types like <em>int</em> or <em>float</em> is just equal to 0 or 0.0 respectively. Now, suppose that you have a &#8220;large&#8221; <em>struct</em> and doesn&#8217;t want to set each member  individually&#8230; you could just type &#8220;={0}&#8221; which means that the first member is explicitly initialized to zero and  the remaining members are implicitly initialized, also zero. Let&#8217;s see an example:</p>
<p><strong>typedef</strong> <strong>struct</strong><br />
<span style="color: #4444ff;"><strong>{</strong></span><br />
<strong> int</strong> <span style="color: #2040a0;">a</span><span style="color: #4444ff;">;</span><br />
<strong> char</strong> <span style="color: #2040a0;">c</span><span style="color: #4444ff;">;</span><br />
<strong> char</strong> <span style="color: #2040a0;">s</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">10</span><span style="color: #4444ff;">]</span><span style="color: #4444ff;">;</span><br />
<strong> int</strong> <span style="color: #4444ff;">*</span><span style="color: #2040a0;">ptr</span><span style="color: #4444ff;">;</span><br />
<span style="color: #4444ff;"><strong>}</strong></span> <span style="color: #2040a0;">data</span><span style="color: #4444ff;">;</span></p>
<p>When you initialize with:</p>
<p><span style="color: #2040a0;">data</span> <span style="color: #2040a0;">d</span><span style="color: #4444ff;"><strong></strong></span><span style="color: #4444ff;"><strong></strong></span><span style="color: #4444ff;">;</span></p>
<p>You got some random value like:</p>
<p>{a = -1208298748, c = -12 &#8216;\364&#8242;, s = &#8220;\317\372\267\230\353\377\277\351\203\004&#8243;, ptr = 0xb7e94cc5}</p>
<p>When you type:</p>
<p><span style="color: #2040a0;">data</span> <span style="color: #2040a0;">d</span> <span style="color: #4444ff;">=</span> <span style="color: #4444ff;"><strong>{</strong></span><span style="color: #ff0000;">0</span><span style="color: #4444ff;"><strong>}</strong></span><span style="color: #4444ff;">;</span></p>
<p>You&#8217;ll have each struct member initialized to <em>zero</em>.</p>
<p>{a = 0, c = 0 &#8216;\000&#8242;, s = &#8220;\000\000\000\000\000\000\000\000\000&#8243;, ptr = 0&#215;0}</p>
<p>You can learn much more about <a href="http://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html" target="_blank">designated inits</a> [section 6.26] on GCC docs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/blog/a-brief-on-designated-initializers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embed Python inside Latex</title>
		<link>http://www.coding.com.br/linux/embed-python-inside-latex/</link>
		<comments>http://www.coding.com.br/linux/embed-python-inside-latex/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 19:37:53 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[latex]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1141</guid>
		<description><![CDATA[After a video demostrating the use of Python inside a Tex document. I decided to do a document explaining how to use,  check it:
Embed Python Inside Latex (pdf ~ 100KB)

Update: I also published online through Scribd, check here.

]]></description>
			<content:encoded><![CDATA[<p>After a <a href="http://www.youtube.com/watch?v=e0SSxA1xbaA" target="_blank">video</a> demostrating the use of Python inside a Tex document. I decided to do a document explaining how to use,  check it:</p>
<p style="text-align: center;"><a href="http://www.coding.com.br/wp-content/uploads/2010/07/embed_python_latex.pdf">Embed Python Inside Latex</a> (<em>pdf</em> ~ <em>100KB</em>)</p>
<p style="text-align: center;">
<p style="text-align: left;"><span style="color: #ff0000;">Update:</span> I also published online through Scribd, check <a href="http://www.scribd.com/doc/34332481/Embed-Python-Latex" target="_blank">here</a>.</p>
<p style="padding-left: 30px;">
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/linux/embed-python-inside-latex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Opcode stats</title>
		<link>http://www.coding.com.br/embarcado/opcode-stats/</link>
		<comments>http://www.coding.com.br/embarcado/opcode-stats/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 00:09:50 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[embarcado]]></category>
		<category><![CDATA[arm]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[x86]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1128</guid>
		<description><![CDATA[I was trying some GCC options and decided see how they affect assembly code generated. I&#8217;ve created a simple Python script that parses .s output and put in a human readable way. Suppose the classical Hello World program. The output will be something like:
$ python stats_opcodes.py file
For Cortex-m3 (check previous post):

At my laptop (x86):

 

Download the script here.
]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">I was trying some GCC options and decided see how they affect assembly code generated. I&#8217;ve created a simple Python script that parses <em>.s</em> output and put in a human readable way. Suppose the classical <em>Hello World </em>program. The output will be something like:</p>
<p style="padding-left: 30px;">$ python stats_opcodes.py file</p>
<p>For Cortex-m3 (check <a href="http://www.coding.com.br/embarcado/cortex-m3-and-qemu/" target="_blank">previous</a> post):</p>
<p style="padding-left: 30px;"><img class="aligncenter size-full wp-image-1136" title="opcode-arm" src="http://www.coding.com.br/wp-content/uploads/2010/06/opcode-arm.png" alt="" width="304" height="194" /></p>
<p>At my laptop (x86):</p>
<p style="padding-left: 30px;"><img class="aligncenter size-full wp-image-1133" title="output" src="http://www.coding.com.br/wp-content/uploads/2010/06/opcodes1.png" alt="" width="306" height="194" /></p>
<p><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; font-size: small;"><span style="line-height: 18px; white-space: pre;"><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: small;"><span style="line-height: 19px; white-space: normal;"> </span></span></span></span></p>
<p style="text-align: center;">
<p>Download the script <a href="http://gist.github.com/raw/452170/db097f735c52ffd733d2060603c203982d53b79f/stats_opcode.py" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/embarcado/opcode-stats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cortex-M3 and Qemu</title>
		<link>http://www.coding.com.br/embarcado/cortex-m3-and-qemu/</link>
		<comments>http://www.coding.com.br/embarcado/cortex-m3-and-qemu/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 15:08:10 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[embarcado]]></category>
		<category><![CDATA[arm]]></category>
		<category><![CDATA[cortex-m3]]></category>
		<category><![CDATA[qemu]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1115</guid>
		<description><![CDATA[Just a small tip to test code generated for ARM Cortex-M3 using QEmu:
$ arm-none-eabi-gcc main.c -ggdb -mcpu=cortex-m3 -mthumb -T generic-m-hosted.ld
$ qemu-arm -cpu cortex-m3 ./a.out
You can download Code Sourcery toolchain here and QEmu here (also available from package management system of your favorite Linux distribution). Just unpack the toolchain associating the arm-201XqX/bin with your $PATH and run qemu.
]]></description>
			<content:encoded><![CDATA[<p>Just a small tip to test code generated for ARM Cortex-M3 using QEmu:</p>
<p><span style="color: #2040a0;">$ arm</span><span style="color: #4444ff;">-</span><span style="color: #2040a0;">none</span><span style="color: #4444ff;">-</span><span style="color: #2040a0;">eabi</span><span style="color: #4444ff;">-</span><span style="color: #2040a0;">gcc</span> <span style="color: #2040a0;">main</span>.<span style="color: #2040a0;">c</span> <span style="color: #4444ff;">-</span><span style="color: #2040a0;">ggdb</span> <span style="color: #4444ff;">-</span><span style="color: #2040a0;">mcpu</span><span style="color: #4444ff;">=</span><span style="color: #2040a0;">cortex</span><span style="color: #4444ff;">-</span><span style="color: #2040a0;">m3</span> <span style="color: #4444ff;">-</span><span style="color: #2040a0;">mthumb</span> <span style="color: #4444ff;">-</span><span style="color: #2040a0;">T</span> <span style="color: #2040a0;">generic</span><span style="color: #4444ff;">-</span><span style="color: #2040a0;">m</span><span style="color: #4444ff;">-</span><span style="color: #2040a0;">hosted</span>.<span style="color: #2040a0;">ld</span><br />
<span style="color: #2040a0;">$ qemu</span><span style="color: #4444ff;">-</span><span style="color: #2040a0;">arm</span> <span style="color: #4444ff;">-</span><span style="color: #2040a0;">cpu</span> <span style="color: #2040a0;">cortex</span><span style="color: #4444ff;">-</span><span style="color: #2040a0;">m3</span> ./<span style="color: #2040a0;">a</span>.<span style="color: #2040a0;">out</span></p>
<p style="text-align: justify;">You can download Code Sourcery toolchain <a href="http://www.codesourcery.com/sgpp/lite/arm/portal/release1294" target="_blank">here</a> and QEmu <a href="http://wiki.qemu.org/Download" target="_blank">here</a> (also available from package management system of your favorite Linux distribution). Just unpack the toolchain associating the arm-201XqX/bin with your $PATH and run qemu.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/embarcado/cortex-m3-and-qemu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx rewrite for Wikka Wiki</title>
		<link>http://www.coding.com.br/blog/nginx-rewrite-for-wikka-wiki/</link>
		<comments>http://www.coding.com.br/blog/nginx-rewrite-for-wikka-wiki/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 17:24:37 +0000</pubDate>
		<dc:creator>Celso Fernandes</dc:creator>
				<category><![CDATA[blog]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1104</guid>
		<description><![CDATA[I&#8217;m posting it here, because I started a few weeks ago working with Nginx (if you don&#8217;t know that, you really should), a very powerful and fast webserver (lets leave it for another post), but I faced a problem with redirects for Wikka Wiki, I&#8217;m not a beginner on regular expressions or mod_rewrite, but sometimes [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m posting it here, because I started a few weeks ago working with <a title="Nginx" href="http://nginx.org/" target="_blank">Nginx</a> (if you don&#8217;t know that, you really should), a very powerful and <strong>fast</strong> webserver (lets leave it for another post), but I faced a problem with redirects for Wikka Wiki, I&#8217;m not a beginner on regular expressions or mod_rewrite, but sometimes we get in trouble working on something new.</p>
<p>I haven&#8217;t found the solution for my problem (for wordpress, drupal and joomla there are so many) so I resolved it and now I&#8217;m posting if somebody can&#8217;t do it or just wanna some copy/paste <img src='http://www.coding.com.br/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"> location ~ <span style="color: #339933;">^/</span>wiki <span style="color: #009900;">&#123;</span>
 	root <span style="color: #339933;">/</span>path<span style="color: #339933;">/</span>to<span style="color: #339933;">/</span>wiki<span style="color: #339933;">;</span>
 	index wikka.<span style="color: #202020;">php</span><span style="color: #339933;">;</span>
&nbsp;
 	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!-</span>e $request_filename<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 		rewrite <span style="color: #339933;">^/</span>wiki<span style="color: #339933;">/</span>images<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>.<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>$ <span style="color: #339933;">/</span>images<span style="color: #339933;">/</span>$<span style="color: #0000dd;">1</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
		rewrite <span style="color: #339933;">^/</span>wiki<span style="color: #339933;">/</span>templates<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>.<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>$ <span style="color: #339933;">/</span>templates<span style="color: #339933;">/</span>$<span style="color: #0000dd;">1</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
 		rewrite <span style="color: #339933;">^/</span>wiki<span style="color: #339933;">/</span>3rdparty<span style="color: #339933;">/</span>plugins<span style="color: #339933;">/</span>freemind<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>.<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>$ <span style="color: #339933;">/</span>3rdparty<span style="color: #339933;">/</span>plugins<span style="color: #339933;">/</span>freemind<span style="color: #339933;">/</span>$<span style="color: #0000dd;">1</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
 		rewrite <span style="color: #339933;">^/</span>wiki<span style="color: #339933;">/</span>3rdparty<span style="color: #339933;">/</span>plugins<span style="color: #339933;">/</span>wikkaedit<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>.<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>$ <span style="color: #339933;">/</span>3rdparty<span style="color: #339933;">/</span>plugins<span style="color: #339933;">/</span>wikkaedit<span style="color: #339933;">/</span>$<span style="color: #0000dd;">1</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
 		rewrite <span style="color: #339933;">^/</span>wiki<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>.<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>$ <span style="color: #339933;">/</span>wiki<span style="color: #339933;">/</span>wikka.<span style="color: #202020;">php</span><span style="color: #339933;">?</span>wakka<span style="color: #339933;">=</span>$<span style="color: #0000dd;">1</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
 		<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
 	<span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>A brief explanation:</p>
<p>on line 1 we setup where our wiki is located, on our case /wiki, so in line 2 we give full path to where the wiki&#8217;s file are located on the filesystem and line 3 we says our index will be wikka.php once Wikka Wiki just redirect index.php to wikka.php (ok I don&#8217;t mind why they don&#8217;t put the contents of wikka.php on index.php and its over <img src='http://www.coding.com.br/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ).</p>
<p>line 5-12 we configure the rewrite rules, on line 5 is the condition what to do when there is no file or symbolic link when a URL is acessed, if its matched the following rules are processed:<br />
line 6-10: rules to ensure that static content like css, js and images won&#8217;t be redirected to wikka.php.<br />
line 11: the main rule, that will redirect all URLs to wikka.php so it process and show the output for each wiki page.</p>
<p>I don&#8217;t why (I&#8217;m new to Nginx) even using the condition <strong>if(!-e $request_filename)</strong> I need to put the rules to ensure that static content will be reached, if I discover, I update this post, but these rules are working for me under Nginx 0.7.67 and Wikka 1.2-p1 </p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/blog/nginx-rewrite-for-wikka-wiki/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Licenças para módulos no Linux</title>
		<link>http://www.coding.com.br/kernel/licencas-para-modulos-no-linux/</link>
		<comments>http://www.coding.com.br/kernel/licencas-para-modulos-no-linux/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 03:29:29 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[kernel]]></category>
		<category><![CDATA[gpl]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1083</guid>
		<description><![CDATA[O arquivo /usr/src/linux/include/linux/module.h define as licenças aceitáveis para um módulo (ou driver) seja reconhecido como software livre.

GPL - GNU Public License v2 or later
GPL v2 - GNU Public License v2
GPL and additional rights - GNU Public License v2 rights and more
Dual BSD/GPL - GNU Public License v2  or BSD license choice
Dual MIT/GPL - GNU Public License v2 or MIT license choice
Dual MPL/GPL [...]]]></description>
			<content:encoded><![CDATA[<p>O arquivo <em>/usr/src/linux/include/linux/module.h</em> define as licenças aceitáveis para um módulo (ou <em>driver</em>) seja reconhecido como software livre.</p>
<ul>
<li><strong>GPL</strong> - <em>GNU Public License v2 or later</em></li>
<li><strong>GPL v2</strong> - <em>GNU Public License v2</em></li>
<li><strong>GPL and additional rights</strong> - <em>GNU Public License v2 rights and more</em></li>
<li><strong>Dual BSD/GPL</strong> - <em>GNU Public License v2  or BSD license choice</em></li>
<li><strong>Dual MIT/GPL</strong> - <em>GNU Public License v2 or MIT license choice</em></li>
<li><strong>Dual MPL/GPL</strong> -<em> GNU Public License v2 or Mozilla license choice</em></li>
</ul>
<div id="_mcePaste">Também há um espaço (infelizmente) para licenças proprietárias:</div>
<div>
<ul>
<li><strong>Proprietary <em>- </em></strong><em>Non free products<br />
</em></li>
</ul>
</div>
<p>Como vocês podem notar, há componentes que podem ser definidos com licenças duplas, contudo quando executado no Linux apenas a GPL é relevante. Algumas razões para definir a licença:</p>
<ol>
<li><span id="result_box" class="short_text"><span>O </span><em>modinfo</em><span> pode  mostrar informações para usuários que desejam avaliar as licenças dos módulos sua instalação.</span></span></li>
<li><span id="result_box" class="short_text"><span><span id="result_box" class="short_text">A comunidade  pode ignorar relatórios de <em>bugs</em> dos módulos proprietários.</span></span></span></li>
<li><span id="result_box" class="short_text"><span><span id="result_box" class="short_text">Os fabricantes podem fazer o mesmo com suas próprias políticas.</span></span></span></li>
</ol>
<p>Para inserir a licença, basta colocar no seu código-fonte a macro  &#8221;MODULE_LICENCE&#8221;. Exemplo:</p>
<pre>  MODULE_LICENCE("GPL");</pre>
<p>Lembre-se que alguns recursos do <em>kernel</em> são disponíveis apenas se seu código é livre.</p>
<p>Um exemplo é o <strong>sysfs</strong> (através da macro EXPORT_SYMBOL_GPL) que por questões de manutenção e consistência exige que você licencie seu módulo em alguma licença compatível com a GPL.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/kernel/licencas-para-modulos-no-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NFS errors</title>
		<link>http://www.coding.com.br/embarcado/nfs-errors/</link>
		<comments>http://www.coding.com.br/embarcado/nfs-errors/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 20:04:36 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[embarcado]]></category>
		<category><![CDATA[nfs]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1061</guid>
		<description><![CDATA[If you use NFS to mount your root filesystem you should probably faced with this problem:
Root-NFS: Unable to get mountd port number from server, using default
Root-NFS: Server returned error -5 while mounting /my/nfs/server/path/
VFS: Unable to mount root fs via NFS, trying floppy.
The -5 and -13 are the most common on my daily usage, but I [...]]]></description>
			<content:encoded><![CDATA[<p>If you use NFS to mount your root filesystem you should probably faced with this problem:</p>
<blockquote><p>Root-NFS: Unable to get mountd port number from server, using default<br />
Root-NFS: Server returned error -5 while mounting /my/nfs/server/path/<br />
VFS: Unable to mount root fs via NFS, trying floppy.</p></blockquote>
<p style="text-align: justify;">The <strong>-5 </strong>and<strong> -13 </strong>are the most common on my daily usage, but I always forgot what this number means&#8230; So, I decided to get it from source by checking <em>nfs-utils </em>package. The following values where extracted  from <em>utils/mount/error.c</em>.</p>
<pre>EPERM  ........................................ -1

ENOENT ........................................ -2

EIO ........................................... -3

ENXIO ......................................... -4

<strong>EACCESS ....................................... -5 </strong>

EEXIST ........................................ -6

ENODEV ........................................ -7

ENOTDIR ....................................... -8

EISDIR ........................................ -9

EINVAL ........................................ -10

EFBIG ......................................... -11

ENOSPC  ....................................... -12

<strong>EROFS ......................................... -13</strong>

ENAMETOOLONG .................................. -14

ENOTEMPTY ..................................... -15

EDQUOT ........................................ -16

ESTALE ........................................ -17

EWFLUSH ....................................... -18
</pre>
<p>Knowing what each error status means allow you quick fix the problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/embarcado/nfs-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>idéia inspiradas por applescript, kde e d-bus</title>
		<link>http://www.coding.com.br/usabilidade/ideia-inspiradas-por-applescript-kde-e-d-bus/</link>
		<comments>http://www.coding.com.br/usabilidade/ideia-inspiradas-por-applescript-kde-e-d-bus/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 23:32:19 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[usabilidade]]></category>
		<category><![CDATA[apple script]]></category>
		<category><![CDATA[dbus]]></category>
		<category><![CDATA[kde]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1033</guid>
		<description><![CDATA[Tudo começou numa tentativa que fiz para automatizar uma tarefa - reiniciar o AirPort no MacOSX - em 10 minutos no Google consegui as informações necessárias para fazer um script na linguagem AppleScript. Isso me fez pensar em algumas coisas sobre a interatividade que obtemos nos ambientes atuais e as possibilidades nos ambientes livres. 

Veja um exemplo [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><em>Tudo começou numa tentativa que fiz para automatizar uma tarefa - reiniciar o AirPort no MacOSX - em 10 minutos no Google consegui as informações necessárias para fazer um script na linguagem AppleScript. Isso me fez pensar em algumas coisas sobre a interatividade que obtemos nos ambientes atuais e as possibilidades nos ambientes livres. </em></p>
<p style="text-align: justify;">
<p style="text-align: justify;">Veja um exemplo feito no <em><a href="http://developer.apple.com/applescript/" target="_blank">AppleScript</a></em> simples para mostrar a janela com as preferências de rede (<em>System Preferences -&gt; Network</em>).</p>
<h5>Nota: (1) se o você for testar e seu sistema estiver em Português, lembre-se de traduzir os nomes entre aspas.  (2) Para rodar os scripts é preciso marcar a opção <em>Enable access for assistive Devices em System Preferences -&gt; Universal Access</em></h5>

<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;System Preferences&quot;</span>
	<span style="color: #0066ff;">activate</span>
	<span style="color: #ff0033; font-weight: bold;">set</span> current pane <span style="color: #ff0033; font-weight: bold;">to</span> pane <span style="color: #009900;">&quot;com.apple.preference.network&quot;</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span></pre></div></div>

<p>Para desligar/ligar o AirPort:</p>

<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;System Events&quot;</span>
	<span style="color: #ff0033; font-weight: bold;">tell</span> process <span style="color: #009900;">&quot;System Preferences&quot;</span>
		<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">window</span> <span style="color: #009900;">&quot;Network&quot;</span>
			<span style="color: #ff0033; font-weight: bold;">tell</span> group <span style="color: #000000;">1</span>
				<span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">exists</span> button <span style="color: #009900;">&quot;Turn Airport Off&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
					click button <span style="color: #009900;">&quot;Turn AirPort Off&quot;</span>
					delay <span style="color: #000000;">3</span>
				<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
				<span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">exists</span> button <span style="color: #009900;">&quot;Turn Airport On&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
					click button <span style="color: #009900;">&quot;Turn AirPort On&quot;</span>
				<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
			<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
		<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
	<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span></pre></div></div>

<p style="text-align: justify;">Veja que é uma tradução em palavras (praticamente verbos no imperativo) do que seria o processo feito no modo gráfico. Se você programa em Python, existe um <a href="http://aurelio.net/doc/as4pp.html" target="_blank">comparativo</a>.</p>
<p style="text-align: justify;"><strong>Ambientes livres</strong></p>
<p style="text-align: justify;">E é justamente com Python que vejo uma alternativa interessante para controlar as aplicações como o <em>System Settings. <span style="font-style: normal;">Talvez o jeito mais fácil de fazer isso seria através de uma comunicação IPC como o <a href="http://techbase.kde.org/Development/Tutorials/D-Bus/Introduction" target="_blank">D-BUS</a> . Inclusive o system settings é exportado em</span> org.kde.systemsettings<span style="font-style: normal;">.</span></em></p>
<pre>$ qdbus org.kde.systemsettings</pre>
<p style="text-align: justify;">Resumindo, o acesso pode<strong> não</strong> ser tão fácil quanto no <em>AppleScript </em>mas o &#8220;meio&#8221; já existe em ambiente gráficos tal como KDE e  GNOME. O Python lida muito bem com este tipo de comunicação e é uma saída para quem está procurando um jeito para controlar seu ambiente de forma automatizada.</p>
<p style="text-align: justify;"><strong>Futuro</strong></p>
<p style="text-align: justify;">Na minha opinião há uma deficiência para (A) pessoas leigas, se quiserem, controlar seus aplicativos de forma automatizada e (B) melhorar as formas de usabilidade nas interfaces <strong>já</strong> existentes.</p>
<p style="text-align: justify;">Fico imaginando se não seria interessante um investimento (e pesquisa) para criar linguagens de programação que herdem construções da &#8220;fala&#8221; para acessar aplicativos, para no futuro utilizar da &#8220;voz&#8221; humana para controlar o computador.</p>
<p>O software livre é um terreno vasto para esse tipo de experiência. Cito algumas tecnologias que tornaria isso possível:</p>
<ul>
<li><a href="http://dbus.freedesktop.org" target="_blank">D-bus</a> para comunicação entre os aplicativos</li>
<li><a href="http://www.python.org" target="_blank">Python</a> como linguagem de programação para construir as &#8220;amarras&#8221;</li>
<li><a href="http://www.nltk.org" target="_blank">NTLK </a> (<em>N</em><em>atural Language Toolkit</em>) para processar a linguagem</li>
</ul>
<p>Se você trabalhar com algum tipo de pesquisa na área ou tem experiência, por favor, deixe um comentário.</p>
<p>Bom começo de semana a todos.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/usabilidade/ideia-inspiradas-por-applescript-kde-e-d-bus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Básico de passagem de parâmetros em C++</title>
		<link>http://www.coding.com.br/unifei/basico-de-passagem-de-parametros-em-c/</link>
		<comments>http://www.coding.com.br/unifei/basico-de-passagem-de-parametros-em-c/#comments</comments>
		<pubDate>Mon, 31 May 2010 04:15:15 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[unifei]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1021</guid>
		<description><![CDATA[para não acontecer certos erros que vi por aí&#8230;
Em C++ há três maneiras de passar um parâmetro para uma função, as tradicionais herdadas da linguagem C: valor e ponteiro; além da novidade: a passagem por referência. Para ilustrar veja o seguinte exemplo, passar uma estrutura de dados &#8220;grande&#8221; (neste caso aproximadamente 10 kilobytes) para uma [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: right;"><em>para não acontecer certos erros que vi por aí&#8230;</em></p>
<p>Em C++ há <strong>três</strong> maneiras de passar um parâmetro para uma função, as tradicionais herdadas da linguagem C: <em>valor </em>e <em>ponteiro</em>; além da novidade: a passagem por <em>referência. </em>Para ilustrar veja o seguinte exemplo, passar uma estrutura de dados &#8220;grande&#8221; (neste caso aproximadamente 10 kilobytes) para uma função:</p>
<p><span style="color: #0000ff;"><strong>#include<span style="color: #008000;">&lt;iostream&gt;</span></strong></span><br />
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;string.h&gt;</span> </strong></span></p>
<p><strong>using</strong> <strong>namespace</strong> <span style="color: #2040a0;">std</span><span style="color: #4444ff;">;</span></p>
<p><strong>struct</strong> <span style="color: #2040a0;">Big</span> <span style="color: #4444ff;"><strong>{</strong></span><br />
<strong> char</strong> <span style="color: #2040a0;">text</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">10000</span><span style="color: #4444ff;">]</span><span style="color: #4444ff;">;</span><br />
<strong> int</strong> <span style="color: #2040a0;">id</span><span style="color: #4444ff;">;</span><br />
<span style="color: #4444ff;"><strong>}</strong></span><span style="color: #4444ff;">;</span></p>
<p><strong>void</strong> <span style="color: #2040a0;">f1</span><span style="color: #4444ff;">(</span> <span style="color: #2040a0;">Big</span> <span style="color: #2040a0;">v</span> <span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span><br />
<span style="color: #2040a0;"> cout</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #2040a0;">v</span>.<span style="color: #2040a0;">text</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #2040a0;">endl</span><span style="color: #4444ff;">;</span><br />
<span style="color: #2040a0;"> cout</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #008000;">&#8220;Ox&#8221;</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #2040a0;">hex</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #2040a0;">v</span>.<span style="color: #2040a0;">id</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #2040a0;">endl</span><span style="color: #4444ff;">;</span><br />
<span style="color: #4444ff;"><strong>}</strong></span></p>
<p><strong>void</strong> <span style="color: #2040a0;">f2</span><span style="color: #4444ff;">(</span> <strong>const</strong> <span style="color: #2040a0;">Big</span> <span style="color: #4444ff;">*</span><span style="color: #2040a0;">v</span> <span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span><br />
<span style="color: #2040a0;"> cout</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #2040a0;">v</span><span style="color: #4444ff;">-</span><span style="color: #4444ff;">&gt;</span><span style="color: #2040a0;">text</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #2040a0;">endl</span><span style="color: #4444ff;">;</span><br />
<span style="color: #2040a0;"> cout</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #008000;">&#8220;Ox&#8221;</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #2040a0;">hex</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #2040a0;">v</span><span style="color: #4444ff;">-</span><span style="color: #4444ff;">&gt;</span><span style="color: #2040a0;">id</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #2040a0;">endl</span><span style="color: #4444ff;">;</span><br />
<span style="color: #4444ff;"><strong>}</strong></span></p>
<p><strong>void</strong> <span style="color: #2040a0;">f3</span><span style="color: #4444ff;">(</span> <strong>const</strong> <span style="color: #2040a0;">Big</span> <span style="color: #4444ff;">&amp;</span><span style="color: #2040a0;">v</span> <span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span><br />
<span style="color: #2040a0;"> cout</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #2040a0;">v</span>.<span style="color: #2040a0;">text</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #2040a0;">endl</span><span style="color: #4444ff;">;</span><br />
<span style="color: #2040a0;"> cout</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #008000;">&#8220;Ox&#8221;</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #2040a0;">hex</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #2040a0;">v</span>.<span style="color: #2040a0;">id</span> <span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span> <span style="color: #2040a0;">endl</span><span style="color: #4444ff;">;</span><br />
<span style="color: #4444ff;"><strong>}</strong></span></p>
<p><strong>int</strong> <span style="color: #2040a0;">main</span><span style="color: #4444ff;">(</span><strong>int</strong> <span style="color: #444444;">/*argc*/</span>, <strong>char</strong> <span style="color: #4444ff;">*</span> <span style="color: #444444;">/*argv*/</span><span style="color: #4444ff;">[</span><span style="color: #4444ff;">]</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span></p>
<p><span style="color: #2040a0;"> Big</span> <span style="color: #4444ff;">*</span><span style="color: #2040a0;">b0</span> <span style="color: #4444ff;">=</span> <strong>new</strong> <span style="color: #2040a0;">Big</span><span style="color: #4444ff;">;</span><br />
<span style="color: #2040a0;"> Big</span> <span style="color: #2040a0;">b1</span><span style="color: #4444ff;">;</span><br />
<span style="color: #2040a0;"> Big</span> <span style="color: #4444ff;">&amp;</span><span style="color: #2040a0;">b2</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">b1</span><span style="color: #4444ff;">;</span></p>
<p><span style="color: #2040a0;"> strcpy</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">b0</span><span style="color: #4444ff;">-</span><span style="color: #4444ff;">&gt;</span><span style="color: #2040a0;">text</span>,<span style="color: #008000;">&#8220;asdfg asdfg asdf asdf asdf asdf&#8221;</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span><br />
<span style="color: #2040a0;"> strcpy</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">b1</span>.<span style="color: #2040a0;">text</span>,<span style="color: #008000;">&#8220;azsxd azsxd azsxd azsxd azsxd azsxd&#8221;</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span></p>
<p><span style="color: #2040a0;"> b0</span><span style="color: #4444ff;">-</span><span style="color: #4444ff;">&gt;</span><span style="color: #2040a0;">id</span> <span style="color: #4444ff;">=</span> <span style="color: #ff0000;">0xbc</span><span style="color: #4444ff;">;</span><br />
<span style="color: #2040a0;"> b1</span>.<span style="color: #2040a0;">id</span> <span style="color: #4444ff;">=</span> <span style="color: #ff0000;">0xde</span><span style="color: #4444ff;">;</span></p>
<p><span style="color: #2040a0;"> f2</span><span style="color: #4444ff;">(</span> <span style="color: #2040a0;">b0</span> <span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span> <span style="color: #444444;">/* pointer */</span><br />
<span style="color: #2040a0;"> f1</span><span style="color: #4444ff;">(</span> <span style="color: #2040a0;">b1</span> <span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span> <span style="color: #444444;">/* value */</span><br />
<span style="color: #2040a0;"> f3</span><span style="color: #4444ff;">(</span> <span style="color: #2040a0;">b2</span> <span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span> <span style="color: #444444;">/* reference */</span><br />
<span style="color: #4444ff;"><strong>}</strong></span></p>
<p><span style="color: #4444ff;"><strong><br />
</strong></span></p>
<p>Veja o código <em>assembly</em> gerado pelo compilador (g++) para cada um dos três casos:</p>
<p><strong>1) Ponteiro</strong></p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #00007f; font-weight: bold;">mov</span>    <span style="color: #339933;">-</span><span style="color: #0000ff;">0xc</span><span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #339933;">%</span><span style="color: #00007f;">ebp</span><span style="color: #009900; font-weight: bold;">&#41;</span><span style="color: #339933;">,%</span><span style="color: #00007f;">eax</span>
<span style="color: #00007f; font-weight: bold;">mov</span>    <span style="color: #339933;">%</span><span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #339933;">%</span><span style="color: #00007f;">esp</span><span style="color: #009900; font-weight: bold;">&#41;</span>
<span style="color: #00007f; font-weight: bold;">call</span>   <span style="color: #0000ff;">0x8048885</span></pre></div></div>

<p><strong>2) Valor</strong></p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;">movl   $<span style="color: #0000ff;">0x0</span><span style="color: #339933;">,-</span><span style="color: #0000ff;">0x2728</span><span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #339933;">%</span><span style="color: #00007f;">ebp</span><span style="color: #009900; font-weight: bold;">&#41;</span>
<span style="color: #00007f; font-weight: bold;">lea</span>    <span style="color: #339933;">-</span><span style="color: #0000ff;">0x2720</span><span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #339933;">%</span><span style="color: #00007f;">ebp</span><span style="color: #009900; font-weight: bold;">&#41;</span><span style="color: #339933;">,%</span><span style="color: #00007f;">eax</span>
<span style="color: #00007f; font-weight: bold;">mov</span>    <span style="color: #339933;">%</span><span style="color: #00007f;">eax</span><span style="color: #339933;">,-</span><span style="color: #0000ff;">0x272c</span><span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #339933;">%</span><span style="color: #00007f;">ebp</span><span style="color: #009900; font-weight: bold;">&#41;</span>
<span style="color: #00007f; font-weight: bold;">jmp</span>    <span style="color: #0000ff;">0x8048a36</span>
<span style="color: #00007f; font-weight: bold;">mov</span>    <span style="color: #339933;">-</span><span style="color: #0000ff;">0x272c</span><span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #339933;">%</span><span style="color: #00007f;">ebp</span><span style="color: #009900; font-weight: bold;">&#41;</span><span style="color: #339933;">,%</span><span style="color: #00007f;">ecx</span>
<span style="color: #00007f; font-weight: bold;">mov</span>    <span style="color: #339933;">-</span><span style="color: #0000ff;">0x2728</span><span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #339933;">%</span><span style="color: #00007f;">ebp</span><span style="color: #009900; font-weight: bold;">&#41;</span><span style="color: #339933;">,%</span><span style="color: #00007f;">edx</span>
movzbl <span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #339933;">%</span><span style="color: #00007f;">ecx</span><span style="color: #339933;">,%</span><span style="color: #00007f;">edx</span><span style="color: #339933;">,</span><span style="color: #0000ff;">1</span><span style="color: #009900; font-weight: bold;">&#41;</span><span style="color: #339933;">,%</span><span style="color: #00007f;">eax</span>
<span style="color: #00007f; font-weight: bold;">mov</span>    <span style="color: #339933;">-</span><span style="color: #0000ff;">0x2728</span><span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #339933;">%</span><span style="color: #00007f;">ebp</span><span style="color: #009900; font-weight: bold;">&#41;</span><span style="color: #339933;">,%</span><span style="color: #00007f;">edx</span>
<span style="color: #00007f; font-weight: bold;">mov</span>    <span style="color: #339933;">%</span><span style="color: #00007f;">al</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #339933;">%</span><span style="color: #00007f;">esp</span><span style="color: #339933;">,%</span><span style="color: #00007f;">edx</span><span style="color: #339933;">,</span><span style="color: #0000ff;">1</span><span style="color: #009900; font-weight: bold;">&#41;</span>
addl   $<span style="color: #0000ff;">0x1</span><span style="color: #339933;">,-</span><span style="color: #0000ff;">0x2728</span><span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #339933;">%</span><span style="color: #00007f;">ebp</span><span style="color: #009900; font-weight: bold;">&#41;</span>
cmpl   $<span style="color: #0000ff;">0x2714</span><span style="color: #339933;">,-</span><span style="color: #0000ff;">0x2728</span><span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #339933;">%</span><span style="color: #00007f;">ebp</span><span style="color: #009900; font-weight: bold;">&#41;</span>
<span style="color: #00007f; font-weight: bold;">jb</span>     <span style="color: #0000ff;">0x8048a16</span>
<span style="color: #00007f; font-weight: bold;">call</span>   <span style="color: #0000ff;">0x80488fe</span></pre></div></div>

<p><strong>3) Referência</strong></p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #00007f; font-weight: bold;">mov</span>    <span style="color: #339933;">-</span><span style="color: #0000ff;">0x8</span><span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #339933;">%</span><span style="color: #00007f;">ebp</span><span style="color: #009900; font-weight: bold;">&#41;</span><span style="color: #339933;">,%</span><span style="color: #00007f;">eax</span>
<span style="color: #00007f; font-weight: bold;">mov</span>    <span style="color: #339933;">%</span><span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#40;</span><span style="color: #339933;">%</span><span style="color: #00007f;">esp</span><span style="color: #009900; font-weight: bold;">&#41;</span>
<span style="color: #00007f; font-weight: bold;">call</span>   <span style="color: #0000ff;">0x804880c</span></pre></div></div>

<p>Talvez seja importante:</p>
<ul>
<li>Se você prefere a sintaxe da intel? Mude no GDB: <em>set disassembly-flavor intel</em></li>
<li>Não precisa ser muito esperto para ver que a passagem por valor é a pior de todas, veja quanto código <em>assembly</em> foi gerado [#fail]</li>
<li>A passagem por referência é inclusive mais eficiente pois aloca no %ebp (<em>base pointer</em>) [8 bytes ao invés de 12 bytes do ponteiro].</li>
<li>A passagem por referência provê a eficiência da passagem por ponteiros com a clareza da passagem por valor.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/unifei/basico-de-passagem-de-parametros-em-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
