X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a68d00b19257c886d48d2583021f308b6bb3d3f5..3c79cf49ec608c37ad04a6e5c8e2bc61fd39e0fc:/docs/html/standard.htm diff --git a/docs/html/standard.htm b/docs/html/standard.htm index 1b8e6cf15d..bf0295e279 100644 --- a/docs/html/standard.htm +++ b/docs/html/standard.htm @@ -50,7 +50,13 @@ C++ portability guide by David Williams.
  • Don't use STL
  • Don't declare variables inside for()
  • Don't use nested classes
  • + +
    +
  • Other compiler limitations
  • +
    1. Use ternary operator ?: carefully
    2. +
    3. Don't use initializers with automatic arrays
    4. +
    5. Always have at least one constructor in a class with destructor

  • General recommendations
  • @@ -332,7 +338,17 @@ you can try the following:

    A nice side effect is that you don't need to recompile all the files including the header if you change the PrivateLibClass declaration (it's an example of a more general interface/implementation separation idea). + + +
    +

  • Other compiler limitations
  • +This section lists the less obvious limitations of the current C++ compilers +which are less restrictive than the ones mentioned in the previous section but +are may be even more dangerous as a program which compiles perfectly well on +some platform and seems to use only standard C++ featurs may still fail to +compile on another platform and/or with another compiler. +

    1. Use ternary operator ?: carefully
    2. The ternary operator ?: shouldn't be used with objects (i.e. if any of its operands are objects) because some compilers (notable Borland C++) fail @@ -351,6 +367,24 @@ to compile such code. else s = s2; + +

    3. Don't use initializers with automatic arrays
    4. +The initializers for automatic array variables are not supported by some older +compilers. For example, the following line +

      +    int daysInMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
      +
      +will fail to compile with HP-UX C++ compiler. +

      Workaround: either make the array static or initialize each item +separately: in the (stupid) example above, the array should be definitely +declared as static const (assuming that the leap years are dealt with +elsewhere somehow...) which is ok. When an array is really not const, you +should initialize each element separately. + +

    5. Always have at least one constructor in a class with destructor
    6. +It is a good rule to follow in general, but some compilers (HP-UX) enforce it. +So even if you are sure that the default constructor for your class is ok but +it has a destructor, remember to add an empty default constructor to it.