    <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  :: You Write, the Editor Replies</title>
        <link>https://members.accu.org/index.php/articles/942</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>




<div class="xar-mod-head"><span class="xar-mod-title">Letters to the Editor + CVu Journal Vol 11, #6 - Oct 1999</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/articles/">All</a>

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

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

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

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

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

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c129/">116</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c186-129/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c186+129/">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;You Write, the Editor Replies</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 06 October 1999 13:15:33 +01:00 or Wed, 06 October 1999 13:15:33 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e20" id="d0e20"></a></h2>
</div>
<p>Dear Francis,</p>
<p>Further to my critique of the ISBN code, I found a routine in
Ivor Horton's Beginning Visual C++ 6 (Wrox) which will delete
dashes from a string without using functions from the standard
library.</p>
<pre class="programlisting">
void removeDashes(char * foo) {
  int i=0;     /* copy to offset within string     */
  int j=0;     /* copy from offset within string   */
  while (( *(foo + i) = *(foo + j++)) != '\0')
    if (*(foo + i) != '-')  i++;
  return;
}
</pre>
<p class="c2"><span class="remark">I think I would prefer to code
that function like this:</span></p>
<pre class="programlisting c3">
<span class="remark">char[] removedashes(char  sourcestring[]) {
int i=0;     /* index of destination in string     */
int j=0;     /* index of source in string   */
while ( sourcestring[i] ==  sourcestring [++ j]) 
  if (sourcestring[i] != '-') ++i;
return sourcestring;
}</span>
</pre>
<p class="c2"><span class="remark">Note that we do not need to
compare the value of the assignment with the nul character. What do
the readers think? How about writing a function to remove all
instances of the chars given in one string from a second string.
Implement the following prototype:</span></p>
<pre class="programlisting c3">
<span class=
"remark">char[] eliminate(char these[], char from[]);</span>
</pre>
<p>Here are some thoughts on the <tt class="literal">i+=++i</tt>
challenge from C Vu 11.5. I think they fail the coherence test
though. I hope they add something to the discussion process.</p>
<p>As with the previous case (<tt class="literal">i += i++</tt>) we
have <tt class="varname">i</tt> being written to more than once
without an intermediate sequence point. The pre-increment of
<tt class="varname">i</tt> (<tt class="literal">++i</tt>) returns
the current value of <tt class="varname">i</tt> plus <tt class=
"literal">1</tt> to be used in the evaluation of the expression and
then guarantees to write it back to the i variable at some future
time. The pre-incremented value could either be returned in a
temporary object or in the i variable itself. This last option
makes the implicit assumption that the compiler has a view on what
constitutes the <tt class="varname">i</tt> variable and its value
at all times.</p>
<p>From the compiler's viewpoint, the statement will be parsed and
code produced. However, the effects of any code optimisation may
change the outcome because of the side effects of some of the
statement components.</p>
<p>The possible final values that I could imagine and how they
could be produced are:</p>
<p><tt class="literal">i+1</tt></p>
<div class="orderedlist">
<ol type="1">
<li>
<p><tt class="varname">i</tt> is pushed onto the stack.</p>
</li>
<li>
<p><tt class="varname">i</tt> is preincremented and the rvalue is
pushed onto the stack.</p>
</li>
<li>
<p>the two values are added and popped into the <tt class=
"varname">i</tt> variable.</p>
</li>
<li>
<p>a sequence point happens and the value in step 2 is popped into
<tt class="varname">i</tt>.</p>
</li>
</ol>
</div>
<p><tt class="literal">2i+1</tt></p>
<div class="orderedlist">
<ol type="1">
<li>
<p><tt class="varname">i</tt> is pushed onto the stack as a
temporary object.</p>
</li>
<li>
<p><tt class="varname">i</tt> is preincremented and the rvalue is
pushed onto the stack as a temporary object.</p>
</li>
<li>
<p>the value in step 2 is popped into wherever the compiler thinks
<tt class="varname">i</tt> is.</p>
</li>
<li>
<p>the two values are added and popped into the i variable.</p>
</li>
</ol>
</div>
<p><tt class="literal">2i+2</tt></p>
<div class="orderedlist">
<ol type="1">
<li>
<p><tt class="varname">i</tt> is loaded into a register (Ri)</p>
</li>
<li>
<p><tt class="varname">i</tt> is loaded into another register (Rj)
and incremented.</p>
</li>
<li>
<p>Rj is copied into Ri.</p>
</li>
<li>
<p>Rj is added to Ri.</p>
</li>
</ol>
</div>
<p>The value 2i+2 is produced by the compilers I have tried (MS
VC++5, Metroworks Codewarrior, Symantec Think C 5 and IBM xlc).
There may be a difference in C++ is used. I am led to believe that
if the pre-increment function is overloaded to have the form
<tt class="methodname">operator++(int)</tt> then a sequence point
will occur because sequence points occur after the evaluation of a
functions arguments. I am very hazy on this point having managed to
avoid C++ and stay with C so far.</p>
<p>The above analyses assume that i is a standard type variable and
not user defined.</p>
<p>In the final section of the previous article you made the
comment that avoiding multiple writes in a single statement was a
good guideline, but that the guideline may be ignored if the
reasons for it are understood.</p>
<p>My question is:&quot;What are the circumstances in which the
guideline can be ignored?&quot;. My feeling is that something which
relies on such a deep understanding of what is defined is probably
something which will cause problems in the future. When someone
making a change to the code makes a change which then invalidates
the circumstances under which a double write is allowed the
behaviour of the code may become undefined.</p>
<i><span class="remark">It is always a serious error to attempt to
write twice to the same storage between sequence points however
given:</span></i>
<pre class="programlisting c3">
<span class=
"remark">int fn(int* i, int* j){ return ++(*i) + (*j)++;}</span>
</pre>
<i><span class="remark">consider</span></i>
<pre class="programlisting c3">
<span class="remark">int main(){
int i=0, j=0, k;
k = ++i + j++ ;  /* OK, three writes to different storage */
i = fn(&amp;i, &amp;j);  /* OK the two writes to i are protected by sequence points */
k = fn(&amp;i, &amp;i);  /* Undefined behaviour !! */
}</span>
</pre>
<i><span class="remark">I am not advocating this style but if you
understand when there is a risk of aliasing you can write to
several variables between sequence points.</span></i></div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
