<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Weiqi Gao&#039;s Observations - gnu tag</title>
  <link>http://www.weiqigao.com/blog/tags/gnu/</link>
  <description>Sharing My Experience...</description>
  <language>en</language>
  <copyright>Weiqi Gao</copyright>
  <lastBuildDate>Fri, 11 May 2012 12:48:36 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  <image>
    <url>http://pebble.sourceforge.net/common/images/powered-by-pebble.gif</url>
    <title>Weiqi Gao&#039;s Observations</title>
    <link>http://www.weiqigao.com/blog/</link>
  </image>
  
  
  <item>
    <title>Friday C Quiz: Know Your Closures</title>
    <link>http://www.weiqigao.com/blog/2008/04/04/friday_c_quiz_know_your_closures.html</link>
    
      
        <description>
          &lt;p&gt;You know what?  This &lt;a href= &#034;http://www.weiqigao.com/blog/2008/02/01/friday_java_quiz_know_your_closures.html&#034; &gt;closure&lt;/a&gt; thing &lt;a href= &#034;http://www.weiqigao.com/blog/2008/03/30/closures_comes_to_c0x.html&#034; &gt;has gotten&lt;/a&gt; into &lt;a href= &#034;http://www.weiqigao.com/blog/2008/02/21/dreaming_up_syntax_for_function_types_for_bgga_closures.html&#034; &gt;my head&lt;/a&gt;.  I know it&#039;s pointless and useless to think and talk about it all the time, but I can&#039;t help it.&lt;/p&gt;

&lt;p&gt;Well, my loss is your gain.  And today&#039;s Friday quiz will take you all the way back to C.  Yes, old trusty C!  Although ANSI C does not support closures, some C compilers provide nested function extensions that provide a limited subset of closure functionalities such as accessing variables in the outer function.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Q&lt;/b&gt;: Will the following C program compile and run under your C compiler?  If so, what will it print?&lt;/p&gt;

&lt;pre style=&#034;margin:3em;background-color:blue;color:white;font-weight:bold&#034;&gt;

  #include &amp;lt;stdio.h&gt;
  
  int main() {
    int (*&lt;span style=&#034;color:red&#034;&gt;pFib&lt;/span&gt;)(int);
    int fib(int n) {
      return n == 0 ? 0 :
             n == 1 ? 1 :
             &lt;span style=&#034;color:red&#034;&gt;pFib&lt;/span&gt;(n - 1) + &lt;span style=&#034;color:red&#034;&gt;pFib&lt;/span&gt;(n - 2);
    }
    &lt;span style=&#034;color:red&#034;&gt;pFib&lt;/span&gt; = fib;
    printf(&#034;%d\n&#034;, &lt;span style=&#034;color:red&#034;&gt;pFib&lt;/span&gt;(6));
    return 0;
  }

&lt;/pre&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2008/04/04/friday_c_quiz_know_your_closures.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2008/04/04/friday_c_quiz_know_your_closures.html</guid>
    <pubDate>Fri, 04 Apr 2008 12:11:48 GMT</pubDate>
  </item>
  
  <item>
    <title>GNU grep&#039;s New Trick</title>
    <link>http://www.weiqigao.com/blog/2006/06/10/gnu_greps_new_trick.html</link>
    
      
        <description>
          &lt;p&gt;I stumbled upon this &lt;a href= &#034;&#034; &gt;Linux.com&lt;/a&gt; article: &lt;a href= &#034;http://www.linux.com/article.pl?sid=06/05/19/1920231&#034; &gt;GNU grep&#039;s new features&lt;/a&gt; about a week ago.  (No, the &lt;a href= &#034;http://www.stumbleupon.com/&#034; &gt;StumbleUpon&lt;/a&gt; Firefox plugin was not used.)  I printed it out but only got a chance reading it on Thursday.&lt;/p&gt;

&lt;p&gt;It talked about several new features in &lt;a href= &#034;http://www.gnu.org/software/grep/&#034; &gt;GNU grep&lt;/a&gt; 2.5 that&#039;s pretty neat.  I&#039;ve already used two of the features at work yesterday.  But before I go on, let me see a show of hands,  how many of you are using GNU grep 2.5?  2.4?  2.0?  Right, chances are that you don&#039;t know or much care which version of grep you are using.  I didn&#039;t know until I read the article.  (I&#039;m using GNU grep 2.5.1, which is a patch level behind the latest release.  Must download, ./configure; make; make check; make install! ...Not!  By the way, 2.5 was out in 2002&amp;mdash;four years ago.)&lt;/p&gt;

&lt;p&gt;The features I used are called &lt;tt&gt;--only-matching&lt;/tt&gt; and &lt;tt&gt;--color&lt;/tt&gt;.  The &lt;tt&gt;--only-matching&lt;/tt&gt; feature can also be specified using the &lt;tt&gt;-o&lt;/tt&gt; option on the command line and it shows only the part of a matching line that matches PATTERN.  The &lt;tt&gt;--color&lt;/tt&gt; feature will show the matching portion of the line in color (by default red).&lt;/p&gt;

&lt;p&gt;I find myself using the &lt;tt&gt;--color&lt;/tt&gt; option to experiment with the regular expressions and then using the &lt;tt&gt;-o&lt;/tt&gt; option to get the matching text for further processing:&lt;/p&gt;

&lt;pre style=&#034;margin-left:3em&#034;&gt;[weiqi@gao]$ &lt;b&gt;cat foo&lt;/b&gt;
This is a test.
[weiqi@gao]$ &lt;b&gt;grep --color test foo&lt;/b&gt;
This is a &lt;span style=&#034;color:red&#034;&gt;test&lt;/span&gt;.
[weiqi@gao]$ &lt;b&gt;grep -o test foo&lt;/b&gt;
test&lt;/pre&gt;

&lt;p&gt;For more complicated regular expressions, the color option gives a better visual feedback.&lt;/p&gt;

&lt;p&gt;Give these new options a try.&lt;/p&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2006/06/10/gnu_greps_new_trick.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2006/06/10/gnu_greps_new_trick.html</guid>
    <pubDate>Sat, 10 Jun 2006 16:23:48 GMT</pubDate>
  </item>
  
  <item>
    <title>GNU&#039;s Now Unix</title>
    <link>http://www.weiqigao.com/blog/2006/02/10/gnus_now_unix.html</link>
    
      
        <description>
          &lt;blockquote&gt;
&lt;p&gt;&lt;a href= &#034;http://www.tbray.org/ongoing/When/200x/2006/02/09/What-Does-Linux-Mean&#034; &gt;Tim Bray&lt;/a&gt;: I think Sun could legally ship something like this under the name “GNU/Unix”.  Which would be concise, descriptive, accurate, and funny.  (Because GNU stands for “Gnu’s Not Unix” and Solaris, after all, is.)&lt;/p&gt;

&lt;p&gt;I was chatting this over with &lt;a href= &#034;http://www.webmink.net/&#034; &gt;Simon Phipps&lt;/a&gt; and he suggested that GNU could stand for “Gnu’s Now Unix”.&lt;/p&gt;
&lt;/blockquote&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2006/02/10/gnus_now_unix.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2006/02/10/gnus_now_unix.html</guid>
    <pubDate>Sat, 11 Feb 2006 00:30:24 GMT</pubDate>
  </item>
  
  </channel>
</rss>

