<?xml version='1.0' encoding='utf-8' ?>
<!--  If you are running a bot please visit this policy page outlining rules you must respect. http://www.livejournal.com/bots/  -->
<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/' xmlns:media='http://search.yahoo.com/mrss/' xmlns:atom10='http://www.w3.org/2005/Atom'>
<channel>
  <title>Informal Methods</title>
  <link>http://ahefner.livejournal.com/</link>
  <description>Informal Methods - LiveJournal.com</description>
  <lastBuildDate>Thu, 02 Apr 2009 20:09:05 GMT</lastBuildDate>
  <generator>LiveJournal / LiveJournal.com</generator>
  <lj:journal>ahefner</lj:journal>
  <lj:journalid>14248520</lj:journalid>
  <lj:journaltype>personal</lj:journaltype>
  <image>
    <url>http://l-userpic.livejournal.com/71615828/14248520</url>
    <title>Informal Methods</title>
    <link>http://ahefner.livejournal.com/</link>
    <width>100</width>
    <height>100</height>
  </image>

<item>
  <guid isPermaLink='true'>http://ahefner.livejournal.com/13588.html</guid>
  <pubDate>Thu, 02 Apr 2009 20:09:05 GMT</pubDate>
  <title>Managing tasks</title>
  <link>http://ahefner.livejournal.com/13588.html</link>
  <description>&lt;p&gt;I&apos;m fiddling with some C code, experimenting with different approaches to various subtasks, some of which depend on previous tasks. Results are valid only for the duration of the current frame. Performance matters, so I tend to comment pieces I&apos;m not currently working on unless they&apos;re needed. For the time being, the data is often only displayed as debugging output, but sometimes the debug display is turned off, making the computation wasteful. Up to this point I&apos;d been juggling the dependencies manually, calling each computation in order from a central point, but finally I&apos;ve gotten restless to automate things. Here&apos;s some cute C preprocessor fun I bashed out a few minutes ago:&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;
struct task {
    char *name;
    int last_time;
    int locked;
    void (*taskfn) (void);
};

#define deftask(name) \
  void task_do_##name (void); \
  struct task name = {#name, -1, 0, task_do_##name}; \
  noinline void task_do_##name (void)

static inline void require_task (struct task *task, int time)
{
    assert(task != NULL);
    if (task-&amp;gt;last_time &amp;lt; time) {
        if (task-&amp;gt;locked) {
            fprintf(stderr, &amp;quot;Fatal: Circular dependency on task \&amp;quot;%s\&amp;quot;.\n&amp;quot;, task-&amp;gt;name);
            exit(1);
        }
        task-&amp;gt;locked = 1;
        task-&amp;gt;taskfn();
        task-&amp;gt;last_time = time;
        task-&amp;gt;locked = 0;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;I interface this with my code and the global frame_number as follows:&lt;/p&gt;&lt;br /&gt;&lt;code&gt;#define using(name) require_task(&amp;amp;name, frame_number)&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Next I define various tasks. Some depend on others:&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;deftask(track_motion)
{
    .. some code here ..
}

deftask(feature_matrix)
{
  .. more code here ..
}

deftask(grid_alignment)
{
    using(track_motion);
    .. yet more code..
}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Code elsewhere also relies on the &apos;using&apos; macro to ensure computations are up to date. The components communicate through global state. If they didn&apos;t, and the style were more functional, I supposed I&apos;d be blogging about how I&apos;d implemented memoization instead. Eventually, I might rig this up to farm the computation out to other threads (though this doesn&apos;t seem like such a huge win unless I go back to eagerly computing things in advance of needing them). I&apos;d need a parallel &apos;using&apos; operator.&lt;/p&gt;</description>
  <comments>http://ahefner.livejournal.com/13588.html</comments>
  <category>programming</category>
  <category>c</category>
  <lj:music>Frank Zappa, &quot;San Ber&apos;dino&quot;</lj:music>
  <media:title type="plain">Frank Zappa, &quot;San Ber&apos;dino&quot;</media:title>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://ahefner.livejournal.com/3897.html</guid>
  <pubDate>Sat, 26 Apr 2008 06:38:37 GMT</pubDate>
  <title>The New C Standard</title>
  <link>http://ahefner.livejournal.com/3897.html</link>
  <description>I&apos;ve just happened upon the PDF of &quot;The New C Standard: An Economic and Cultural Commentary&quot;, an unpublished book by Derek Jones, available &lt;a href=&quot;http://homepage.ntlworld.com/dmjones/cbook1_0a.pdf&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;. Although it has now been available for several years, I have unfortunately overlooked it until this evening. At 1616 pages, the breadth is staggering, and the introductory material on software development, engineering, and the author&apos;s experience nearly constitutes a book of its own. The book takes the exhaustive approach of examining each sentence of the C99 standard in sequence, providing expert commentary, comparison between language versions, and statistics gleaned from well known large C programs.&lt;br /&gt;&lt;br /&gt;This approach is of dissecting the standard is of particular interest to me, being someone who despite having programmed in C for more than ten years has had (I&apos;m ashamed to say) little or no exposure to the actual language standard, and a mental model of the language grown by accretion from hearsay, intuition, code I&apos;ve read, and the intersection of things which work in the implementations of the language I have experience with. This approach has worked reasonably well for C, but is probably quite a dangerous way to proceed in a more intricate language such as C++ (although I fear a great many programmers learn it in just that fashion). This situation has become particularly unsatisfactory when considered in contrast with Common Lisp, a language which I&apos;ve worked with equally extensively over the last five or six years, and where a direct HTML conversion of the ANSI standard (the &lt;a href=&quot;http://www.lisp.org/HyperSpec/FrontMatter/index.html&quot; rel=&quot;nofollow&quot;&gt;Common Lisp Hyperspec&lt;/a&gt;) serves comfortably as both an everyday reference and the ultimate arbiter of language semantics.&lt;br /&gt;&lt;br /&gt;In any case, the book looks interesting, and I look forward to any insights and corrections/extensions to my inferred model of the language which it can provide.</description>
  <comments>http://ahefner.livejournal.com/3897.html</comments>
  <category>c</category>
  <category>coding</category>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
</channel>
</rss>
