Differences between revisions 3 and 4
Revision 3 as of 2008-02-06 13:21:58
Size: 927
Editor: mpiat1403
Comment: Mixing char and int types
Revision 4 as of 2008-02-06 13:25:47
Size: 1018
Editor: mpiat1403
Comment: Use the C and C++ Standard Library
Deletions are marked like this. Additions are marked like this.
Line 12: Line 12:

 * Use the C and C++ Standard Library (part of which is the STL) ''whenever possible''.

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.

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.

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