<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2009-12-11-a-gcd-case-study-building-an-http-server.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-12-11-a-gcd-case-study-building-an-http-server.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Sun, 10 May 2026 05:15:42 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>jtc - 2009-12-20 06:57:55</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-12-11-a-gcd-case-study-building-an-http-server.html#comments</link><description>Thank you for a very informative series on GCD.
&lt;br /&gt;
&lt;br /&gt;John</description><guid isPermaLink="true">728574f1ff308c1b300d74519d5b800c</guid><pubDate>Sun, 20 Dec 2009 06:57:55 GMT</pubDate></item><item><title>Jonathan Mitchell - 2009-12-13 20:49:09</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-12-11-a-gcd-case-study-building-an-http-server.html#comments</link><description>I agree. The clang static analyser does catch it though, detecting the undefined value that results from int x = x + 1.</description><guid isPermaLink="true">fed8b46c0c6cc5fe1ae3f238c989923b</guid><pubDate>Sun, 13 Dec 2009 20:49:09 GMT</pubDate></item><item><title>mikeash - 2009-12-13 17:16:31</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-12-11-a-gcd-case-study-building-an-http-server.html#comments</link><description>That's not really what I want, though. That warns if you shadow a variable (and shadowing is sometimes useful) and doesn't warn if you misspelled something and thus &lt;i&gt;didn't&lt;/i&gt; shadow a variable, but are still using a variable in its own initializer.</description><guid isPermaLink="true">1dba5cf807802d3dc839f4be9876105b</guid><pubDate>Sun, 13 Dec 2009 17:16:31 GMT</pubDate></item><item><title>Jonathan Mitchell - 2009-12-13 11:44:37</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-12-11-a-gcd-case-study-building-an-http-server.html#comments</link><description>void Foo(int x) 
&lt;br /&gt;{ 
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(x) 
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{ 
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int x = x + 1; // use the parameter to initialize the local 
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;... 
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} 
&lt;br /&gt;} 
&lt;br /&gt;
&lt;br /&gt;GCC_WARN_SHADOW, -Wshadow will give you a warning for this, if desirable.</description><guid isPermaLink="true">3e5f30e6b39a0c45a1db2fd46a3103e0</guid><pubDate>Sun, 13 Dec 2009 11:44:37 GMT</pubDate></item><item><title>mikeash - 2009-12-12 17:42:00</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-12-11-a-gcd-case-study-building-an-http-server.html#comments</link><description>No, referring to a variable in its own initializer is perfectly legal, if frequently nonsensical. For example, I write code like this with disturbing regularity:
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;void Foo(int x)
&lt;br /&gt;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(x)
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int x = x + 1; // use the parameter to initialize the local
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;...
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&lt;br /&gt;}&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;It's legal, builds fine, and doesn't even produce any warnings. But the &lt;code&gt;x&lt;/code&gt; that's used in the initializer is not the parameter, it is the local variable, and thus the variable is effectively uninitialized even though there is an initializer.
&lt;br /&gt;
&lt;br /&gt;And in fact, gcc is perfectly happy to have a block refer to itself, too:
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;void Bar(void)
&lt;br /&gt;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void (^block)(void) = ^{ block(); };
&lt;br /&gt;}&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;This compiles fine, no warnings.
&lt;br /&gt;
&lt;br /&gt;It also doesn't work as expected, because it captures the value of &lt;code&gt;block&lt;/code&gt; from &lt;i&gt;before&lt;/i&gt; the initializer occurs, thus capturing a junk value. To work around that problem, you can qualify the variable with &lt;code&gt;__block&lt;/code&gt;, which causes the block to track changes to the variable. Works fine, except that if you initialize the block on the same line rather than on a separate line, gcc throws these bizarre errors:
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;test.m: In function ‘__Bar_block_invoke_1’:
&lt;br /&gt;test.m:16: error: request for member ‘__forwarding’ in something not a structure or union
&lt;br /&gt;test.m: In function ‘Bar’:
&lt;br /&gt;test.m:16: error: invalid type argument of ‘unary *’&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;Clang handles it fine, and there's nothing wrong with the code. It's just a gcc bug.</description><guid isPermaLink="true">f4ed88d34cfa23784e5f031c69e258cf</guid><pubDate>Sat, 12 Dec 2009 17:42:00 GMT</pubDate></item><item><title>Gwynne Raskind - 2009-12-12 10:26:50</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-12-11-a-gcd-case-study-building-an-http-server.html#comments</link><description>&lt;code&gt;__block dispatch_source_t source; // gcc won't compile if the next line is an initializer?!&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;This is because you refer to source itself within the block, which you can't do in the variable's initializer because the initializer is evaluated before the declaration within the compiler; in essence, GCC doesn't know that the variable exists yet. Whether that behavior conforms to C90 or C99, I don't know.</description><guid isPermaLink="true">316d782e5a22412c8f0f03e98dcc6a0f</guid><pubDate>Sat, 12 Dec 2009 10:26:50 GMT</pubDate></item><item><title>JulesLt - 2009-12-12 08:48:14</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-12-11-a-gcd-case-study-building-an-http-server.html#comments</link><description>Damn you - I'm intrigued to know how a fully developed GCD based HTTP server would benchmark against Apache now!
&lt;br /&gt;
&lt;br /&gt;</description><guid isPermaLink="true">89695ece41f45d8259e3426caf7af428</guid><pubDate>Sat, 12 Dec 2009 08:48:14 GMT</pubDate></item></channel></rss>
