Mozilla C++ portability guide

I'm up to Chapter 18 of Stroustrup's The C++ Programming Language. The templates chapter was painful and I had to read it twice. I think I got it the second time through. Stroustrup talks about how people ask him how long it takes to learn C++ and he says (paraphrased) "a year or two probably; be happy, it's not as long as it takes to learn a spoken language or a musical instrument". It's still frustrating. The syntax and whatnot are so easy to learn, but the idioms and common practices take forever to ingrain.

Today in my somewhat futile half-hearted attempt to learn autotools, I chanced upon the Mozilla C++ portability guide It includes such advice as:

  • Don't use templates.
  • Don't use exceptions.
  • Don't use namespaces.
  • Don't use the C++ standard library, not even iostream.
  • Don't put assignments in if statements.
  • Use macros.

This is interesting, since it's the exact opposite of what Stroustrup writes. And Stroustrup also says he wrote this book in such a way as to demonstrate "standard" portable code. I guess I don't doubt that the Mozilla guys know what they're talking about, but if that's the extent you have to bend in order to write "portable" code, I hope I don't ever have to.

3 Responses to “Mozilla C++ portability guide”

  1. Quoth Syd:

    I happened to work at Netscape at the time this document was produced. Many of the items are dated; I don't, for example, agree today that avoid RTTI is a reasonable guideline.

    I'm currently preparing a book on C++ portability that will be released by Prentice Hall, based on my experiences at Netscape. Of the items mentioned by Mozilla in that document, when it comes down to it, the only ones I mention are 1) take care regarding the sign of char types 2) use of NSPR (using an abstraction library is definitely a good thing and 3) fix your compiler warnings. Beyond that, I think anything that Stroustrup claims is safe (especially if portability means working with Visual C++, and GCC on Mac and Linux — which is the case for a great many people).

    After reading Stroustrup, I'd move on to the Effective C++ book by Scott Meyers. Read that book back to front, and then do it again twice more. Use Stroustrup as a reference, but read (and practice) what Meyers has to say until it is second nature. You'll be a better C++ programmer for it.

  2. Quoth Brian:

    Awesome. Thanks for the advice and clarification.

  3. Quoth Ranjith Thai Valappil:

    I will be using new C++ compilers, which will be supporting RTTI. Is there still any problem in using RTTI(dynamic_cast all those things)?

Leave a Reply

You can use these tags in comments (Note: HTML is automatically escaped inside <pre> tags, nowhere else, so if you post source code, put it in <pre>):

<pre lang="some_programming_language"> 
<em>
<strong>
<a href="url">

NOTE: Comments are automatically spam-filtered. If your comment fails to appear, it was likely munched by the filter. Try not to link-spam or post anything that looks like it was typed by a robot.