    <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  :: Questions &amp; Answers</title>
        <link>https://members.accu.org/index.php/journals/755</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, #1 - Nov 1998 + 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/c134/">111</a>
                    (19)
<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/c134-186/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/journals/c134+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;Questions &amp; Answers</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 November 1998 13:15:28 +00:00 or Tue, 03 November 1998 13:15:28 +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="d0e20" id="d0e20"></a></h2>
</div>
<p>I have just got time to squeeze this in before midnight.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e24" id="d0e24"></a>Mr R.J. Smith
emailed the following question:</h2>
</div>
<p>I work with electronic microcontrollers (PIC devices) and to be
able to program in C would be useful to me as the PIC
microcontroller assember has <tt class="literal">#includes</tt>,
<tt class="literal">#defines</tt> and so on very similar to C.
Apart from which, C is more powerful than the Microsoft BASIC and
perhaps more useful in electronics than FORTRAN. I am familiar with
both these languages.</p>
<p>I have been reading about C for about 4-6 months, making notes
and so on and decided that it would be good for me to create a
simple terminal program to receive information via the RS232 serial
port (COMX). I have an old book called BORLAND C++ Library
Reference which lists a function called:-</p>
<pre class="programlisting">
_bios_serialcom(_COM......
</pre>
<p>I copied the listing given in the book and I understand the
code.</p>
<p>However, at least 11 errors are produced showing that the:</p>
<p>...Call to undefined function: <tt class=
"function">_bios_serialcom(....)</tt>; in <tt class=
"function">main</tt> .......... undefined symbol '_COM_INIT' &quot; &quot; &quot;
'_COM_CHR7' ...etc.</p>
<p>The includes:</p>
<pre class="programlisting">
#include &lt;bios.h&gt;
#include &lt;conio.h&gt;
</pre>
<p>are in the program at the top.</p>
<p>I have set the paths for the include and library files to point
to the correct location.</p>
<p>A friend of mine who was an old C programmer with years of
experience said that the compiler/linker is finding the header
files, but it cannot seem to find the function in the library. To
prove it, he included a bogus header: <tt class="literal">#include
&lt;bios123.h&gt;</tt> and the error message that came up was
completely different, although, I did point out to him that the
<tt class="literal">_int cmd, int port, char abyte</tt> where in
the <tt class="filename">bios.h</tt> header file and I did not
understand why it would throw up an undefined symbol for these if
they were there and if was finding the bios.h okay.</p>
<p>I have spent two days on this problem and even though my friend
tried to compile it using Borland 5 is still flagged up the same
errors.</p>
<p>I was using Borland 4.5 on my machine.</p>
<p>The Help was useless to me since with 4.5 it shows only some of
the bios functions but not the <tt class=
"function">_bios_serialcom</tt>. However, on my friends machine
using Borland 5 some help information is available and appears to
be a copy of what is in the Borland C++ library I spoke of earlier.
When we clicked for an example, nothing was available.</p>
<p>My friend did say we could probably achieve what I wanted to do
by going up a level (I think he said something about windows).
However, it would suit me to stay at this level for a while since I
only starting out on C.</p>
<p>It seems to me when I have looked on the web to be very little
information about this function or examples of its use. I bought a
CD with what was a C++ suite of programs. All the code was there
for many applications, but the serial comms was an advert for
purchase of some coding for using the serial port.</p>
<p>Despite the function in question having its prototype in the
header file (bios.h) along with others, the library routine is
either missing or there is a mistake somewhere that I can't find. I
repeat that I copied the code verbatim from the book, but even if
you have only a few lines to include</p>
<pre class="programlisting">
#include &lt;bios.h&gt;
</pre>
<p>a few simple definitions and the troublesome <tt class=
"function">_bios_serialcom</tt> it still does not
work!---argh!!!</p>
<p>If you have come across anything like this before I would
appreciate your help. I was planning to use some of the other bios
calls as well. My friend says the paths are all correct and he is
really puzzled!</p>
<p>PS I rang the user group on 01980-630032 and they said that you
may be able to help. Thanks in advance.</p>
<p class="c2"><span class="remark">Your editor forwarded this cry
for help to three of our experts in embedded code. Unlike Mr
Smith's friend, these knew their code.</span></p>
<p class="c2"><span class="remark">Here is the brief response from
Chris Hills</span></p>
<p>I think I solved it, emailed (a longer) answer to Mr Smith.</p>
<p>Correct it is seeing the header. However the header has a lot of
<tt class="literal">#ifdef</tt>'s. There is one round <tt class=
"function">_bios_serialcom</tt>. It can only be used in DOS not
windows or DPMI! The error is a compiler error (not a linker error
so there is no library involvement)</p>
<p>It was finding the <tt class="filename">bios.h</tt> but just not
reading the part with <tt class="function">bios_serialcom</tt> in
it.</p>
<p>Solution: set the BC compiler to DOS .EXE and C. (OK you could
use C++ but he wants C)</p>
<p>Anyone found a better solution?</p>
<p>By the way I recommended he get C for Engineers by Brian
Bramer</p>
<p class="c2"><span class="remark">Now any experienced C programmer
could have found that out couldn't they? Note that there is a
difference between compiler and linker errors. Assuming that the
function really was a function and not a macro C should have been
deducing the prototype. However why did Mr Smith's friend not use
grep (or a similar utility) to search for the relevant function
declaration? We will never know.</span></p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e129" id="d0e129"></a>Question from
Dave Williams regarding a posting of mine to a newsgroup.</h2>
</div>
<p>I've seen you make this point on a number of occasions in C Vu
and, at the risk of sounding ignorant, I don't understand why C
uses all upper case for <tt class="literal">const</tt> values and
<tt class="literal">enum</tt>s. I appreciate your example shows a
silent &quot;redefinition&quot; of apparently <tt class="literal">const</tt>
values, however I would have thought that showed up the perils of
using <tt class="literal">#define</tt> more than problems with a
naming convention. Maybe I have missed the point.</p>
<p>If you could possibly provide a reference to the C explanation
I'd be very grateful - if it's been in C Vu in the past year and
I've missed it, I apologise. I have looked in Dejanews and at a
number of textbooks but cannot find any convincing reason to
reserve all capitals for pre-processor identifiers. Indeed,
Stroustrup's first enumeration example in section 4.8 of &quot;<i class=
"citetitle">The C++ Programming Language</i>&quot; uses <tt class=
"literal">enum { ASM, AUTO, BREAK }</tt>.</p>
<p>Anyway, as I said above I am probably just showing my ignorance.
Any pointers to lessen that ignorance would be much
appreciated.</p>
<p class="c2"><span class="remark">So Bjarne isn't perfect&#9786;
(I'll buy you a drink in Dublin, Bjarne)</span></p>
<p class="c2"><span class="remark">The problem stems back to the
fact that C makes fairly heavy use of the pre-processor because it
did not have any mechanism for providing compile time constants
(still doesn't because, unlike C++, <tt class="literal">const</tt>
in C does not produce a constant expression (technical term meaning
the compiler can use the value directly) Unfortunately there was
only one set of characters available for creating identifiers. C
split this up between different users/uses. For example any
identifier starting with either two underscores or an underscore
and an uppercase letter was deemed to belong to implementors. That
rule is written into the C standard. The other one about using all
uppercase for pre-processor identifiers is purely
conventional.</span></p>
<p class="c2"><span class="remark">Many self-taught programmers
deduced that the convention was that named values were written in
uppercase. In other words they misunderstood the reason for the
convention (to keep dangerous <tt class="literal">#define</tt>
identifiers distinct from all other identifiers). The result is
that many C programmers use uppercase for <tt class=
"literal">const</tt> variables and for <tt class=
"literal">enum</tt> labels. C++ programmers being even less expert
at C just copied them. The original convention was there for good
reasons. Those reasons are just as valid today as ever they were.
Even if you never use <tt class="literal">#define</tt> yourself
code in included header files will. If someone uses any lowercase
letters in a pre-processor identifier you have every right to
complain (even if it is the C Standard's Committees unless they
start with two underscores) but if you use identifiers without any
lowercase letters anywhere else the resulting problems are of your
own making. It is time that the gurus started setting better
examples.</span></p>
<p class="c2"><span class="remark">Quite apart from issues of
readability the following guidelines will go a long way to protect
your code (programmers need to be defensive):</span></p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p class="c2"><span class="remark">Pre-processor identifiers should
never include any lowercase letters</span></p>
</li>
<li>
<p class="c2"><span class="remark">All other identifiers should
include at least one lowercase letter.</span></p>
</li>
</ul>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
