C++ Portability Rules

C++ Portability Rules.

1. Don't use C++ templates. (*)
2. Don't use static constructors.
3. Don't use exceptions.
4. Don't use Run-time Type Information.
5. Don't use namespace facility.
6. main() must be in a C++ file.
7. Use the common denominator between members of a C/C++ compiler family.
8. Don't put C++ comments in C code.
9. Don't put carriage returns in XP code.
10. Put a new line at end-of-file.
11. Don't put extra top-level semi-colons in code.
12. C++ filename extension is .cpp.
13. Don't mix varargs and inlines.
14. Don't use initializer lists with objects.
15. Always have a default constructor.
16. Don't put constructors in header files.
17. Be careful with inner-classes.
18. Be careful of variable declarations that require construction or initialization.
19. Make header files compatible with C and C++.
20. Be careful of the scoping of variables declared inside for() statements.
21. Declare local initialized aggregates as static.
22. Expect complex inlines to be non-portable.
23. Don't use return statements that have an inline function in the return expression.
24. Be careful with the include depth of files and file size.
25. Use virtual declaration on all subclass virtual member functions.
26. Always declare a copy constructor and assignment operator.
27. Be careful of overloaded methods with like signatures.
28.Type scalar constants to avoid unexpected ambiguities.
29.Always use PRBool or XP_Bool for Boolean variables in XP code.
30.Use macros for C++ style casts.
31.Don't use mutable.
32.Don't use reserved words as identifiers.


Stuff that is good to do for C or C++.

1.Do not wrap include statements with an #ifdef.
2.#include statements should include only simple filenames.
3.Macs complain about assignments in Boolean expressions.
4.Every source file must have a unique name.
5.Use #if 0 rather than comments to temporarily kill blocks of code.
6.Turn on warnings for your compiler, and then write warning free code

Links:
http://www.mozilla.org/hacking/portable-cpp.html
http://www.doc.ic.ac.uk/lab/cplus/c++.rules/chap18.html
http://www.doc.ic.ac.uk/lab/cplus/c++.rules/chap22.html
http://www.lisp-p.org/portable/portable.html