DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="Kipp E.B. Hickman">
   <META NAME="GENERATOR" CONTENT="Mozilla/4.04 [en] (WinNT; U) [Netscape]">
   <TITLE>C++ Tips</TITLE>
</HEAD>
<BODY>

<H1>
C++ Tips</H1>
This is a compilation of tips on how to write cross-platform C++ code that
compiles everywhere.
<H2>
General</H2>

<UL>
<LI>
Always use the nspr types for intrinsic integer types. The only exception
to this rule is when writing machine dependent code that is called from
xp code. In this case you will probably need to bridge the type systems
and cast from an nspr type to a native type. The other exception is floating
point; nspr defines PRFloat as a double (!).</LI>

<LI>
Exceptions do not work everywhere so don't use them anywhere except in
machine specific code, and then if you do use them in machine specific
code you must catch all exceptions there because you can't throw the exception
across xp code.</LI>

<LI>
Templates do not work everywhere so don't use them anywhere.</LI>

<LI>
Do not wrap include statements with an #ifdef. The reason is that when
the symbol is not defined, other compiler symbols will not be defined and
it will be hard to test the code on all platforms. An example of what <B>not</B>
to do:</LI>

<BR>&nbsp;
<UL><TT>#ifdef X</TT>
<BR><TT>#include "foo.h"</TT>
<BR><TT>#endif</TT>
<BR><TT></TT>&nbsp;</UL>

<LI>
For types that do not need operator= or a copy constructor, declare them
yourselves and make them private. Example:</LI>

<BR>&nbsp;
<UL><TT>class foo {</TT>
<BR><TT>...</TT>
<BR><TT>private:</TT>
<BR><TT>&nbsp; // These are not supported and are not implemented!</TT>
<BR><TT>&nbsp; foo(const foo&amp; x);</TT>
<BR><TT>&nbsp; foo&amp; operator=(const foo&amp; x);</TT>
<BR><TT>};</TT></UL>

<LI>
</LI>
</UL>

<H2>
Windows Compatability</H2>

<H2>
Metroworks Compatability</H2>

<UL>
<LI>
MAC compilers do not handle #include path names in the same manner as other
systems. Consequently #include statements should not contain path names,
just simple file names. An example of what <B>not</B> to do:</LI>

<BR>&nbsp;
<UL>#include "gemini/nsICSSParser.h"
<BR>&nbsp;</UL>

<LI>
</LI>
</UL>

<H2>
G++ Compatability</H2>

<UL>
<LI>
Use void in argument lists for functions that have no arguments (this works
around a bug in g++ 2.6.3)</LI>
</UL>

</BODY>
</HTML>