    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: The Wall</title>
        <link>https://members.accu.org/index.php/journals/964</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>


        <h2>Journal Articles</h2>


<div class="xar-mod-head"><span class="xar-mod-title">CVu Journal Vol 12, #1 - Jan 2000 + Letters to the Editor</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c128/">121</a>
                    (30)
<br />

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c184/">Journal Columns</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c186/">LettersEditor</a>
                    (132)
<br />

                                            <a href="https://members.accu.org/index.php/journals/c128-186/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/journals/c128+186/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;The Wall</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 January 2000 13:15:34 +00:00 or Mon, 03 January 2000 13:15:34 +00:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e22" id="d0e22"></a>And Again</h2>
</div>
<p>Dear Francis,</p>
<p>There is of course more than one way to skin a cat and I thought
you might be interested in the way I would write a function to
remove dashes. In this function I have preferred pointers over
indexes:</p>
<pre class="programlisting">
char *remove_dashes(char *string) {
  char *src = string;
  char *dst = string;
  while ((*dst = *src++) != '\0')
    if (*dst != '-')
      ++dst;
  return string;
}
</pre>
<p>Although I know the test against the nul character in the while
expression is not necessary I like to use it as I think it makes it
clearer that I really did mean the assignment. In general I think
the simpler the expression the better as there is less to read and
less to misinterpret. Obviously one doesn't want to go too far and
make things cryptic! All C/C++ programmers know that zero means
false and any non-zero value means true, and I don't think that
using this fact is likely to confuse anyone. But, as I say, in this
case if I had used</p>
<pre class="programlisting">
  while (*dst = *src++)
</pre>
<p>someone might misread it as</p>
<pre class="programlisting">
  while (*dst == *src++)
</pre>
<p>hence the explicit comparison against the nul character.</p>
<p>Slight digression: another thing in this while expression that
might be worth mentioning is that it relies on the fact that the
result of an assignment is the rightmost term; in this case the
character value stored at *src, before src is post-incremented. You
can write</p>
<pre class="programlisting">
  a = b = c;
</pre>
<p>which, as assignment is right-associative, is equivalent to</p>
<pre class="programlisting">
  a = (b = c);
</pre>
<p>and in both cases the value of the rightmost term, c, will be
assigned to a and b. (This is why operator=() member functions
should return a value.)</p>
<p>Out of interest, do you know what will happen in these two
statements?</p>
<pre class="programlisting">
  a = b = c, d = e;
  a = (b = c, d = e);
</pre>
<p>In the first c is assigned to a and b, e is assigned to d. In
the second c is assigned to b, e is assigned to d and also to
a.</p>
<p>By the way, I didn't understand your version of removedashes()
at all. It didn't look to me as though it would work. Have I
misunderstood something fundamental or is this a case of a
programmer &quot;improving&quot; code and introducing a bug? (I understand
you had other things on your mind while preparing the last issue of
C Vu.) I read somewhere, I don't remember where, that programmers
are likely to introduce more bugs in small functions than in larger
functions, up to a certain size, and then the bug count rises
again. Maybe it's related to the fact that apparently more car
accidents occur within a few streets of home. Perhaps we switch to
automatic, and make mistakes. (I don't know if the statistics take
account of the fact that presumably we spend more time driving a
few streets from home than we do anywhere else.)</p>
<p>One thing about my own solution occurs to me, that it may spend
a lot of time needlessly assigning characters to themselves, until
it comes across the first dash. If this function was frequently
used for long strings one might want to investigate improving its
performance, against the cost of increasing the complexity of the
code, and the possibility of making the function very quick to get
the wrong answer.</p>
<p>You asked for an implementation of the following prototype:</p>
<p>char[] eliminate(char these[], char from[]);</p>
<p>I'm afraid my compiler, MS VC++ 6, didn't like that char[]
return type. Here is my effort:</p>
<pre class="programlisting">
char *eliminate(char these[], char from[]) {
  char *src = from;
  char *dst = from;
  while (*src){
    if (strchr(these, *src) != 0) ++src; // skip unwanted char
    else *dst++ = *src++;
  }
  *dst = '\0'; // null-terminate result
  return from;
}
</pre>
<p>alternatively, if I'm not permitted to call strchr()...</p>
<pre class="programlisting">
char *eliminate(char these[], char from[]){
  char *src = from;
  char *dst = from;
  while ((*dst = *src++) != '\0') {
    for (char *p = these; *p; ++p) if (*dst == *p) break;
    if (*p == '\0')++dst; // don't overwrite wanted char
  }
  return from;
}
</pre>
<p>Thank you for a very interesting journal.</p>
<p>Anthony Hay. <tt class="email">&lt;<a href=
"mailto:ahay@centennial.co.uk">ahay@centennial.co.uk</a>&gt;</tt></p>
<p class="c3"><span class="remark">My coding for removedashes()
illustrates a variation on the miss-typing of '==' as '=', this
time I put '==' where I intended '='. There is a difference between
C and C++ when it comes to the assignment operators. In C they
return a value, in C++ they return a reference to the lhs (first
operand). Note that this is conventionally a non-const reference
for udts (it is required to be for fundamental types). Note that
the explicit comparison with '\0' does nothing to help catch that
typo.</span></p>
<p class="c3"><span class="remark">Note that the error message on
the return value emphasises that arrays and pointers really are not
interchangeable despite so many programmers thinking they
are.</span></p>
<p class="c3"><span class="remark">I think that some programmers
may not like your use of break. And quite a few would advocate that
the prototype of your function be:</span></p>
<pre class="programlisting">
  char *eliminate(char const these[], char from[]; 
</pre>
<p class="c3"><span class="remark">Anyone offer an implementation
that does not use break nor call another function?</span></p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
