    <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 Journey</title>
        <link>https://members.accu.org/index.php/journals/940</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, #6 - Oct 1999 + Programming Topics</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/c129/">116</a>
                    (22)
<br />

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

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

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c65/">Programming</a>
                    (877)
<br />

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

                    -                        <a href="https://members.accu.org/index.php/journals/c129+65/">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 Journey</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 04 October 1999 13:15:34 +01:00 or Mon, 04 October 1999 13:15:34 +01:00</p>
<p><strong>Summary:</strong>&nbsp;<p><span class="emphasis"><em>The Journey is a reduction of the
postings to accu-general compiled every month. ACCU general
provides an opportunity for members to discuss, share, educate and
be educated.</p></p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e20" id="d0e20"></a></h2>
</div>
<p><span class="emphasis"><em>The Journey is a reduction of the
postings to accu-general compiled every month. ACCU general
provides an opportunity for members to discuss, share, educate and
be educated. The monster thread of the month award goes to &quot;How
Language Design Affects Idioms&quot; started by Sean Corfield. Since the
intention was to produce material for an article by Sean, I won't
be quoting from that path. Here are some of the other prime threads
from June.</em></span></p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e25" id="d0e25"></a>Detecting
stream errors</h2>
</div>
<p><span class="emphasis"><em>This thread brought about the
interesting issue of stream diagnostics, or rather the lack of
them.</em></span></p>
<p>[Dave Rutlidge]</p>
<p>If I have code that looks like...</p>
<pre class="programlisting">
void foo() {
  ifstream ifs;
  ifs.open(&quot;bar&quot;);
  if (ifs.fail()) {
    clog &lt;&lt; &quot;I got an error&quot;;
  }
</pre>
<p>How do I find the reason why the open failed? I have spent hours
looking at the documentation but could not find any official way of
doing this. I also played and found that <tt class=
"function">perror()</tt> will display the error message, but this
is C not C++/streams. I could use <tt class=
"function">strerror()</tt>. Is this the &quot;official&quot; way? Is there a
better way?</p>
<p>[Sean Corfield]</p>
<p>We discussed this a while back on this list and the answer was
&quot;You can't&quot;.</p>
<p>[Klitos Kyriacou]</p>
<p>Now it seems that C++ <tt class="classname">ifstream</tt> also
sets <tt class="varname">errno</tt>. However, this may be a result
of the streams library using the C stdio library in its
implementation (depending on who developed your C++ library). The
standard doesn't require <tt class="varname">errno</tt> to be set
when <tt class="methodname">ifstream.open()</tt> fails. Having said
that, I suspect the C standard doesn't say exactly when <tt class=
"varname">errno</tt> should be set either. So it sounds like pot
luck whether errno gives you anything useful, whatever language you
choose. Any comments?</p>
<p>How about the following way of obtaining an error message, if
one is available:</p>
<pre class="programlisting">
{
  errno = 0;  // Reset to no error
  ifstream f(filename);
  if (f)
    process_file(f);
  else
    if (errno)  // Set by ifstream::ifstream(const char*)
      cout &lt;&lt; &quot;Failed to open file: &quot; &lt;&lt; strerror(errno) &lt;&lt; endl;
    else
      cout &lt;&lt; &quot;Failed to open file.&quot; &lt;&lt; endl;  // Unknown cause
}
</pre>
<p>[Bill Somerville]</p>
<p>I still think that <tt class="varname">errno</tt> should only be
relied on immediately after a system call returns a failure
status.</p>
<p>[Philip Hibbs]</p>
<p>A global variable like <tt class="varname">errno</tt> can never
be thread-safe, so even checking it immediately might not work.</p>
<p>[Adrian Fagg]</p>
<p>Well, actually it can sometimes be, though you can't rely on it
everywhere. Multithreaded libraries - so long as they're properly
initialised - will work correctly. As far as I know this applies to
<tt class="varname">errno</tt>.</p>
<p>[Sean Corfield]</p>
<p>You can check the flags in a stream to get some information but
generally any particular errors are platform specific (permissions,
existence etc.) so these have no place within a Standard. Not much
help I'm afraid... The committee did discuss making more
information available but there was no agreement on how to do this
in a portable manner.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e97" id="d0e97"></a>Code Analysis
Tools</h2>
</div>
<p><span class="emphasis"><em>This conversation was started by Paul
Rocca, who explained he had to convert Pascal to C. To make things
a shade more complex, the Pascal code was in French. Having Y2K
checked some French C recently, I know how surprised I was at the
complexity added by not understanding variable names
etc.</em></span></p>
<p>[Jon Jagger]</p>
<p>If I were you the first thing I'd do is rewrite the
French-Pascal as English-Pascal. Then worry about converting it to
C. Or whatever. One thing at a time. Evolution rather than
revolution. Stable Intermediate Forms (as Kevlin would say)</p>
<p>[Nigel Thornton-Clark]</p>
<p>A few years ago I worked on a project to convert a large
application written in C from OS9 to RSX11. The original
application was written by a German company so all the comments and
names were in German. For some strange reason there were actually
two projects doing the same conversion for the same customer on
different sites run in parallel. The first project manager decided
to translate everything into English, port the code, and make some
enhancements all at the same time. The second project manager
ported the code first and then made the enhancements. At each stage
he made sure that the code was stable before proceeding. The result
was that the second project finished six months ahead of the first
and was a pleasure to work on. We didn't get round to translating
everything from German to English because by the time we'd finished
we could understand the comments and we were familiar with the
German naming conventions.</p>
<p>In addition, I would make sure I could compile and run the code
in Pascal before even thinking about translating it or converting
it. I would also treat any automatic conversion tools with a great
deal of suspicion as, from what I can remember, p2c only works with
fairly standard Pascal whereas the source may be written in
TurboPascal which has a lot of non-standard extensions. One
approach may be to convert the code module by module, using p2c,
and to keep the C code in a library that can be linked to the
remaining Pascal code. That way you have something that works at
every stage.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e113" id="d0e113"></a>Strings</h2>
</div>
<p><span class="emphasis"><em>Finally this month, we have some
distilled wisdom on the subject of strings. The following comes
from a couple of separate threads which show how the unwary can be
caught out by the C++ Standard <tt class="classname">string</tt>,
even if they have used old style strings (<tt class="type">char
*</tt> or the MFC <tt class="classname">CString</tt>). The names
have been removed to protect the innocent, and answers may have
been supplied by more than one person.</em></span></p>
<p>[Q - Strings and map]</p>
<p>I'm trying to use the STL map and I'm having some problems.</p>
<pre class="programlisting">
map&lt;char*, char*&gt; myMap;
char a[40];
char b[40];
do {
  myMap.insert(myMap.begin(), map&lt;char*, char*&gt;::value_pair(a, b));
} while( morevaluesfromdb() );
</pre>
<p>If I do this, it overwrites the values. I believe this is
because its storing the address of a and b rather than the values.
How do I use the map correctly?</p>
<p>[A]</p>
<p>Map stores values - the values being stored are pointers
(<tt class="type">char *</tt>) Your code stores <tt class=
"classname">pair&lt;&amp;a, &amp;b&gt;</tt> over and over. Instead
of <tt class="classname">std::map&lt; char *, char * &gt;</tt>, use
<tt class="classname">std::map&lt; std::string, std::string
&gt;</tt></p>
<p>[Q - Strings and default parameters]</p>
<p>I have a function like:</p>
<pre class="programlisting">
int GetThing
  (const string&amp; stra, const string&amp; strb = NULL);
</pre>
<p>If I do this:</p>
<pre class="programlisting">
string x = &quot;EH101&quot;;
GetThing(x);
</pre>
<p>I get an access violation because of the NULL <i class=
"parameter"><tt>strb</tt></i>.</p>
<p>What am I doing wrong. Can I use default values of type
string?</p>
<p>[A]</p>
<p>You are attempting to initialise a string with a null pointer.
Try:</p>
<pre class="programlisting">
int GetThing(const string&amp; stra, const string&amp; strb = string());
</pre>
<p>I like to talk about the former (<tt class="type">char *</tt> or
<tt class="type">char []</tt>) as a C string, and the latter
(<tt class="classname">std::string</tt>) as a C++ string, in the
hope that all those programmers who haven't caught up yet will soon
stop using raw <tt class="type">char</tt> arrays in C++.</p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
