Windows Studio gcc 3.2.3 and beyond gcc 3.4

Inevitably, one C++ compiler will wink at certain kinds of sloppiness while the other won't, or one will implement the latest standard while the other doesn't. This page attempts to document such differences and suggested work-arounds.

Windows

Doesn't support + operator for std::string; other complaints involving std::string or other standard template classes.
Solution: Be sure you have included relevant system header files, e.g.
#include <string>

gcc (3.2.3 and beyond)

Warning generated for unused argument
Workaround: Don't use dummy names of unused arguments in implementation. (You can and usually should keep them in the header file declaration.) That is, in the implementation file replace
int myMethod(double energy) {
   ...
  return 1;
}
with
int myMethod(double) {
   ...
  return 1;
}
or, if you would like a reminder,
int myMethod(double /* energy */) {
   ...
  return 1;
}

gcc 3.4

Run-time memory problems
Workaround: Look for hints in the traceback implicating static variables of non-fixed size, e.g. objects which include std::vector members. If found, replace with a pointer to the type, initialized to 0. Allocate object at a suitable place in the executable code with new.

E.g., replace

  // Declaration, usually in .h file
  static std::vector mystrings;
             .
             .
  // Definition, usually in .cxx file
  // Used by system to determine how much memory to allocate
  std::vector mystrings;
             .
             .
  // Somewhere in executable code
  mystrings.push_back("aString");

with

  // Declaration, usually in .h file
  static std::vector<std::string>* pMystrings;
             .
             .
  // Definition, usually in .cxx file
  // Used by system to determine how much memory to allocate
  std::vector<std::string>* pMystrings = 0;
             .
             .
  // Somewhere in executable code
  if (!pMystrings) {
    pMystrings = new std::vector<std::string>;
  }
  pMystrings->push_back("aString");

J. Bogart
Last modified: