    <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 EPOC C++ API</title>
        <link>https://members.accu.org/index.php/journals/540</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">Overload Journal #32 - Jun 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/c78/">Overload</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c172/">32</a>
                    (11)
<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/c172-65/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/journals/c172+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 EPOC C++ API</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 26 June 1999 17:50:53 +01:00 or Sat, 26 June 1999 17:50:53 +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="d0e16" id="d0e16"></a></h2>
</div>
<p>Last year I upgraded my Personal Organiser to a Psion Series 5
and was contemplating spending the money (175UKP) to get the EPOC
C++ SDK - EPOC is the operating system that runs the Series 5. To a
professional C++ (and hobbyist Java) developer this looked more
enticing than learning the alternative OPL &quot;user friendly&quot;
programming language.</p>
<p>I'm not really interested in writing applications for the Psion,
but there are occasions when I write utilities that it would be
nice to have available both on my desktop system and on the Psion.
Obviously some EPOC specific code would be required, but since I
keep platform specific code (such as user interfaces and
input/output) in separate modules from the core application I
expected this to be feasible.</p>
<p>The Psion is a small system so it would be unreasonable to
expect all the facilities of a desktop system. But since I had
already established that the C standard library was available I had
hopes of &quot;porting&quot; some of my less demanding programs.</p>
<p>Around the time I was considering buying the SDK Psion had
separated their software development under the name of Symbian. On
visiting the Symbian website [<a href="#symbian">symbian</a>] I
found they advertised an evaluation version of their C++ SDK. I
requested a copy but in August 1998 a dispute with STNC led to the
SDK becoming unavailable.</p>
<p>Time passed, the dispute with STNC continued and I found other
interests. So it was a surprise when sometime around the end of
January or early February I finally received this SDK. It then had
to sit on a shelf until I had time to look at it.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e31" id="d0e31"></a>Contents of the
SDK</h2>
</div>
<p>The evaluation SDK requires Windows95 or NT and Visual C++ 4 or
5 (the learning edition will do) which may be a disappointment to
those developers that resist all things Microsoft. There is a patch
on the Symbian web site that &quot;cures some of the problems
experienced using Visual C++ 6&quot;.</p>
<p>The full SDK is built around two tool chains. One of these is
based on Visual C++ and targets a version of EPOC implemented on
top of Windows and allows debugging using Visual Studio. The second
tool chain is based on Cygnus's build tools distribution (gcc etc.)
and targets EPOC systems. Key elements of the latter are omitted
from the evaluation SDK.</p>
<p>In addition there are instructions for building a range of
example programs, coding guidelines, and an API reference. The API
covers all the EPOC operating system facilities - such as accessing
files, communications ports, and the GUI library.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e40" id="d0e40"></a>Getting
started</h2>
</div>
<p>The SDK installed easily - although it annoyed me by creating a
number of top level directories on the partition of my choice
rather than letting me specify a base directory under which to
install everything.</p>
<p>After installation I followed the instructions for building some
of the example programs to run using the &quot;Emulator&quot;. This is a
library that implements the EPOC APIs under Windows and provides a
user interface via a window that looks like the Psion. The example
programs built and ran happily and I could debug into them using
Developer Studio. Looking at the code my first impression was
confusion - class instances were initialised using two phase
construction, many of the member functions had weird looking names
ending in a capital &quot;L&quot; and class names began either with &quot;T&quot; or
&quot;C&quot; prefix with no apparent pattern.</p>
<p>This led to a nagging suspicion that all was not as I had hoped
- two phase construction is a technique developed in the early days
of C++ to deal with the inability of the language to deal with
error conditions occurring in constructors. When exception handling
was adopted in the early '90s it fell into disuse.</p>
<p>I dived into the documentation seeking an explanation. Here I
discovered that the &quot;coding guidelines&quot; require two phase
construction, that &quot;L&quot; identifies a function that could &quot;leave&quot; and
that &quot;T&quot; and &quot;C&quot; are used to distinguish classes that have no
destructor from those that need to free memory at the end of their
lifetime. I also discovered &quot;R&quot; a prefix for classes that need to
free other system resources.</p>
<p>I deduced that &quot;leaving&quot; isn't like throwing an exception since
any function that calls an &quot;L&quot; function has to manually register
instances of any &quot;C&quot; or &quot;R&quot; classes with a &quot;cleanup stack&quot;. This
delivers similar results to exception handling with the following
differences: the programmer can get the registration logic wrong
(the compiler shouldn't), and there is a runtime cost to all these
extra function calls (this can be avoided with compiler support).
There is definitely more code to maintain, but I don't have figures
to support my suspicion that there is also a space cost.</p>
<p>Hopefully, no-one would introduce the unwieldy mechanisms I'd
encountered in preference to using genuine exception handling! But
at the time I could find no direct indication that the version of
C++ was anything other than compatible with Visual C++ which does
have exception handling support. (I later discovered documentation
that states that exceptions - and other language features - are not
supported, but it is hidden in various parts of the API function
reference, not in the introductory material or white papers.)</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e55" id="d0e55"></a>From the
source</h2>
</div>
<p>Having decided that the supported language probably lacked
exceptions I wondered what else was non-standard and decided to
email Symbian in the hope of clarifying matters:</p>
<div class="blockquote">
<blockquote class="blockquote">
<div class="variablelist">
<dl>
<dt><span class="term">Alan Griffiths:</span></dt>
<dd>
<p>Could you confirm a suspicion that has been growing as I read
through the SDK documentation - that the language supported by the
SDK is very different from that defined by the current ISO C++
Language Standard.</p>
<p>In particular I was puzzled by the lack of an explanation of
when one would use the cleanup stack mechanism in preference to
allowing exceptions to unwind the stack. Is this because the C++
exception handling mechanism is not supported? (On a related point
the examples seem to suggest that the &quot;new&quot; operator returns 0 in
place of throwing a <tt class="exceptionname">std::bad_alloc</tt>
exception.)</p>
<p>I appreciate that compiler support for a number of language
features is distinctly patchy and that the development of EPOC32
spans a period of rapid evolution in C++. However, I am repeatedly
puzzled by the approaches taken. While I can surmise that these are
compromises enforced by the available compiler technology I can't
be sure since these issues do not appear to be addressed
anywhere.</p>
</dd>
<dt><span class="term">&gt;Martin Tasker(Symbian):</span></dt>
<dd>
<p>There were essentially two reasons for not adopting the C++
standard library when we started developing EPOC:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>at the time (mid 95) the standard had not been agreed - though
the language standard was substantially in place - clearly that has
changed since</p>
</li>
<li>
<p>the standard library, in particular its use of templates and its
exception-handling culture, was considered too profligate in terms
of space and time for adoption in a small system - that has not
changed since Embedded C++ is evidence that we were not the only
people that shared this feeling. They didn't even support templates
at all! - we do, but we use them exclusively in &quot;thin template&quot;
idioms.</p>
</li>
</ul>
</div>
</dd>
<dt><span class="term">AG:</span></dt>
<dd>
<p>I can understand your reasons for not adopting the standard
library, my main concern however is the _language_</p>
<p>I think your choice is wiser than that of the EC++ group
[<a href="#EC">EC</a>]. (Templates in themselves are not harmful
and can greatly enhance the type safety and reliability of some
code.)</p>
</dd>
<dt><span class="term">&gt;MT:</span></dt>
<dd>
<p>By default, we will pick up and deliver some support for
standard C++ as time goes by. Later this year, we will take newer
drops of Cygnus' GCC toolchain which will include more standard C++
support (our current supported technology dates from 1996). It
might then be possible to implement a C++ standard library on EPOC,
but we have as yet no plans to do that ourselves.</p>
<p>The accessibility of this information could be improved, and our
plans for technical papers in the first half of this year should
help.</p>
<p>Incidentally in EPOC C++, operator new() returns 0 on failure,
unless you use the override which appears as new(ELeave) - which
&quot;leaves&quot; with KErrNoMemory on failure. There was a debate in mid-96
about whether to make ELeave the default behaviour. Largely on the
grounds that this would confuse imported C++ programs too much, we
decided against.</p>
</dd>
<dt><span class="term">AG:</span></dt>
<dd>
<p>Equally, having new return 0 causes portability problems - it
would be best if it threw <tt class=
"exceptionname">std::bad_alloc</tt>. However, there are still many
platforms that implement the pre '95 semantics you describe.</p>
</dd>
</dl>
</div>
</blockquote>
</div>
<p>I must confess to being disappointed that the supported language
was closer to EC++ than C++ but my main difficulty throughout was
the lack of documentation of what is and isn't supported.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e120" id="d0e120"></a>From the
net</h2>
</div>
<p>I have to thank John Forrest <tt class="email">&lt;<a href=
"mailto:j.forrest@dial.pipex.com">j.forrest@dial.pipex.com</a>&gt;</tt>
for posting the following summary on usenet <a href=
"nntp://comp.sys.psion.programmer" target=
"_top">nntp://comp.sys.psion.programmer</a> (I've corrected a few
typos).</p>
<div class="blockquote">
<blockquote class="blockquote">
<div class="itemizedlist">
<ul type="disc">
<li>
<p>Don't use any file scope or local static variables.</p>
</li>
<li>
<p>Don't use any multiply derived types, apart from the limited M
classes.</p>
</li>
<li>
<p>Can't use exceptions - use the EPOC Leave mechanism.</p>
</li>
<li>
<p>Don't use any C++ library stuff, just the EPOC stuff. (This is
easier since you'd have to go out of your way to link them in).</p>
</li>
<li>
<p>Can't use dynamic casts (or other RTTI)</p>
</li>
<li>
<p>Beware that this version of gcc uses an older syntax for
specific templates.</p>
</li>
<li>
<p>Be careful about the IMPORT_C and EXPORT_C usage for dll
external declarations - you only get complaints when compiling for
gcc.</p>
</li>
<li>
<p>Be careful about DLL UIDs - ditto.</p>
</li>
<li>
<p>Ensure all build information is given via the .mmp file - resist
the temptation to add files directly into the VC++
Workspace/Project.</p>
</li>
</ul>
</div>
<p>You can use &lt;stdio.h&gt;, but I'd advise against - that and
other C library stuff are there for backward compatibility - unless
you are trying to port a pure C program. If you mix and match then
you have to close down the library in a special way.</p>
<p>Otherwise as a rule stick to the style used in the examples and
the manual. This is pretty different from normal, and some people
moan like hell, but since all the apps are written in this style
you are much less likely to hit bugs. Try to avoid backsliding -
some people in the past have hit problems because they (as far as I
can make out) have tried to do C style string manipulation directly
on the contents of descriptors (used for strings and other
things).</p>
</blockquote>
</div>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e164" id="d0e164"></a>My
conclusions</h2>
</div>
<p>I guess I'm one of those that &quot;moan like hell&quot; because I don't
want to make a commitment to developing solely for EPOC. I'd rather
my programs were available on whatever computer I have to hand
(which is why Java interests me). If I were intent on developing
applications specifically for EPOC platforms then the non-standard
nature of the C++ used would be less important to me.</p>
<p>At the root of my concerns is a problem I first wrote [<a href=
"#Griffiths">Griffiths</a>] about in 1995 as a result of reading
the first public draft of the ISO C++ standard. I complained about
the many ways in which changes to the language invalidated the
experience, skills and code base of those working with it. A
particular issue is that the presence of exception handling
necessitates a different style of coding. (Of course, the decision
to include exceptions took place long before this - they are
described in the 1990 ARM [<a href="#Ellis">Ellis</a>] as
&quot;experimental&quot; language features.)</p>
<p>Having spent the intervening four years becoming accustomed to
these features I find that I am addicted. My current code base
would not compile or work without exceptions, namespaces, or STL (I
could live without RTTI). I also find that the resulting programs
require less code and are more robust. (If they use
&lt;iostream&gt; they take a substantial, but fixed, hit in
executable size, but otherwise they tend to be smaller or have more
functionality.)</p>
<p>Regarding the programs that it would be nice to have available
on my Psion I'd be willing to do some rework to have them. However,
as it stands I would also need to redevelop the core application in
the supported dialect of C++ and for me this is not worthwhile.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e181" id="d0e181"></a>&quot;The EPOC C++
SDK&quot; - A response from Symbian's Martin Tasker</h2>
</div>
<p>I've had several discussions with Martin about the issues raised
by the above (which he has read in draft form) you may be
interested in the following response: - Alan</p>
<div class="blockquote">
<blockquote class="blockquote">
<p>Your comments are understandable from your perspective but
consider the following:</p>
<div class="orderedlist">
<ol type="1">
<li>
<p>the C++ facilities weren't there in GCC when we designed our
leave support</p>
</li>
<li>
<p>our system is entirely effective re its original design goals
and - re those goals alone - is more economical than native C++
exception facilities</p>
</li>
<li>
<p>compared to other palmtop systems, we're better: Windows CE, for
instance, kills apps and loses data in order to save memory: we
never do that, precisely because our exception handling stuff is
built in so deep</p>
</li>
</ol>
</div>
<p>Compatibility with &quot;standard&quot; C++ (the quotes were justified in
1995) was not a design goal of the original system: we could see
the design goals of the C++ library and exception handling
mechanism diverging grossly from ours, and the GCC toolchain didn't
support exceptions as late as 1996. Our version of the toolchain
will add support for native exceptions - possibly before the year
is out. That will enable others to port the standard library, and
code using it, onto EPOC.</p>
<p>I actually look forward to more dyed-in-the-wool C++ programmers
such as ACCU members using EPOC for both academic/research purposes
and commercial development. Much of commercial work we've fostered
or known about hitherto has been by people from a
SIBO/C/UNIX/Java/Win32-type background - including our own in-house
developers - for whom EPOC poses an entirely different set of
learning and porting issues.</p>
</blockquote>
</div>
</div>
<div class="bibliography">
<div class="titlepage">
<h2><a name="d0e203" id="d0e203"></a>References</h2>
</div>
<div class="bibliomixed"><a name="symbian" id="symbian"></a>
<p class="bibliomixed">[symbian] <span class="bibliomisc"><a href=
"http://www.symbian.com/" target=
"_top">http://www.symbian.com/</a></span></p>
</div>
<div class="bibliomixed"><a name="EC" id="EC"></a>
<p class="bibliomixed">[EC] Embedded C++ is an ARM like dialect of
C++ being promoted by a Japanese consortium - details may be found
at <span class="bibliomisc"><a href=
"http://www.caravan.net/ec2plus/" target=
"_top">http://www.caravan.net/ec2plus/</a></span></p>
</div>
<div class="bibliomixed"><a name="Griffiths" id="Griffiths"></a>
<p class="bibliomixed">[Griffiths] &quot;No such thing as a free lunch&quot;
Alan Griffiths Overload 7 ISSN 1354-3172</p>
</div>
<div class="bibliomixed"><a name="Ellis" id="Ellis"></a>
<p class="bibliomixed">[Ellis] &quot;The Annotated C++ Reference Manual&quot;
Ellis &amp; Stroustrup ISBN 0-201-51459-1</p>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
