Differences between revisions 6 and 7
Revision 6 as of 2008-02-06 14:21:47
Size: 1838
Editor: mpiat1403
Comment:
Revision 7 as of 2008-02-12 12:07:16
Size: 2124
Editor: mpiat1403
Comment: Code from a common codebas
Deletions are marked like this. Additions are marked like this.
Line 19: Line 19:

 * Code from a common codebase: When code cannot be shared, it should be hidden behind abstractions that provide a unified application programming interface (API). Applications using the abstract API should do so ignorant that the API is abstracting platform-specific functionality.

Tips for writing portable code

Many useful tips are taken from the book [http://proquest.safaribooksonline.com/9780321246424 Cross-Platform Development in C++: Building Mac OS X, Linux, and Windows Applications] by Syd Logan. This book describe the essential best practices of a cross-platform development culture that was adopted companywide within Netscape, and embraced by Mozilla, which was critical in enabling Netscape and Mozilla to ship product with approximately the same level of quality across a wide spectrum of platforms to tens of millions of users.

Coding

  • Use the -ansi or a comparable compiler option.

  • Use typedefs for integer types whenever the integer must be of a definite size. For example, define and use the type INT32 for integers that must consist of exactly 32 bits on all target platforms.

  • C and C++ do not specify whether the char data type is signed or unsigned. This can be a problem when mixing char and int types in code — the classic example is reading characters from stdin in C into a unsigned char using the getchar() function, which returns an int and typically uses –1 to indicate end of file. If you mix char and int types, explicitly declare the char as signed or unsigned.
  • Use the C and C++ Standard Library (part of which is the STL) whenever possible.

Policy and Management

  • Make all of your platforms a priority from the very beginning on: To do cross-platform software well, parity, both in terms of functionality and quality, must be fully met on all the supported platforms, at all phases of the product's development and release. Perhaps the scariest situation one can face in cross-platform development is this question: "Now that we have it working on platform x, what about getting it to work on platform y?"
  • Code from a common codebase: When code cannot be shared, it should be hidden behind abstractions that provide a unified application programming interface (API). Applications using the abstract API should do so ignorant that the API is abstracting platform-specific functionality.

CompleteSearch: completesearch/WritingPortableCode (last edited 2008-10-23 11:40:12 by mpiat1403)