    <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  :: Briefs</title>
        <link>https://members.accu.org/index.php/journals/865</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 11, #3 - Apr 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/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/c132/">113</a>
                    (22)
<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;Briefs</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 April 1999 13:15:30 +01:00 or Sat, 03 April 1999 13:15:30 +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="d0e13" id="d0e13"></a></h2>
</div>
<p class="c2"><span class="remark">This is a new, and I hope
regular column in which I will publish contributions from members
that are substantially less than a page in length. That means that
readers who are short of time to write a full article will still
have a chance of experiencing that warm feeling of seeing their
by-line in print.</span></p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e18" id="d0e18"></a>Boolean
Assumptions contributed by Silas Brown</h2>
</div>
<p>I recently came across some code with something like</p>
<pre class="programlisting">
x=y+isspace(ch);
</pre>
<p>This is similar to a BBC BASIC trick that assumes a boolean
function returning an integer will always return the same value for
true (in this case 1). It doesn't work in C because functions like
this are only guaranteed to return non-zero, not 1, when they mean
'true', and in particular the is... functions are often implemented
by taking an array element that gives all the attributes of the
character as a bit pattern and ANDing it with the required bits
before returning the result. This makes them fast (an indexed load
and an AND is quicker than lots of 'if' statements) but it also
means that the value returned can be anything (I tried it on three
different versions of gcc and got three different results). By not
defining it to be 1 or 0, the standard has allowed for such
optimisations. If you want it to be 1 or 0, you would have to write
(isspace(ch)?1:0) and similarly for other functions.</p>
<p>On the subject, did you know that the is... functions are
undefined on EOF? The same code had a <tt class=
"literal">while(isalpha())</tt> loop that evidently assumed that
EOF would fail it. In the sample implementation described above,
EOF is outside the bounds of the array and what the function will
return depends on what rubbish there is in the appropriate memory
location. If you want to bounds-check an is... parameter then first
call <tt class="function">isascii()</tt>.</p>
<p class="c2"><span class="remark">Are there any differences
between C and C++ in this context? No, I am not telling, find out
and write it up.</span></p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e38" id="d0e38"></a>A Dangerous
Assumption contributed by Silas Brown</h2>
</div>
<p>Never assume that your compiler obeys the standard, no matter
how reputable it is. I've just spent my afternoon trying to get my
access gateway working on a web server at Edinburgh University,
because there was interest in a local version there (thanks to
telnet I didn't have to leave Cambridge). The server was a Sun Unix
machine, not Intel, with a not-too-well set-up version of g++; I
had to do some patching to get it to work and when it did work, the
program wouldn't run. I eventually tracked the problem down to
<tt class="function">vsprintf()</tt> not returning what it is
defined to return (even in Sun's and gcc's own documentation) - the
number of characters output, or &lt;0 for an error. Instead, it
returned some incredibly huge positive value that caused a rogue
memory overwrite. Re-writing that section of code to avoid the use
of <tt class="function">vsprintf()</tt>s return value fixed the
problem.</p>
<p>It would be good if someone could write a &quot;standards benchmark&quot;
program that, when compiled with an arbitrary compiler and run,
will report any deviations from the standard (or indeed anything
that does conform to the standard but is not usual) so programmers
attempting to port code to it will know precisely what to expect.
Perhaps ACCU could do this as an organisation, with those members
who are interested contributing and discussing their code?</p>
<p class="c2"><span class="remark">Well such programs exist but are
immensely expensive (they are conformance test suites). The
specific problem here reminds me of problems where there is a
conversion from a signed integer type to an unsigned one. I wonder
if some such was hiding in the code.</span></p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e54" id="d0e54"></a>Did You Know
contributed by Silas Brown</h2>
</div>
<p>Did you know that the GNU C and C++ compilers under Unix have
built-in profilers? If you compile with the <tt class=
"literal">-pg</tt> switch, your executable will generate a file
<tt class="filename">gmon.out</tt>. If the executable itself is
called <tt class="filename">a.out</tt> then you can just type
<tt class="literal">gprof|more</tt> to view the profile. The first
functions or methods that it lists are likely to be the
bottlenecks.</p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
